Commit Graph

305 Commits

Author SHA1 Message Date
Haojian Wu 7438df9960 Remove an unused var decl, NFC. 2022-09-23 11:54:50 +02:00
Haojian Wu 16987998e6 [clangd] Fix LineFoldingOnly flag is not propagated correctly to ClangdServer.
The Opts.LineFoldingOnly must be set before the clangdServer
construction, otherwise this flag is always false when using clangd in VSCode.

Differential Revision: https://reviews.llvm.org/D133299
2022-09-05 15:55:29 +02:00
Utkarsh Saxena c338735020 [clangd] Enable folding ranges by default.
Differential Revision: https://reviews.llvm.org/D132919
2022-08-30 12:04:59 +02:00
Utkarsh Saxena a11ec00afe FoldingRanges: Handle LineFoldingsOnly clients.
Do not fold the endline which contains tokens after the end of range.

Differential Revision: https://reviews.llvm.org/D131154
2022-08-29 19:03:48 +02:00
Kadir Cetinkaya 83411bf06f
[clangd] Support for standard type hierarchy
This is mostly a mechanical change to adapt standard type hierarchy
support proposed in LSP 3.17 on top of clangd's existing extension support.

This does mainly two things:
- Incorporate symbolids for all the parents inside resolution parameters, so
  that they can be retrieved from index later on. This is a new code path, as
  extension always resolved them eagerly.
- Propogate parent information when resolving children, so that at least one
  branch of parents is always preserved. This is to address a shortcoming in the
  extension.

This doesn't drop support for the extension, but it's deprecated from now on and
will be deleted in upcoming releases. Currently we use the same struct
internally but don't serialize extra fields.

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

