Commit Graph

2728 Commits

Author SHA1 Message Date
Haojian Wu 345099ca19 [clangd] Add rename support.
Summary:
Make clangd handle "textDocument/rename" request. The rename
functionality comes from the "local-rename" sub-tool of clang-refactor.

Currently clangd only supports local rename (only symbol occurrences in
the main file will be renamed).

Reviewers: sammccall, ilya-biryukov

Reviewed By: sammccall

Subscribers: cfe-commits, ioeric, arphaman, mgorny

Differential Revision: https://reviews.llvm.org/D39676

llvm-svn: 317780
2017-11-09 11:30:04 +00:00
Sam McCall 99beabf7ed Relax definitions.test to accept windows file paths.
Reviewers: ilya-biryukov

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D39797

llvm-svn: 317692
2017-11-08 13:52:21 +00:00
Krasimir Georgiev 8fc64a7732 [clang-tidy] Add a note about modernize-replace-random-shuffle
Summary:
This adds a note warning the users that the way the suggested fix seeds the
random number generator is poor.

Reviewers: hokein

Reviewed By: hokein

Subscribers: cfe-commits, xazax.hun

Differential Revision: https://reviews.llvm.org/D39787

llvm-svn: 317689
2017-11-08 13:28:53 +00:00
Sam McCall df29d899e8 [clangd] tolerate windows filepaths in tests
llvm-svn: 317686
2017-11-08 12:25:00 +00:00
Sam McCall 28ef7d662f [clangd] loosen tests for flag-dependence revealed by r317670
llvm-svn: 317673
2017-11-08 09:15:01 +00:00
Sam McCall c78ccbdefb [clangd] Sort completion results.
Summary:
This is (probably) not required by LSP, but at least one buggy client wants it.
It also simplifies some tests - changed a few completion tests to use -pretty.

Reviewers: hokein, malaperle

Subscribers: ilya-biryukov, cfe-commits

Differential Revision: https://reviews.llvm.org/D39738

llvm-svn: 317670
2017-11-08 07:44:12 +00:00
Douglas Yung 76036fce25 Fix compile issue on MSVC.
llvm-svn: 317642
2017-11-08 00:29:42 +00:00
Marc-Andre Laperle ba070108a6 [clangd] Fix opening declarations located in non-preamble inclusion
Summary:
When an inclusion is not processed as part of the preamble, its path is
not made into an absolute path as part of the precompiled header code
(adjustFilenameForRelocatableAST in ASTWriter.cpp). Because of this,
when we convert a Decl location to retrieve the file name with
FileEntry->getName(), it is possible for this path to be relative.
Instead, we should try to use tryGetRealPathName first which returns
an absolute path.

Fixes bug 35217.

Reviewers: sammccall, ilya-biryukov, rwols, Nebiroth

Reviewed By: sammccall

Subscribers: cfe-commits, ilya-biryukov

Tags: #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D39705

llvm-svn: 317585
2017-11-07 16:16:45 +00:00
Sam McCall 0930ab094b [clangd] Fix initialize capabilities response
llvm-svn: 317584
2017-11-07 15:49:35 +00:00
Sam McCall 784e88351b [clangd] MSVC - third time's the charm
llvm-svn: 317581
2017-11-07 14:59:21 +00:00
Sam McCall 94362c61c6 [clangd] don't crash on invalid JSON-RPC ID
llvm-svn: 317580
2017-11-07 14:45:31 +00:00
Sam McCall 99633ec527 [clangd] another try at fixing MSVC
llvm-svn: 317575
2017-11-07 14:14:58 +00:00
Gabor Horvath ec87e17c84 [clang-tidy] Misc redundant expressions checker updated for macros
Redundant Expression Checker is updated to be able to detect expressions that
contain macros. Also, other small details are modified to improve the current
implementation.

The improvements in detail are as follows:
* Binary and ternary operator expressions containing two constants, with at
least one of them from a macro, are detected and tested for redundancy.

Macro expressions are treated somewhat differently from other expressions,
because the particular values of macros can vary across builds.
They can be considered correct and intentional, even if macro values equal,
produce ranges that exclude each other or fully overlap, etc. 

