Commit Graph

172 Commits

Author SHA1 Message Date
Tom Praschan 5a85f9b1d4 Add semantic token modifier for non-const reference parameter
See https://github.com/clangd/clangd/issues/839

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D108320
2021-09-13 00:51:09 -04:00
Christian Kandeler 159a269648 [clangd] Add new semantic token modifier "virtual"
This is needed for clients that want to highlight virtual functions
differently.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D107145
2021-08-03 19:53:01 -07:00
Kadir Cetinkaya 41e2422286
[clangd] Unify compiler invocation creation
Background-indexing is fine, because it uses GlobalCompilationDatabase
to fetch the compile commands (hence uses CommandMangler), and creates
invocation through buildCompilerInvocation.

Depends on D106639.

Differential Revision: https://reviews.llvm.org/D106669
2021-07-30 15:22:51 +02:00
Kadir Cetinkaya c3682a22c2
[clangd] Enable relative configs in check mode
See https://github.com/clangd/clangd/issues/649#issuecomment-885903316.
Also disables config support in lit tests to make sure tests are not affected by
clangd config files lying around.

Differential Revision: https://reviews.llvm.org/D107130
2021-07-30 14:23:48 +02:00
Kadir Cetinkaya 259e365dea
Revert "Revert "[clangd] Adjust compile flags to contain only the requested file as input""
This reverts commit 04e21fbc44.
2021-07-27 14:49:53 +02:00
Kadir Cetinkaya ab714ba056
Revert "Revert "[clangd] Canonicalize compile flags before applying edits""
Set driver mode before parsing arglist.

Depends on D106789.

Differential Revision: https://reviews.llvm.org/D106794
2021-07-27 14:49:53 +02:00
Kadir Cetinkaya e7590d748a
Revert "[clangd] Canonicalize compile flags before applying edits"
This reverts commit 7cc8a8e384.
2021-07-23 18:20:52 +02:00
Kadir Cetinkaya 04e21fbc44
Revert "[clangd] Adjust compile flags to contain only the requested file as input"
This reverts commit ba5dd945ad.
2021-07-23 17:58:11 +02:00
Kadir Cetinkaya ba5dd945ad
[clangd] Adjust compile flags to contain only the requested file as input
Depends on D106527.

Differential Revision: https://reviews.llvm.org/D106639
2021-07-23 17:15:06 +02:00
Kadir Cetinkaya 7cc8a8e384
[clangd] Canonicalize compile flags before applying edits
Pushes input for the compile action to the end while separating with a
`--` before applying other manglings. This ensures edits that effect only the
arguments that come after them works, like changing parse language via -x.

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

Differential Revision: https://reviews.llvm.org/D106527
2021-07-23 17:15:06 +02:00
Sam McCall 462d4de35b [clangd] Add CMake option to (not) link in clang-tidy checks
This reduces the size of the dependency graph and makes incremental
development a little more pleasant (less rebuilding).

This introduces a bit of complexity/fragility as some tests verify
clang-tidy behavior. I attempted to isolate these and build/run as much
of the tests as possible in both configs to prevent rot.

Expectation is that (some) developers will use this locally, but
buildbots etc will keep testing clang-tidy.

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

Differential Revision: https://reviews.llvm.org/D105679
2021-07-14 10:04:21 +02:00
Kadir Cetinkaya 8f2bf93b5b
[clangd] Introduce a log-prefix flag to remote-index-server
Differential Revision: https://reviews.llvm.org/D104843
2021-06-25 16:51:29 +02:00
David Goldman 2f951ca98b [clangd] Add support for the `defaultLibrary` semantic token modifier
This allows us to differentiate symbols from the system (e.g. system
includes or sysroot) differently than symbols defined in the user's
project, which can be used by editors to display them differently.

This is currently based on `FileCharacteristic`, but we can
consider alternatives such as `Sysroot` and file paths in the future.

Differential Revision: https://reviews.llvm.org/D101554
2021-06-02 10:24:29 -04:00
Kadir Cetinkaya daf3cb3b8a
[clangd][index-sever] Limit results in repsonse
This is to prevent server from being DOS'd by possible malicious
parties issuing requests that can yield huge responses.

One possible drawback is on rename workflow. As it really requests all
occurences, but it has an internal limit on 50 files currently.
We are putting the limit on 10000 elements per response So for rename to regress
one should have 10k refs to a symbol in less than 50 files. This seems unlikely
and we fix it if there are complaints by giving up on the response based on the
number of files covered instead.

