Commit Graph

2514 Commits

Author SHA1 Message Date
Arthur O'Dwyer e181a6aedd s/instantate/instantiate/ throughout. NFCI.
The static_assert in "libcxx/include/memory" was the main offender here,
but then I figured I might as well `git grep -i instantat` and fix all
the instances I found. One was in user-facing HTML documentation;
the rest were in comments or tests.
2020-12-01 22:13:40 -05:00
Nathan Ridge f15b7869e5 [clang-tidy] [clangd] Avoid multi-line diagnostic range for else-after-return diagnostic
Fixes https://bugs.llvm.org/show_bug.cgi?id=47809

Differential Revision: https://reviews.llvm.org/D92272
2020-11-29 18:32:23 -05:00
Sam McCall d99da80841 [clangd] Fix path edge-case condition. 2020-11-29 13:40:29 +01:00
Sam McCall 67d16b6da4 [clangd] Cache .clang-tidy files again.
This cache went away in 73fdd99870

This time, the cache is periodically validated against disk, so config
is still mostly "live".

The per-file cache reuses FileCache, but the tree-of-file-caches is
duplicated from ConfigProvider. .clangd, .clang-tidy, .clang-format, and
compile_commands.json all have this pattern, we should extract it at some point.
TODO for now though.

Differential Revision: https://reviews.llvm.org/D92133
2020-11-29 13:28:53 +01:00
Kirill Bobyrev 4169c520f6
[clangd] Add symbol origin for remote index
Makes it easier to diagnose remote index issues with --debug-origins flag.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D92202
2020-11-28 15:38:11 +01:00
Nathan James ca64c8948f
[NFC] SmallVector<char...> to SmallString<...> 2020-11-27 20:36:09 +00:00
Kirill Bobyrev abfcb606c2
[clangd] Add support for within-file rename of complicated fields
This was originally a part of D71880 but is separated for simplicity and ease
of reviewing.

Fixes: https://github.com/clangd/clangd/issues/582

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D91952
2020-11-27 03:59:28 +01:00
Adam Czachorowski 9d87739f66 [clangd] AddUsing: do not crash on non-namespace using decls.
Differential Revision: https://reviews.llvm.org/D92186
2020-11-26 20:07:56 +01:00
Aleksandr Platonov 1ca174b642 [clangd][query-driver] Extract target
In some cases system includes extractions is not enough, we also need target specific defines.
The problems appears when clang default target is not the same as toolchain's one (GCC cross-compiler, MinGW on Windows).
After this patch `query-driver` also extracts target and adds `--target=<extracted target>` compile option.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D92012
2020-11-26 15:08:26 +03:00
Nathan Ridge d1fd91ddaf [clangd] Do not treat line as inactive if skipped range ends at character position 0
Fixes https://github.com/clangd/clangd/issues/602

Differential Revision: https://reviews.llvm.org/D92148
2020-11-26 03:42:42 -05:00
Nathan Ridge c6cb47b640 [clangd] Collect main file refs by default
This is needed for call hierarchy to be able to find callers of
main-file-only functions.

Differential Revision: https://reviews.llvm.org/D92000
2020-11-25 20:33:57 -05:00
Sam McCall cbf336ad76 [clangd] Track deprecation of 'member' semantic token type in LSP. 2020-11-25 21:31:46 +01:00
Nathan James 73fdd99870
[clangd] Implement clang-tidy options from config
Added some new ClangTidyOptionsProvider like classes designed for clangd work flow.
These providers are designed to source the options on the worker thread but in a thread safe manner.
This is done through making the options getter take a pointer to the filesystem used by the worker thread which natuarally is from a ThreadsafeFS.
Internal caching in the providers is also guarded.

The providers don't inherit from `ClangTidyOptionsProvider` instead they share a base class which is able to create a provider for the `ClangTidyContext` using a specific FileSystem.
This approach means one provider can be used for multiple contexts even though `ClangTidyContext` owns its provider.

Depends on D90531

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D91029
2020-11-25 18:35:35 +00:00
Adam Czachorowski f6970503d2 [clangd] PopulateSwitch: disable on dependent enums.
If the enum is a dependent type, we would crash somewhere in
getIntWidth(). -Wswitch diagnostic doesn't work on dependent enums
either.

Differential Revision: https://reviews.llvm.org/D92051
2020-11-25 14:12:29 +01:00
Sam McCall a38d13ed36 [clangd] Use TimePoint<> instead of system_clock::time_point, it does matter after all. 2020-11-25 12:49:24 +01:00
Sam McCall d95db1693c [clangd] Extract common file-caching logic from ConfigProvider.
The plan is to use this to use this for .clang-format, .clang-tidy, and
compile_commands.json. (Currently the former two are reparsed every
time, and the latter is cached forever and changes are never seen).

Differential Revision: https://reviews.llvm.org/D88172
2020-11-25 12:09:13 +01:00
Haojian Wu 0cb38699a0 [clangd] Fix a tsan failure.
Tracer must be set up before calling any clangd-specific functions.
2020-11-25 11:47:44 +01:00
Haojian Wu fb6f425d1b [clangd] Add metrics for invalid name.
Differential Revision: https://reviews.llvm.org/D92082
2020-11-25 10:50:43 +01:00
Nathan Ridge 3d2c681f28 [clangd] Avoid type hierarchy crash on incomplete type
Fixes https://github.com/clangd/clangd/issues/597