* The code structure is slightly modified: typos are corrected,
comments are added and some functions are renamed to improve comprehensibility,
both in the checker and the test file. A few test cases are moved to another
function.

* The checker is now able to detect redundant CXXFunctionalCastExprs as well.
A corresponding test case is added.

Patch by: Lilla Barancsuk!

Differential Revision: https://reviews.llvm.org/D38688

llvm-svn: 317570
2017-11-07 13:17:58 +00:00
Haojian Wu 2375c926f4 [clangd] Add ErrorCode enum class.
Summary: Avoid using magic number in the code everywhere.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: ilya-biryukov, cfe-commits

Differential Revision: https://reviews.llvm.org/D39718

llvm-svn: 317559
2017-11-07 10:21:02 +00:00
Sam McCall c2055486eb [clangd] fix MSVC build errors
llvm-svn: 317553
2017-11-07 08:57:54 +00:00
Haojian Wu 5529a244e1 Add new check in google module for Objective-C code to ensure global variables follow the naming convention of Google Objective-C Style Guide
Summary:
This is a new checker for objc files in clang-tidy.

The new check finds global variable declarations in Objective-C files that are not follow the pattern of variable names in Google's Objective-C Style Guide.

All the global variables should follow the pattern of "g[A-Z].*" (variables) or "k[A-Z].*" (constants). The check will suggest a variable name that follows the pattern
if it can be inferred from the original name.

Patch by Yan Zhang!

Reviewers: benhamilton, hokein, alexfh

Reviewed By: hokein

Subscribers: Eugene.Zelenko, mgorny

Differential Revision: https://reviews.llvm.org/D39391

llvm-svn: 317552
2017-11-07 08:53:37 +00:00
NAKAMURA Takumi e02398022d ClangdTests/JSONExprTests.cpp: Appease g++-4.8 to move raw string literal out of macro arg.
llvm-svn: 317538
2017-11-07 02:18:24 +00:00
Sam McCall 0ed8d48c4b [clangd] Squash namespace warning
llvm-svn: 317487
2017-11-06 15:50:35 +00:00
Sam McCall dd0566bb2c Adds a json::Expr type to represent intermediate JSON expressions.
Summary:
This form can be created with a nice clang-format-friendly literal syntax,
and gets escaping right. It knows how to call unparse() on our Protocol types.
All the places where we pass around JSON internally now use this type.

Object properties are sorted (stored as std::map) and so serialization is
canonicalized, with optional prettyprinting (triggered by a -pretty flag).
This makes the lit tests much nicer to read and somewhat nicer to debug.
(Unfortunately the completion tests use CHECK-DAG, which only has
line-granularity, so pretty-printing is disabled there. In future we
could make completion ordering deterministic, or switch to unittests).

Compared to the current approach, it has some efficiencies like avoiding copies
of string literals used as object keys, but is probably slower overall.
I think the code/test quality benefits are worth it.

This patch doesn't attempt to do anything about JSON *parsing*.
It takes direction from the proposal in this doc[1], but is limited in scope
and visibility, for now.
I am of half a mind just to use Expr as the target of a parser, and maybe do a
little string deduplication, but not bother with clever memory allocation.
That would be simple, and fast enough for clangd...
[1] https://docs.google.com/document/d/1OEF9IauWwNuSigZzvvbjc1cVS1uGHRyGTXaoy3DjqM4/edit

+cc d0k so he can tell me not to use std::map.

Reviewers: ioeric, malaperle

Subscribers: bkramer, ilya-biryukov, mgorny, klimek

Differential Revision: https://reviews.llvm.org/D39435

llvm-svn: 317486
2017-11-06 15:40:30 +00:00
Gabor Horvath 8de900ae1f [clang-tidy] Support relative paths in run-clang-tidy.py
Unfortunately, these python scripts are not tested currently. I did the testing
manually on LLVM by editing the CMake generated compilation database to
contain relative paths for some of the files. 

Differential Revision: https://reviews.llvm.org/D39603