Differential Revision: https://reviews.llvm.org/D101914
2021-05-11 08:22:23 +02:00
Kirill Bobyrev 34593ae998 Introduce clangd-server-monitor tool
Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D101516
2021-05-04 12:48:21 +02:00
Nathan Ridge 3504e50b6d [clangd] Fix test failure in initialize-params.test
Differential Revision: https://reviews.llvm.org/D101740
2021-05-03 01:37:09 -04:00
Christian Kandeler 81dae18dff [clangd] Allow AST request without range
If no range is given, return the translation unit AST.
This is useful for tooling operations that require e.g. the full path to
a node.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D101057
2021-04-23 21:35:42 +02:00
Nathan Ridge cbc9c4ea90 [clangd] Add support for inline parameter hints
Differential Revision: https://reviews.llvm.org/D98748
2021-04-14 02:31:20 -04:00
Adam Czachorowski 3b4936ba29 [clangd] Add --check-lines to restrict --check to specific lines
This will allow us to add code completion, which is too expensive at
every token, to --check too.

Differential Revision: https://reviews.llvm.org/D98970
2021-04-09 13:47:20 +02:00
Kadir Cetinkaya 4f1bbc0b84
[clangd] Introduce a CommandLineConfigProvider
This enables unifying command line flags with config options in clangd
internals. This patch changes behaviour in 2 places:
- BackgroundIndex was previously disabled when -remote-index was
provided. After this patch, it will be enabled but all files will have
bkgindex policy set to Skip.
- -index-file was loaded at startup (at least load was initiated), now
the load will happen through ProjectAwareIndex with first index query.

Unfortunately this doesn't simplify any options initially, as
- CompileCommandsDir is also used by clangd --check workflow, which
doesn't use configs.
- EnableBackgroundIndex option controls whether the component will be
created at all, which implies creation of extra threads registering a
listener for compilation database discoveries.

Differential Revision: https://reviews.llvm.org/D98029
2021-03-11 13:35:05 +01:00
Aleksandr Platonov c4efd04f18 [clangd] Use URIs instead of paths in the index file list
Without this patch the file list of the preamble index contains URIs, but other indexes file lists contain file paths.
This makes `indexedFiles()` always returns `IndexContents::None` for the preamble index, because current implementation expects file paths inside the file list of the index.

This patch fixes this problem and also helps to avoid a lot of URI to path conversions during indexes merge.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D97535
2021-03-06 10:47:05 +03:00
Kadir Cetinkaya 1d7b328198
[clangd] Introduce client state invalidation
Clangd can invalidate client state of features like semantic higlighting
without client explicitly triggering, for example after a preamble build
caused by an onSave notification on a different file.

This patch introduces a mechanism to let client know of such actions,
and also calls the workspace/semanticTokens/refresh request to
demonstrate the situation after each preamble build.

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

Differential Revision: https://reviews.llvm.org/D97548
2021-03-04 11:15:10 +01:00
Sam McCall bca3e24139 [clangd] Move DraftStore from ClangdLSPServer into ClangdServer.
ClangdServer already gets notified of every change, so it makes sense for it to
be the source of truth.
This is a step towards having ClangdServer expose a FS that includes dirty
buffers: D94554

Related changes:
 - version is now optional for ClangdServer, to preserve our existing fuzziness
   in this area (missing version ==> autoincrement)
 - ClangdServer::format{File,Range} are now more regular ClangdServer functions
   that don't need the code passed in. While here, combine into one function.
 - incremental content update logic is moved from DraftStore to
   ClangdLSPServer, with most of the implementation in SourceCode.cpp.
   DraftStore is now fairly trivial, and will probably ultimately be
   *replaced* by the dirty FS stuff.

Differential Revision: https://reviews.llvm.org/D97738
2021-03-02 22:58:50 +01:00
Sam McCall 588db1ccff [clangd] Use flags from open files when opening headers they include
Currently our strategy for getting header compile flags is something like:

A) look for flags for the header in compile_commands.json
   This basically never works, build systems don't generate this info.
B) try to match to an impl file in compile_commands.json and use its flags
   This only (mostly) works if the headers are in the same project.
C) give up and use fallback flags
   This kind of works for stdlib in the default configuration, and
   otherwise doesn't.

Obviously there are big gaps here.

This patch inserts a new attempt between A and B: if the header is
transitively included by any open file (whether same project or not),
then we use its compile command.

This doesn't make any attempt to solve some related problems:
 - parsing non-self-contained header files in context (importing PP state)
 - using the compile flags of non-opened candidate files found in the index

Fixes https://github.com/clangd/clangd/issues/123
Fixes https://github.com/clangd/clangd/issues/695
See https://github.com/clangd/clangd/issues/519