Differential Revision: https://reviews.llvm.org/D92077
2020-11-25 03:45:00 -05:00
Adam Czachorowski a200501bca [clangd] Addusing tweak: find insertion point after definition
When type/function is defined in the middle of the file, previuosly we
would sometimes insert a "using" line before that definition, leading to
a compilation error. With this fix, we pick a point after such
definition in translation unit.

This is not a perfect solution. For example, it still doesn't handle
"using namespace" directives. It is, however, a significant improvement.

Differential Revision: https://reviews.llvm.org/D92053
2020-11-24 22:57:02 +01:00
Haojian Wu 1e821217cb [clangd] Add more trace spans for rename, NFC. 2020-11-24 19:57:05 +01:00
Adam Czachorowski f6e59294b6 [clangd] AddUsing: Used spelled text instead of type name.
This improves the behavior related to type aliases, as well as cases of
typo correction.

Differential Revision: https://reviews.llvm.org/D91966
2020-11-24 18:59:09 +01:00
Sam McCall 9e83d0bcdf [clangd] Mention when CXXThis is implicit in exposed AST.
Seeing an implicit this in the AST is pretty confusing I think.
While here, also mention when `this` is const.

Differential Revision: https://reviews.llvm.org/D91868
2020-11-24 16:57:56 +01:00
Kadir Cetinkaya f726101b62
[clangd] Fix shared-lib builds
Differential Revision: https://reviews.llvm.org/D91859
2020-11-24 13:05:20 +01:00
Nathan Ridge 5b6f47595b [clangd] Sort results of incomingCalls request by container name
Differential Revision: https://reviews.llvm.org/D92009
2020-11-24 03:29:02 -05:00
Nathan Ridge dced150375 [clangd] Use WorkScheduler.run() in ClangdServer::resolveTypeHierarchy()
Differential Revision: https://reviews.llvm.org/D91941
2020-11-23 20:44:14 -05:00
Nathan Ridge 0a4f99c494 [clangd] Call hierarchy (ClangdLSPServer layer)
Differential Revision: https://reviews.llvm.org/D91124
2020-11-23 20:44:07 -05:00
Nathan Ridge 4cb976e014 [clangd] Call hierarchy (ClangdServer layer)
Differential Revision: https://reviews.llvm.org/D91123
2020-11-23 20:43:41 -05:00
Nathan Ridge 3e6e6a2db6 [clangd] Call hierarchy (XRefs layer, incoming calls)
Support for outgoing calls is left for a future change.

Differential Revision: https://reviews.llvm.org/D91122
2020-11-23 20:43:38 -05:00
Utkarsh Saxena b31486ad97 [clangd] textDocument/implementation (LSP layer)
Differential Revision: https://reviews.llvm.org/D91721
2020-11-23 13:50:44 +01:00
Kadir Cetinkaya 61e538b15d
Revert "[clangd] testPath's final result agrees with the passed in Style"
This reverts commit 8cec8de2a4 as it
breaks windows buildbots.
2020-11-23 13:12:59 +01:00
Kadir Cetinkaya 8cec8de2a4
[clangd] testPath's final result agrees with the passed in Style
This was confusing, as testRoot on windows results in C:\\clangd-test
and testPath generated with posix explicitly still contained backslashes.

This patch ensures not only the relative part, but the whole final result
respects passed in Style.

Differential Revision: https://reviews.llvm.org/D91947
2020-11-23 12:45:06 +01:00
Kirill Bobyrev 1319c6624e [clangd] Get rid of clangToolingRefactoring dependency
D71880 makes this dependency redundant and we can safely remove it. Tested for
both shared lib build and static lib build.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D91951
2020-11-23 11:59:38 +01:00
Kirill Bobyrev cf39bdb490
[clangd] Implement Decl canonicalization rules for rename
This patch introduces new canonicalization rules which are used for AST-based
rename in Clangd. By comparing two canonical declarations of inspected nodes,
Clangd determines whether both of them belong to the same entity user would
like to rename. Such functionality is relatively concise compared to the
Clang-Rename API that is used right now. It also helps to overcome the
limitations that Clang-Rename originally had and helps to eliminate several
classes of bugs.

Clangd AST-based rename currently relies on Clang-Rename which has design
limitations and also lacks some features. This patch breaks this dependency and
significantly reduces the amount of code to maintain (Clang-Rename is ~2000 LOC,
this patch is just <30 LOC of replacement code).

We eliminate technical debt by simultaneously