llvm-svn: 317468
2017-11-06 10:36:02 +00:00
Eric Liu b0b8f03874 Use ToolExecutor framework in the sample tool-template.
llvm-svn: 317333
2017-11-03 16:03:56 +00:00
Marc-Andre Laperle e7ec16aaa6 [clangd] Handle clangd.applyFix server-side
Summary:
When the user selects a fix-it (or any code action with commands), it is
possible to let the client forward the selected command to the server.
When the clangd.applyFix command is handled on the server, it can send a
workspace/applyEdit request to the client. This has the advantage that
the client doesn't explicitly have to know how to handle
clangd.applyFix. Therefore, the code to handle clangd.applyFix in the VS
Code extension (and any other Clangd client) is not required anymore.

Reviewers: ilya-biryukov, sammccall, Nebiroth, hokein

Reviewed By: hokein

Subscribers: ioeric, hokein, rwols, puremourning, bkramer, ilya-biryukov

Tags: #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D39276

llvm-svn: 317322
2017-11-03 13:39:15 +00:00
Ben Hamilton 82b077db3a Update release notes (check SVN commit-after-approval access)
Summary:
I was just granted commit-after-approval access to SVN,
and @clattner recommended I try a test commit.

So, this tweaks the release notes as a test.

Reviewers: hokein, alexfh

Reviewed By: hokein

Subscribers: Wizard

Differential Revision: https://reviews.llvm.org/D39559