Differential Revision: https://reviews.llvm.org/D97351
2021-03-01 09:43:59 +01:00
lightmelodies 2e851c4172 [clangd] Populate detail field in document symbols
This commit fix https://github.com/clangd/clangd/issues/520 and https://github.com/clangd/clangd/issues/601.
{F15544293}

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D96751
2021-02-18 16:53:41 +01:00
Sam McCall 4dc8365f80 [clangd] Remove support for pre-standard semanticHighlighting notification
This is obsoleted by the standard semanticTokens request family.
As well as the protocol details, this allows us to remove a bunch of plumbing
around pushing highlights to clients.

This should not land until the new protocol has feature parity, see D77702.

Differential Revision: https://reviews.llvm.org/D95576
2021-02-10 22:09:03 +01:00
Sam McCall 59c1139d3e [clangd] Expose more dependent-name detail via semanticTokens
This change makes dependentName a modifier, rather than a token type.
It can be combined with:
- type (new, standard) - this combination replaces dependentType like T::typename Foo
- unknown (new, nonstandard) - for general dependent names
- Field, etc - when the name is dependent but we heuristically resolve it

While here, fix cases where template-template-parameter cases were
incorrectly flagged as type-dependent.
And the merging of modifiers when resolving conflicts accidentally
happens to work around a bug that showed up in a test.

The behavior observed through the pre-standard protocol should be mostly
unchanged (it'll see the bugfixes only). This is done in a somehat
fragile way but it's not expected to live long.

Differential Revision: https://reviews.llvm.org/D95706
2021-02-09 20:40:59 +01:00
Sam McCall 46cc7ce35a [clangd] Add semanticTokens modifiers for function/class/file/global scope
These allow (function-) local variables to be distinguished, but also a
bunch more cases.
It's not quite independent with existing information (e.g. the
field/variable distinction is redundant if you have class-scope + static
attributes) but I don't think this is terribly important.

Depends on D77811

Differential Revision: https://reviews.llvm.org/D95701
2021-02-09 17:57:36 +01:00
Sam McCall dd8fb21227 [clangd] Implement semanticTokens modifiers
- Infrastructure to support modifiers (protocol etc)
- standard modifiers:
  - declaration (but no definition, yet)
  - deprecated
  - readonly (based on a fairly fuzzy const checking)
  - static (for class members and locals, but *not* file-scope things!)
  - abstract (for C++ classes, and pure-virtual methods)
- nonstandard modifier:
  - deduced (on "auto" whose Kind is Class etc)
    Happy to drop this if it's controversial at all.
- While here, update sample tweak to use our internal names, in
  anticipation of theia TM scopes going away.

This addresses some of the goals of D77702, but leaves some things undone.
Mostly because I think these will want some discussion.
 - no split between dependent type/name.
   (We may want to model this as a modifier, type+dependent vs ???+dependent)
 - no split between primitive/typedef.
   (Is introducing a nonstandard kind is worth this distinction?)
 - no nonstandard local attribute
   This probably makes sense, I'm wondering if we want others and how
   they fit together.

There's one minor regression in explicit template specialization declarations
due to a latent bug in findExplicitReferences, but fixing it after seems OK.

Differential Revision: https://reviews.llvm.org/D77811
2021-02-09 16:31:22 +01:00
Sam McCall ff4832dbff [clangd] Respect ReferencesParams.context.includeDeclarations
Unfortunately this treats overrides declarations as declarations, not as
references. I don't plan to land this until I have a fix for that issue.

Differential Revision: https://reviews.llvm.org/D95450
2021-02-01 17:07:02 +01:00
Haojian Wu 78c22fbce9 [clangd] Don't rely on builtin headers for document-link.test.
This test seems to be failing at HEAD.

Reviewed By: kadircet, sammccall

Differential Revision: https://reviews.llvm.org/D95670
2021-02-01 15:36:34 +01:00
Utkarsh Saxena 8bf7116d50 [clangd] Index local classes, virtual and overriding methods.
Previously we did not record local class declarations. Now with features like
findImplementation and typeHierarchy, we have a need to index such local
classes to accurately report subclasses and implementations of methods.

Performance testing results:
- No changes in indexing timing.
- No significant change in memory usage.
- **1%** increase in #relations.
- **0.17%** increase in #refs.
- **0.22%** increase #symbols.

**New index stats**
Time to index: **4:13 min**
memory usage **543MB**
number of symbols: **521.5K**
number of refs: **8679K**
number of relations: **49K**

**Base Index stats**
Time to index: **4:15 min**
memory usage **542MB**
number of symbols: **520K**
number of refs: **8664K**
number of relations: **48.5K**

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

Differential Revision: https://reviews.llvm.org/D94785
2021-01-19 16:18:48 +01:00
Sam McCall 213329d7c6 [clangd] Add server capability advertising hot-reloading of CDBs.
Currently some clients watch for CDB changes and restart clangd, now that we
can reload compile_commands.json ourselves this is counterproductive.
The capability allows this behavior to be phased out.