* Maintaining feature parity and ensuring no regressions
* Opening a straightforward path to improving existing rename bugs
* Making it possible to add more capabilities to rename feature which would not
  be possible with Clang-Rename

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D71880
2020-11-23 11:42:56 +01:00
Kadir Cetinkaya fee78fb004
[clangd] Second attempt at fixing windows buildbots 2020-11-23 10:06:48 +01:00
Kadir Cetinkaya 0dc2589d4a
[clangd] Attempt at fixing ExternalIndex tests on windows 2020-11-23 09:16:06 +01:00
Kadir Cetinkaya 655360096f
[clangd] Fix use-after-free in ProjectAwareIndex tests 2020-11-22 21:29:45 +01:00
Kadir Cetinkaya cab3136807
[clangd] Use ProjectAwareIndex in ClangdMain
Put project-aware-index between command-line specified static index and
ClangdServer indexes.

This also moves remote-index dependency from clangDaemon to ClangdMain
in an attempt to prevent cyclic dependency between clangDaemon and
remote-index-marshalling.

Differential Revision: https://reviews.llvm.org/D91860
2020-11-22 20:59:38 +01:00
Kadir Cetinkaya 067ffbfe60
[clangd] Introduce ProjectAwareIndex
An index implementation that can dispatch to a variety of indexes
depending on the file path. Enables clangd to work with multiple indexes in the
same instance, configured via config files.

Depends on D90749, D90746

Differential Revision: https://reviews.llvm.org/D90750
2020-11-22 20:59:37 +01:00
Kadir Cetinkaya c9776c8d4e
[clangd] Introduce config compilation for External blocks
Compilation logic for External blocks. A few of the high level points:
- Requires exactly one-of File/Server at a time:
  - Server is ignored in case of both, with a warning.
  - Having none is an error, would render ExternalBlock void.
- Ensures mountpoint is an absolute path:
  - Interprets it as relative to FragmentDirectory.
  - Defaults to FragmentDirectory when empty.
- Marks Background as Skip.

Depends on D90748.

Differential Revision: https://reviews.llvm.org/D90749
2020-11-22 20:59:37 +01:00
Kadir Cetinkaya 359e2f988d
[clangd] Introduce config parsing for External blocks
Enable configuration of remote and static indexes through config files
in addition to command line arguments.

Differential Revision: https://reviews.llvm.org/D90748
2020-11-22 20:59:37 +01:00
Nathan James 82c22f1248
[clangd] Fix compile error after 20b69af7
Some of the buildbots were failing due to what seems to be them using a non c++14 compilant std::string implementation.
Since c++14 std::basic_string::append(const basic_string, size_t, size_t) has a defaulted 3rd paramater, but some of the build bots were reporting that it wasn't defaulted in their implementation.
2020-11-22 10:48:48 +00:00
Nathan James 20b69af7c9
[clangd] Add clang-tidy options to config
First step of implementing clang-tidy configuration into clangd config.
This is just adding support for reading and verifying the clang tidy options from the config fragments.
No support is added for actually using the options within clang-tidy yet.

That will be added in a follow up as its a little more involved.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D90531
2020-11-22 10:04:01 +00:00
Sam McCall de5b0b776f [clangd] semanticTokens: fields are 'property', not 'member'
This isn't obvious, but vscode maps member as 'entity.name.function.member',
so it's really for member functions.

Fixes https://github.com/clangd/vscode-clangd/issues/105
2020-11-20 20:53:12 +01:00
Simon Pilgrim 44c96becc9 Fix MSVC "not all control paths return a value" warnings. NFCI. 2020-11-20 11:41:20 +00:00
Kirill Bobyrev da14ae23a5
[clangd] NFC: Reorder headers in tests accordig to Clang-Tidy 2020-11-20 10:38:41 +01:00
Sam McCall 8adc4d1ec7 [clangd] Add textDocument/ast extension method to dump the AST
This is a mass-market version of the "dump AST" tweak we have behind
-hidden-features.
I think in this friendlier form it'll be useful for people outside clang
developers, which would justify making it a real feature.
It could be useful as a step towards lightweight clang-AST tooling in clangd
itself (like matcher-based search).

Advantages over the tweak:
 - simplified information makes it more accessible, likely somewhat useful
   without learning too much clang internals
 - can be shown in a tree view
 - structured information gives some options for presentation (e.g.
   icon + two text colors + tooltip in vscode)
 - clickable nodes jump to the corresponding code
Disadvantages:
 - a bunch of code to handle different node types
 - likely missing some important info vs dump-ast due to brevity/oversight
 - may end up chasing/maintaining support for the long tail of nodes

Demo with VSCode support: https://imgur.com/a/6gKfyIV

Differential Revision: https://reviews.llvm.org/D89571
2020-11-20 01:13:28 +01:00
Sam McCall ad5a195ae5 [clangd] Express ASAN interactions of tests more clearly. NFC 2020-11-19 20:14:51 +01:00
Sam McCall d7747dacba [clangd] Also detect corrupt stri table size.
Differential Revision: https://reviews.llvm.org/D91299
2020-11-19 20:11:14 +01:00
Haojian Wu 734d2f98f6 [clangd] No crash on "-verify" mode.
If there is a "-verify" flag in the compile command, clangd will crash
(hit the assertion) inside the `~VerifyDiagnosticConsumer` (Looks like our
compiler invocation doesn't setup correctly?).

This patch disables the verify mode as it is rarely useful in clangd.

Differential Revision: https://reviews.llvm.org/D91777
2020-11-19 15:51:53 +01:00