llvm-svn: 317261
2017-11-02 20:00:17 +00:00
Sam McCall 32995b3056 Fix clangd test on platforms where get_thread_name does nothing.
llvm-svn: 317194
2017-11-02 09:48:55 +00:00
Sam McCall 8567cb3720 Performance tracing facility for clangd.
Summary:
This lets you visualize clangd's activity on different threads over time,
and understand critical paths of requests and object lifetimes.
The data produced can be visualized in Chrome (at chrome://tracing), or
in a standalone copy of catapult (http://github.com/catapult-project/catapult)

This patch consists of:
 - a command line flag "-trace" that causes clangd to emit JSON trace data
 - an API (in Trace.h) allowing clangd code to easily add events to the stream
 - several initial uses of this API to capture JSON-RPC requests, builds, logs

Example result: https://photos.app.goo.gl/12L9swaz5REGQ1rm1

Caveats:
 - JSON serialization is ad-hoc (isn't it everywhere?) so the API is
   limited to naming events rather than attaching arbitrary metadata.
   I'd like to fix this (I think we could use a JSON-object abstraction).
 - The recording is very naive: events are written immediately by
   locking a mutex. Contention on the mutex might disturb performance.
 - For now it just traces instants or spans on the current thread.
   There are other things that make sense to show (cross-thread flows,
   non-thread resources such as ASTs). But we have to start somewhere.

Reviewers: ioeric, ilya-biryukov

Subscribers: cfe-commits, mgorny

Differential Revision: https://reviews.llvm.org/D39086

llvm-svn: 317193
2017-11-02 09:21:51 +00:00
Shoaib Meenai 99cfb67ad2 [clangd] Remove redundant install
`add_clang_tool` already adds the install command, so the one here is
redundant.

llvm-svn: 317187
2017-11-02 05:02:24 +00:00
Shoaib Meenai 09d4efee52 [clang-tidy] Clean up installation rules
An installation rule for the executable with the correct component is
already created by `add_clang_tool`, so the rule in this file is
redundant. Correct the installation component for the Python scripts so
that they also get installed by `install-clang-tidy`.

llvm-svn: 317155
2017-11-02 01:48:20 +00:00
Shoaib Meenai c40419d94b [clang-reorder-fields] Switch to add_clang_tool
`add_clang_tool` invokes `add_clang_executable` internally, but it also
takes care of setting up the install rule. It also adds an `install-*`
build target, which is required for `LLVM_DISTRIBUTION_COMPONENTS`.

Differential Revision: https://reviews.llvm.org/D39523

llvm-svn: 317149
2017-11-02 01:10:05 +00:00
Simon Pilgrim 948c0bcbd6 Add LLVM_FALLTHROUGH to silence warning. NFCI.
llvm-svn: 317083
2017-11-01 09:22:03 +00:00
Benjamin Kramer 5349eedfdd [clangd] Fix clang-tidy warnings.
No functionality change intended.

llvm-svn: 316832
2017-10-28 17:32:56 +00:00
Benjamin Kramer 1d053791a1 [clangd] Don't crash on extremely large JSON messages.
Found by clangd-fuzzer.

llvm-svn: 316774
2017-10-27 17:06:41 +00:00
Benjamin Kramer decd8a702a [clangd] Harden clangd a bit against garbage input.
There can be nullptrs here if the YAML fails to parse. Found by
clangd-fuzzer!

llvm-svn: 316770
2017-10-27 16:33:15 +00:00
Jonas Toth 8ba28c7200 [clang-tidy] Fix bug 34845, offending standard bitmask types
Summary:
The C++ standard allows implementations to choose the underlying type for
bitmask types (e.g. std::ios_base::openmode). MSVC implemented some of them
as signed integers resulting in warnings for usual code like
`auto dd = std::ios_base::badbit | std::ios_base::failbit;`

These false positives were reported in https://bugs.llvm.org/show_bug.cgi?id=34845

The fix allows bitwise |,&,^ for known standard bitmask types under the condition
that both operands are such bitmask types.
Shifting and bitwise complement are still forbidden.

Reviewers: aaron.ballman, alexfh, hokein

Reviewed By: aaron.ballman

Subscribers: xazax.hun

Differential Revision: https://reviews.llvm.org/D39099

llvm-svn: 316767
2017-10-27 14:44:08 +00:00
Haojian Wu e010406e28 [clang-tidy ObjC] [3/3] New check objc-forbidden-subclassing
Summary:
This is part 3 of 3 of a series of changes to improve Objective-C
linting in clang-tidy.

This adds a new clang-tidy check `objc-forbidden-subclassing` which
ensures clients do not create subclasses of Objective-C classes which
are not designed to be subclassed.

(Note that for code under your control, you should use
__attribute__((objc_subclassing_restricted)) instead -- this
is intended for third-party APIs which cannot be modified.)

By default, the following classes (which are publicly documented
as not supporting subclassing) are forbidden from subclassing:

ABNewPersonViewController
ABPeoplePickerNavigationController
ABPersonViewController
ABUnknownPersonViewController
NSHashTable
NSMapTable
NSPointerArray
NSPointerFunctions
NSTimer
UIActionSheet
UIAlertView
UIImagePickerController
UITextInputMode
UIWebView

Clients can set a CheckOption
`objc-forbidden-subclassing.ClassNames` to a semicolon-separated
list of class names, which overrides this list.

Test Plan: `ninja check-clang-tools`

Patch by Ben Hamilton!

Reviewers: hokein, alexfh

Reviewed By: hokein

Subscribers: saidinwot, Wizard, srhines, mgorny, xazax.hun

Differential Revision: https://reviews.llvm.org/D39142

llvm-svn: 316744
2017-10-27 07:41:36 +00:00
Benjamin Kramer ee19f16633 [clangd] Report an error on findDefinitions/signatureHelp on an unopened file instead of crashing.
Found by clangd-fuzzer.

llvm-svn: 316659
2017-10-26 12:28:13 +00:00
Benjamin Kramer b560a9a1b8 [clangd] Don't crash on empty textDocument/didChange.
Found by clangd-fuzzer.

llvm-svn: 316652
2017-10-26 10:36:20 +00:00
Benjamin Kramer 74a1895422 [clangd] Don't use /// for non-doxygen comments.
llvm-svn: 316650
2017-10-26 10:07:04 +00:00
Benjamin Kramer 09113ae2c5 [clangd] Add a simple fuzzer. It crashes a lot :)
llvm-svn: 316649
2017-10-26 10:03:11 +00:00
Haojian Wu d2825825f8 [clang-tidy ObjC] [2/3] Support non-C++ files in ClangTidyTest
Summary:
This is part 2 of 3 of a series of changes to improve
Objective-C linting in clang-tidy.

Currently, `clang::tidy::test::runCheckOnCode()` assumes all files
are C++ and unconditionally adds `-std=c++11` to the list of
`clang-tidy` options.

This updates the logic to check the extension of the source file
and only add `-std=c++11` if the extension indicates C++ or
Objective-C++.

Depends On D39188

Test Plan:

  ninja ClangTidyTests && \
  ./tools/clang/tools/extra/unittests/clang-tidy/ClangTidyTests

Patch by Ben Hamilton!

Reviewers: hokein, alexfh

Reviewed By: hokein

Subscribers: Wizard

Differential Revision: https://reviews.llvm.org/D39189

llvm-svn: 316645
2017-10-26 08:37:25 +00:00
Haojian Wu abcd64ccbf [clang-tidy ObjC] [1/3] New module `objc` for Objective-C checks
Summary:
This is part 1 of 3 of a series of changes to improve Objective-C
linting in clang-tidy.

This introduces a new clang-tidy module, `objc`, specifically for
Objective-C / Objective-C++ checks.

The module is currently empty; D39142 adds the first check.

Test Plan: `ninja check-clang-tools`

Patch by Ben Hamilton!

Reviewers: hokein, alexfh

Reviewed By: hokein

Subscribers: Wizard, mgorny

Differential Revision: https://reviews.llvm.org/D39188

llvm-svn: 316643
2017-10-26 08:23:20 +00:00
Alex Lorenz fbd17e17f5 Handle PragmaDebug in PPChainedCallbacks
The test is in clang-tools-extra/test/pp-trace

llvm-svn: 316621
2017-10-25 22:01:23 +00:00
Ilya Biryukov 90bbcfd350 [clangd] Added a callback-based codeComplete in clangd.
Reviewers: klimek, bkramer, sammccall, krasimir

Reviewed By: sammccall

Subscribers: rwols, cfe-commits

Differential Revision: https://reviews.llvm.org/D38629

llvm-svn: 316565
2017-10-25 09:35:10 +00:00
Ilya Biryukov 0d9b8a3ee8 [clangd] Handle exit notification (proper shutdown)
Summary:
This changes the onShutdown handler to do essentially nothing (for now), and
instead exits the runloop when we receive the exit notification from the client.

Some clients may wait on the reply from the shutdown request before sending an
exit notification. If we exit the runloop already in the shutdown request, a
client might block forever.

This also gives us the opportunity to do any global cleanups and/or
serializations of PCH preambles to disk, but I've left that out for now.

See the LSP protocol documentation for details.

Reviewers: malaperle, krasimir, bkramer, sammccall, ilya-biryukov

Reviewed By: malaperle, sammccall, ilya-biryukov

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D38939

llvm-svn: 316564
2017-10-25 08:45:41 +00:00
Ilya Biryukov b080cb155b [clangd] Allow to pass code completion opts to ClangdServer.
Reviewers: bkramer, krasimir, sammccall

Reviewed By: krasimir

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D38731

llvm-svn: 316327
2017-10-23 14:46:48 +00:00
Ilya Biryukov a7e3763a2b [clangd] Updated outdated test comment. NFC.
llvm-svn: 316323
2017-10-23 14:08:52 +00:00
Ilya Biryukov 01e3bf8afd [clangd] Report proper kinds for 'Keyword' and 'Snippet' completion items.
Reviewers: rwols, malaperle, krasimir, bkramer, sammccall

Reviewed By: rwols, sammccall

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D38720

llvm-svn: 316311
2017-10-23 06:06:21 +00:00
NAKAMURA Takumi f793fa3335 clang-tidy: Fix deps.
llvm-svn: 316260
2017-10-21 11:02:30 +00:00
Zachary Turner afc4b3857b [clang-tidy] Remove MSVC inline assembly test from cross-plat test.
This originally started out here in dev, but I moved it to another
file when it became clear this wouldn't work on non-Windows.
Unfortunately I forgot to remove it from this file.  Test is still
live, just in another source file.

llvm-svn: 316247
2017-10-20 23:09:20 +00:00
Zachary Turner fbdca1daec [clang-tidy] Don't error on MS-style inline assembly.
To get MS-style inline assembly, we need to link in the various
backends.  Some other clang tools already do this, and this issue
has been raised with clang-tidy several times, indicating there
is sufficient desire to make this work.

Differential Revision: https://reviews.llvm.org/D38549

llvm-svn: 316246
2017-10-20 23:00:51 +00:00
Haojian Wu 49b8e94478 [clang-tidy] Add missing test files in r316090.
llvm-svn: 316221
2017-10-20 17:54:53 +00:00