Differential Revision: https://reviews.llvm.org/D131385
2022-08-17 09:29:15 +02:00
Kazu Hirata 5cff5142a8 Use value instead of getValue (NFC) 2022-07-15 20:03:13 -07:00
Sam McCall 93cd159ca9 [clangd] Remove `allCommitCharacters`
This was added in 2a095ff6f5, however it never worked with VSCode
due to bugs in vscode-languageclient
(https://github.com/microsoft/vscode-languageserver-node/issues/673).
Now that it does work, we can tell the interactions with text editing, with
snippets, and vscode's select-first-completion behavior are bad.

The spec is vague and clients could do something reasonable with the
current values. However they could clearly do something unreasonable
too, and over time behavior+spec tends to converge on VSCode's behavior.

This addresses https://github.com/clangd/vscode-clangd/pull/358
See also https://github.com/clangd/vscode-clangd/pull/358 which hotfixes
this on the client-side (as we can't apply this change retroactively to
clangd 12-14).

Differential Revision: https://reviews.llvm.org/D129579
2022-07-12 21:42:38 +02:00
Kadir Cetinkaya 333620d37a
[clangd] Support multiline semantic tokens
Per LSP, multiline tokens should be handled as if they end at the end
of the line starting the token (there's also a capability to enable them, but
that's an adventure for a different day).

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

Differential Revision: https://reviews.llvm.org/D127856
2022-06-29 13:49:03 +02:00
Kazu Hirata 94460f5136 Don't use Optional::hasValue (NFC)
This patch replaces x.hasValue() with x where x is contextually
convertible to bool.
2022-06-26 19:54:41 -07:00
Kazu Hirata 3b7c3a654c Revert "Don't use Optional::hasValue (NFC)"
This reverts commit aa8feeefd3.
2022-06-25 11:56:50 -07:00
Kazu Hirata aa8feeefd3 Don't use Optional::hasValue (NFC) 2022-06-25 11:55:57 -07:00
Kazu Hirata 5413bf1bac Don't use Optional::hasValue (NFC) 2022-06-20 11:33:56 -07:00
Kazu Hirata 5dd171dcb5 [clang-tools-extra] Use value_or instead of getValueOr (NFC) 2022-06-19 00:13:38 -07:00
Kadir Cetinkaya 3137ca80b9
[clangd] Support for standard inlayHint protocol
- Make clangd's internal representation more aligned with the standard.
  We keep range and extra inlayhint kinds around, but don't serialize
  them on standard version.
- Have custom serialization for extension (ugly, but going to go away).
- Support both versions until clangd-17.
- Don't advertise extension if client has support for standard
  implementation.
- Log a warning at startup about extension being deprecated, if client
  doesn't have support.

Differential Revision: https://reviews.llvm.org/D125228
2022-05-10 18:59:15 +02:00
Sam McCall 4d006520b8 [clangd] Clean up unused includes. NFCI
Add includes where needed to fix build.
Haven't systematically added used headers, so there is still accidental
dependency on transitive includes.
2022-02-26 12:00:16 +01:00
Christian Kandeler bd6c6974f5
clangd: Set a diagnostic on a code action resulting from a tweak
... if there is a match.
This is needed to that clients can can make a connection between a
diagnostic and an associated quickfix-tweak.
Ideally, quickfix-kind tweak code actions would be provided inline along
with the non-tweak fixes, but this doesn't seem easily achievable.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D118976
2022-02-10 15:58:12 +01:00
Christian Kühnel 8edfc2f814 [clangd] Cleanup of readability-identifier-naming
Auto-generated patch based on clang-tidy readability-identifier-naming.
Only some manual cleanup for `extern "C"` declarations and a GTest change was required.

I'm not sure if this cleanup is actually very useful. It cleans up clang-tidy findings to the number of warnings from clang-tidy should be lower.  Since it was easy to do and required only little cleanup I thought I'd upload it for discussion.

One pattern that keeps recurring: Test **matchers** are also supposed to start with a lowercase letter as per LLVM convention. However GTest naming convention for matchers start with upper case. I would propose to keep stay consistent with the GTest convention there. However that would imply a lot of `//NOLINT` throughout these files.

To re-product this patch run:
```
run-clang-tidy -checks="-*,readability-identifier-naming" -fix -format ./clang-tools-extra/clangd
```

To convert the macro names, I was using this script with some manual cleanup afterwards:
https://gist.github.com/ChristianKuehnel/a01cc4362b07c58281554ab46235a077

Differential Revision: https://reviews.llvm.org/D115634
2022-02-01 13:31:52 +00:00
Sam McCall 71a082f726 [clangd] Implement textDocument/typeDefinition
This reuses the type=>decl mapping from go-to-definition on auto.
(Which could stand some improvement, but that can happen later).

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

Differential Revision: https://reviews.llvm.org/D116443
2022-01-13 22:15:10 +01:00
Sam McCall 54eb70886c [clangd] Remove --inlay-hints flag
Differential Revision: https://reviews.llvm.org/D117036
2022-01-13 10:02:28 +01:00
Sam McCall 7c19fdd599 [clangd] Polish clangd/inlayHints and expose them by default.
This means it's a "real feature" in clangd 14, albeit one that requires special
client support.

- remove "preview" from the flag description
- expose the `clangdInlayHints` capability by default
- provide `position` as well as `range`
- support `InlayHintsParams.range` to restrict the range retrieved
- inlay hint list is in document order (sorted by position)

Still to come: control feature via config rather than flag.

Fixes https://github.com/clangd/clangd/issues/313
Protocol doc is in https://github.com/llvm/clangd-www/pull/56/files

Differential Revision: https://reviews.llvm.org/D116699
2022-01-07 15:12:43 +01:00
Sam McCall 92417eaf33 [CodeCompletion] Signature help for braced constructor calls
Implementation is based on the "expected type" as used for
designated-initializers in braced init lists. This means it can deduce the type
in some cases where it's not written:

  void foo(Widget);
  foo({ /*help here*/ });

Only basic constructor calls are in scope of this patch, excluded are:
 - aggregate initialization (no help is offered for aggregates)
 - initializer_list initialization (no help is offered for these constructors)

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

Differential Revision: https://reviews.llvm.org/D116317
2022-01-03 20:14:59 +01:00
Sam McCall cd45e8c7bc [CodeCompletion] Signature help for template argument lists
Provide signature while typing template arguments: Foo< ^here >
Here the parameters are e.g. "typename x", and the result type is e.g.
"struct" (class template) or "int" (variable template) or "bool (std::string)"
(function template).

Multiple overloads are possible when a template name is used for several
overloaded function templates.

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

Differential Revision: https://reviews.llvm.org/D116352
2022-01-03 16:28:16 +01:00
Kadir Cetinkaya 1a929525e8
[clangd] Return error for textdocument/outgoingCalls rather than success 2021-12-21 17:06:59 +01:00
Kadir Cetinkaya 517f1d9e5c
[clangd] Add ) to signature-help triggers
It is important for nested function calls.

Differential Revision: https://reviews.llvm.org/D115799
2021-12-15 14:56:27 +01:00
Kadir Cetinkaya d3606a3375
[clangd] Provide documentation as MarkupContent in signaturehelp
This unifies the behaviour we have in code completion item
documentations and signaturehelp. Providing better line wrapping and detection
of inline code blocks in comments to be renedered appropriately in markdown.

Differential Revision: https://reviews.llvm.org/D115442
2021-12-10 12:58:08 +01:00
Sam McCall f764a1a5bd [clangd] Avoid possible crash: apply configuration after binding methods
The configuration may kick off indexing, which may involve sending LSP
messages.
The crash is fiddly to reproduce in a hermetic test (we need background
indexing on without disk storage, and to handle server->client messages
in LSPClient...)

Fixes https://github.com/clangd/clangd/issues/926
2021-11-20 01:13:38 +01:00
Christian Kühnel ec4a2c9565 [NFC][clangd] cleanup llvm-else-after-return findings
Cleanup of clang-tidy findings: removing "else" after a return statement
to improve readability of the code.

This patch was created by applying the clang-tidy fixes automatically.

Differential Revision: https://reviews.llvm.org/D113892
2021-11-17 14:37:03 +00:00
Adam Czachorowski 8fbac4e88a [clangd] Add code completion of param name on /* inside function calls.
For example, if you have:
  void foo(int bar);
  foo(/*^
it should auto-complete to "bar=".

Because Sema callbacks for code completion in comments happen before we
have an AST we need to cheat in clangd by detecting completion on /*
before, moving cursor back by two characters, then running a simplified
verion of SignatureHelp to extract argument name(s) from possible
overloads.

Differential Revision: https://reviews.llvm.org/D110823
2021-10-19 12:49:46 +02:00
Sam McCall 4ad9ec8a32 [clangd] Rename Features.h -> Feature.h to avoid confilct with libstdc++
Fixes https://github.com/clangd/clangd/issues/835

Differential Revision: https://reviews.llvm.org/D107624
2021-08-06 18:56:41 +02:00
Sam McCall e2559e5dc6 [clangd] Add platform triple (host & target) to version info
Useful in logs to understand issues around some platforms we don't have much
experience with (e.g. m1, mingw)

Differential Revision: https://reviews.llvm.org/D105681
2021-07-27 14:25:17 +02:00
Sam McCall 0c96a92d86 [clangd] Log feature configuration (linux+asan+grpc) of the clangd build
Included in logs, --version, remote index queries, and LSP serverInfo.

Differential Revision: https://reviews.llvm.org/D100553
2021-06-30 17:49:29 +02:00
Kadir Cetinkaya dc10bf1a4e
[clangd][Protocol] Drop optional from WorkspaceEdit::changes
This is causing weird code patterns in various places and I can't see
any difference between None and empty change list. Neither in the current use
cases nor in the spec.

Differential Revision: https://reviews.llvm.org/D103449
2021-06-02 22:59:18 +02:00
Christian Kandeler f088af37e6
[clangd] Fix data type of WorkDoneProgressReport::percentage
According to the specification, this should be an unsigned integer.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D101616
2021-05-10 14:57:20 +02:00
Kirill Bobyrev e623ce6188
[clangd] Split CC and refs limit and increase refs limit to 1000
Related discussion: https://github.com/clangd/clangd/discussions/761

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D101902
2021-05-05 23:39:48 +02:00
Nathan Ridge cea736e5b8 [clangd] Hide inlay hints capability behind a command-line flag
Differential Revision: https://reviews.llvm.org/D101275
2021-05-03 01:01:57 -04:00
Nathan James 6815037085
[clangd][NFC] Remove unnecessary string captures in lambdas.
Due to a somewhat annoying, but necessary, shortfall in -Wunused-lambda-capture, These unused captures aren't warned about.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D101611
2021-04-30 13:27:24 +01: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
Sam McCall ca13f5595a [clangd] Add `limit` extension on completion and workspace-symbols
This overrides the --limit-results command-line flag, and is not constrained
by it.
See https://github.com/clangd/clangd/issues/707

Differential Revision: https://reviews.llvm.org/D97801
2021-03-16 12:28:01 +01:00
Sam McCall 3b99731c4e [clangd] Turn off implicit cancellation based on client capabilities
Capability is in upcoming 3.17: https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/

(This is also useful for C++ embedders)

Differential Revision: https://reviews.llvm.org/D98414
2021-03-16 12:27:40 +01: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
Nathan James 0250b053b5
[clangd] Add a Filesystem that overlays Dirty files.
Create a `ThreadsafeFS` in the `DraftStore` that overlays the dirty file contents over another `ThreadsafeFS`.
This provides a nice thread-safe interface for using dirty file contents throughout the codebase, for example cross file refactoring.
Creating a Filesystem view will overlay a snapshot of the current contents, so if the draft store is updated while the view is being used, it will contain stale contents.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D94554
2021-03-09 14:35:21 +00:00
Sam McCall a60d06d8b7 [clangd] Rename Module -> FeatureModule to avoid confusion. NFC
As pointed out in D96244, "Module" is already pretty overloaded to refer
to clang and llvm modules. (And clangd deals directly with the former).

FeatureModule is a bit of a mouthful but it's pretty self-descriptive.
I think it might be better than "Component" which doesn't really capture
the "common interface" aspect - it's IMO confusing to refer to
"components" but exclude CDB for example.

Differential Revision: https://reviews.llvm.org/D97950
2021-03-05 10:04:00 +01: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
Haojian Wu b218f7c4ba [clangd] NFC, remove an extra "class" keyword. 2021-02-25 09:32:36 +01:00
Sam McCall 7b83837af6 [clangd] Bind outgoing calls through LSPBinder too. NFC
The redundancy around work-done-progress is annoying but ok for now.

There's a weirdness with context lifetimes around outgoing method calls, which
I've preserved to keep this NFC. We should probably fix it though.

Differential Revision: https://reviews.llvm.org/D96717
2021-02-17 10:56:06 +01:00
Sam McCall 4d700fb060 [clangd] Pass raw client capabilities to modules. NFC 2021-02-15 20:57:14 +01:00
Sam McCall 6c5f17e701 [clangd] Delay binding LSP methods until initialize. NFC
This is NFC because the MessageHandler refused to dispatch to them until the
server is initialized anyway.

This is a more natural time to bind them - it's when they become callable, and
it's when client capabalities are available and server ones can be set.

One module-lifecycle function will be responsible for all three.

Differential Revision: https://reviews.llvm.org/D96608
2021-02-15 19:33:40 +01:00
Sam McCall 0b55ecce45 [clangd] Allow modules to bind LSP methods/notifications/commands
Differential Revision: https://reviews.llvm.org/D96625
2021-02-15 11:00:14 +01:00
Sam McCall 5786f64a4e [clangd] Extract binding of typed->untyped LSP handlers to LSPBinder. NFC
The goal is to allow the LSP bindings of features to be defined outside
the ClangdLSPServer class, turning it into less of a monolith.

Differential Revision: https://reviews.llvm.org/D96544
2021-02-15 10:48:14 +01:00