This is going to be a mild regression, as we do not actually watch for files on
disk and so new diagnostics need to wait until a rebuild is requested e.g. due
to file change (and the internal caches have expired).
However this is still a better tradeoff (and if it's important, we can request
the client to watch files for us in the future).

Differential Revision: https://reviews.llvm.org/D94222
2021-01-07 13:39:21 +01:00
Giulio Girardi 2f8d1e9eb2 [clangd] When querying drivers by binary, look in PATH too
Sometimes compile_commands.json databases are created without an
absolute path for the driver in the command field. By default the driver
name is appended to the current directory, however if no driver is found
in that location assume it was in the default PATH and try finding it
there

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D93600
2021-01-05 12:54:07 +01:00
Nathan James cfa1010c42
[clangd] Provide suggestions with invalid config keys
Update the config file warning when an unknown key is detected which is likely a typo by suggesting the likely key.
This won't suggest a key that has already been seen in the block.

Appends the fix to the diag, however right now there is no support for presenting that fix to the user.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D92990
2020-12-15 18:16:17 +00:00
Adam Czachorowski 3c5bed734f [clangd] ExpandAutoType: Do not offer code action on lambdas.
We can't expand lambda types anyway. Now we simply not offer the code
action instead of showing it and then returning an error in apply().

Differential Revision: https://reviews.llvm.org/D92847
2020-12-08 20:03:16 +01:00
Sam McCall fed9af29c2 [clangd] Publish config file errors over LSP
We don't act as a language server for these files (e.g. don't get open/close
notifications for them), but just blindly publish diagnostics for them.

This works reasonably well in coc.nvim and vscode: they show up in the
workspace diagnostic list and when you open the file.
The only update after the file is reparsed, not as you type which is a bit
janky, but seems a lot better than nothing.

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

Differential Revision: https://reviews.llvm.org/D92704
2020-12-07 11:07:32 +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 0a4f99c494 [clangd] Call hierarchy (ClangdLSPServer layer)
Differential Revision: https://reviews.llvm.org/D91124
2020-11-23 20:44:07 -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
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
Utkarsh Saxena 4bc085f5b3 [clangd] Add OverridenBy Relation to index.
This was previously explored in reviews.llvm.org/D69094.

Differential Revision: https://reviews.llvm.org/D91610
2020-11-18 06:59:49 +01:00
Kadir Cetinkaya 8741a76f5d
[clangd] Ensure we test for compatibility of serialized index format
Differential Revision: https://reviews.llvm.org/D91330
2020-11-13 17:06:23 +01:00
Sam McCall 686d8a0911 [clangd] Add index server request logging
- Add verbose logging of payloads
- Add public logging of request summaries
- fix non-logging of messages in request scopes (oops!)
- add test for public/non-public logging, extending pipeline_helper a bit.

We've accumulated quite a lot of duplication in the request handlers by now.
I should factor that out, but not in this patch...

Differential Revision: https://reviews.llvm.org/D90654
2020-11-11 23:58:18 +01:00
Kirill Bobyrev 8e9bde34e7 [clangd] NFC: Add more logging to remote index test 2020-11-11 08:24:09 +01:00
Sam McCall c29513f7e0 [clangd] Fix check-clangd with no clang built
- pass required=False to use_clang(), as we don't need it
- fix required=False (which was unused and rotted):
  - make derived substitutions conditional on it
  - add a feature so we can disable tests that need it
- conditionally disable our one test that depends on %resource_dir.
  This doesn't seem right from first principles, but isn't a big deal.

Differential Revision: https://reviews.llvm.org/D90528
2020-11-02 21:10:43 +01:00
Shoaib Meenai 6bd01b8184 [clangd] Account for vendor in version string
The vendor will be prefixed to the "clangd" and can be an arbitrary
string, so account for it in the test.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D90517
2020-11-02 09:04:44 -08:00
Kirill Bobyrev d0beda1b66 [clangd] Improve remote-index test
Introduce a separate thread that will kill `clangd-index-server` after 10 seconds regardless. This helps shut down the test if the server hangs and `stderr.readline()` does not contain inititalizatiton message. It prevents "necessary" waiting delay for the server warm-up and only introduces additional delay if the test fails.

It also makes use of `subprocess.Popen.kill()` which is a portable way of handling process shutdown and avoids using signals.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D90590
2020-11-02 10:55:17 +01:00
Kirill Bobyrev 76a168bce0 [clangd] Add lit tests for remote index
Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D90291
2020-11-02 08:38:16 +01:00
Sam McCall 5627ae6c50 [clangd] Support CodeActionParams.only
Differential Revision: https://reviews.llvm.org/D89126
2020-10-29 09:44:08 +01:00