Commit Graph

199 Commits

Author SHA1 Message Date
Haojian Wu 3fcca804b2 [clangd] Refine recoveryAST flags in clangd
so that we could start experiment for C.

Previously, these flags in clangd were only meaningful for C++. We need
to flip them for C, this patch repurpose these flags.

- if true, just set it.
- if false, just respect the value in clang.

this would allow us to keep flags on for C++, and optionally flip them on for C.

Differential Revision: https://reviews.llvm.org/D89233
2020-10-14 13:42:11 +02:00
Kadir Cetinkaya 35871fde55
[clangd] Record memory usages after each notification
Depends on D88415

Differential Revision: https://reviews.llvm.org/D88417
2020-10-12 15:25:29 +02:00
Sam McCall 7530b254e9 [clangd] Make the tweak filter a parameter to enumerateTweaks. NFC
(Required for CodeActionContext.only)

Differential Revision: https://reviews.llvm.org/D88724
2020-10-09 14:11:19 +02:00
Haojian Wu ba268d2fb0 [clangd] Fix a typo, NFC. 2020-10-08 09:35:49 +02:00
Haojian Wu 9c09e2055e [clangd] Add a NewName optional parameter to clangdServer::prepareRename.
If the NewName is provided, prepareRename would perform a name
validation.

The motivation is to allow our internal embeder implement the customized
"canRenameInto" functionality on top of prepareRename.

Differential Revision: https://reviews.llvm.org/D88881
2020-10-07 21:18:51 +02:00
Haojian Wu 8a3cbb1535 [clangd] Add basic keyword-name-validation in rename.
Differential Revision: https://reviews.llvm.org/D88875
2020-10-06 15:47:57 +02:00
Haojian Wu 0f0cbcc4b1 [clangd] Extend the rename API.
several changes:
- return a structure result in rename API;
- prepareRename now returns more information (main-file occurrences);
- remove the duplicated detecting-touch-identifier code in prepareRename (which is implemented in rename API);

Differential Revision: https://reviews.llvm.org/D88634
2020-10-02 16:03:44 +02:00
Sam McCall 17747d2ec8 [clangd] Remove Tweak::Intent, use CodeAction kind directly. NFC
Intent was a nice idea but it ends up being a bit awkward/heavyweight
without adding much.

In particular, it makes it hard to implement `CodeActionParams.only` properly
(there's an inheritance hierarchy for kinds).

Differential Revision: https://reviews.llvm.org/D88427
2020-10-02 11:14:23 +02:00
Haojian Wu 667867e0df [clangd] Enable recovery-ast-type by default.
Differential Revision: https://reviews.llvm.org/D86602
2020-08-26 16:47:04 +02:00
Nathan Ridge 15673d748a [clangd] Index refs to main-file symbols as well
Summary: This will be needed to support call hierarchy

Reviewers: kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83536
2020-08-18 00:30:07 -04:00
Sam McCall 41d0edd54e [clangd] Express dumpAST in tests as a customAction() 2020-08-13 14:27:32 +02:00
Sam McCall 32626bcc0b [clangd] Add ClangdServer::customAction() extension point
This lets basic AST-consuming actions be defined outside clangdserver.
(it essentially exposes TUScheduler::runWithAST).

Two use cases for now:
 - replace ClangdServer::dumpAST, which doesn't really belong in the public
   interface (a followup patch will do this)
 - allow embedders to add/experiment with extra features
   (e.g. I know some who want to try crazy AST+ML code completion...)

Maybe in the future we should use this sort of mechanism to make ClangdServer
less of a monolith, but that's not in scope for now.
This would probably require a richer and more carefully-thought-out API.

Differential Revision: https://reviews.llvm.org/D85883
2020-08-13 12:26:32 +02:00
Kirill Bobyrev 7a514c9bf8
[clangd] Implement textDocument/foldingRange
Summary:
This patch introduces basic textDocument/foldingRange support. It relies on
textDocument/documentSymbols to collect all symbols and uses takes ranges
to create folds.

The next steps for textDocument/foldingRange support would be:

* Implementing FoldingRangeClientCapabilities and respecting respect client
  preferences
* Specifying folding range kind
* Migrating from DocumentSymbol implementation to custom RecursiveASTVisitor flow that will allow more flexibility
* Supporting more folding range types: comments, PP conditional regions, includes and other code regions (e.g. public/private/protected sections of classes, control flow statement bodies)

Tested: (Neo)Vim (coc-clangd) and VSCode.

Related issue: https://github.com/clangd/clangd/issues/310

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: nridge, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82436
2020-07-14 09:28:42 +02:00
Kadir Cetinkaya 1c7c5019a7
[clangd] Enable async preambles by default
Summary:
We've been testing this internally for a couple weeks now and it seems
to be stable enough. Let's flip the flag before branch cut to increase testing
coverage and have enough time to revert if need be.

Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83290
2020-07-09 10:57:45 +02:00
Sam McCall 15a60fe09f [clangd] Config: compute config in TUScheduler and BackgroundIndex
Summary:
ClangdServer owns the question of exactly which config to create, but
TUScheduler/BackgroundIndex control threads and so decide at which point
to inject it.

Reviewers: kadircet

Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83095
2020-07-04 11:18:14 +02:00
Sam McCall ffa63dde8e [clangd] Run formatting operations asynchronously.
Summary:
They don't need ASTs or anything, so they should still run immediately.

These were sync for historical reasons (they predate clangd having a pervasive
threading model). This worked ok as they were "cheap".
Aside for consistency, there are a couple of reasons to make them async:
 - they do IO (finding .clang-format) so aren't trivially cheap
 - having TUScheduler involved in running these tasks means we can use it as
   an injection point for configuration.
   (TUScheduler::run will need to learn about which file is being operated on,
   but that's an easy change).
 - adding the config system adds more potential IO, too

Reviewers: kbobyrev

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82642
2020-07-01 00:52:08 +02:00
Kadir Cetinkaya 8d654df5b9
[clangd] Rename FSProvider to TFS in case of ThreadsafeFS
Summary: Depends on D81998

Reviewers: sammccall

Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82024
2020-06-19 12:12:03 +02:00
Kadir Cetinkaya 0628705efa
[clangd][NFC] Rename FSProvider and getFileSystem
Summary:
Clangd uses FSProvider to get threadsafe views into file systems. This
patch changes naming to make that more explicit.

Depends on D81920

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D81998
2020-06-19 12:12:03 +02:00
Haojian Wu 1e87261ba1 [clangd] Turn on RecoveryAST for clangd by default.
Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D81739
2020-06-15 11:26:32 +02:00
Kadir Cetinkaya 1f4ba66ecc
[clangd] Run PreambleThread in async mode behind a flag
Summary: Depends on D80198.

This patch implies ASTs might be built with stale preambles without
blocking for a fresh one. It also drops any guarantees on every preamble
version being built. In case of multiple preamble build requests, in
addition to being debounced.

Any preamble requested with a WantDiags::Yes will always be built, this
is ensured by blocking enqueueing of any subsequent reqest.

AST worker will still block for initial preamble to reduce duplicate
work.

Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, jfb, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80293
2020-05-29 13:20:46 +02:00
Haojian Wu 0320ce8916 [clangd] Add a flag to preserve type for recovery expression.
Reviewers: sammccall

Reviewed By: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79938
2020-05-19 15:21:57 +02:00
Sam McCall fa1f4cf843 [clangd] Rename FormattedString -> Markup, move to support. NFC 2020-05-02 14:53:47 +02:00
Sam McCall ad97ccf6b2 [clangd] Move non-clang base pieces into separate support/ lib. NFCI
Summary:
This enforces layering, reduces a sprawling clangd/ directory, and makes life
easier for embedders.

Reviewers: kbobyrev

Subscribers: mgorny, ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, jfb, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79014
2020-04-29 15:57:12 +02:00
Sam McCall 808c2855e1 [clangd] Add tests that no-op changes are cheap
Summary:
We want to be sure they don't cause AST rebuilds or evict items from the cache.
D77847 is going to start sending spurious no-op changes (in case the preamble
was invalidated), this is cheap enough but we shouldn't regress that in future.

Reviewers: kadircet

Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, jfb, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D78048
2020-04-14 16:15:23 +02:00
Sam McCall fc830106e1 [clangd] Don't send semanticHighlights to clients that support semanticTokens.
Summary: This allows the standard mechanism to gracefully displace the old one.

Reviewers: hokein

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77206
2020-04-02 17:38:02 +02:00
Haojian Wu 72439b6b95 [clangd] Add a flag to turn on recovery-expr.
Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77142
2020-04-01 09:03:56 +02:00
Sam McCall 71177ac168 [clangd] Support new semanticTokens request from LSP 3.16.
Summary:
This is a simpler request/response protocol.

Reference: https://github.com/microsoft/vscode-languageserver-node/blob/master/protocol/src/protocol.semanticTokens.proposed.ts

No attempt to support incremental formatting (yet).

Reviewers: hokein

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D76663
2020-03-31 15:14:35 +02:00
Sam McCall 8f237f9b09 [clangd] Support multiple cursors in selectionRange.
Summary:
One change: because there's no way to signal failure individually for
each cursor, we now "succeed" with an empty range with no parent if a
cursor doesn't point at anything.

Reviewers: usaxena95

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D76741
2020-03-25 17:59:09 +01:00
Sam McCall edf6a19adf [clangd] Rename theia-derived semantic highlighting protocol. NFC
This feature is being added to LSP with a different (request-response)
protocol in 3.16, so this should avoid some confusion.
2020-03-24 00:39:47 +01:00
Sam McCall 2cd33e6fe6 [clangd] Track document versions, include them with diags, enhance logs
Summary:
This ties to an LSP feature (diagnostic versioning) but really a lot
of the value is in being able to log what's happening with file versions
and queues more descriptively and clearly.

As such it's fairly invasive, for a logging patch :-\

Key decisions:
 - at the LSP layer, we don't reqire the client to provide versions (LSP
   makes it mandatory but we never enforced it). If not provided,
   versions start at 0 and increment. DraftStore handles this.
 - don't propagate magically using contexts, but rather manually:
   addDocument -> ParseInputs -> (ParsedAST, Preamble, various callbacks)
   Context-propagation would hide the versions from ClangdServer, which
   would make producing good log messages hard
 - within ClangdServer, treat versions as opaque and unordered.
   std::string is a convenient type for this, and allows richer versions
   for embedders. They're "mandatory" but "null" is a reasonable default.

Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75582
2020-03-05 01:22:32 +01:00
Sam McCall c0b27c4891 [clangd] Remove unused getDocument() API 2020-03-03 14:53:59 +01:00
Haojian Wu c443b610bf [clangd] Remove the deprecated clangdServer::rename API, NFC.
There is no actual user of it now.
2020-03-02 09:48:25 +01:00
Haojian Wu 34d0e1bd6d [clangd] Expose the rename LimitFiles option to the C++ API, NFC.
Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74834
2020-02-26 09:33:58 +01:00
Sam McCall 7d3f8b1e2d [clangd] Debounce rebuilds responsively to rebuild times.
Summary:
Old: 500ms always. New: rebuild time, up to 500ms.

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

Reviewers: hokein

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73949
2020-02-23 15:34:28 +01:00
David Goldman 6ff0228c6d [clang] Add `forceReload` clangd extension to 'textDocument/didChange'
Summary:
- This option forces a preamble rebuild to handle the odd case
  of a missing header file being added

Reviewers: sammccall

Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, jfb, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73916
2020-02-10 14:02:02 -05:00
Sam McCall 2f4c4d0a78 Reland "[clangd] Mechanism to make update debounce responsive to rebuild speed."
This reverts commit ed98994f64.
Removed the accidental double-mutex-unlock.
2020-02-04 17:17:53 +01:00
Sam McCall ed98994f64 Revert "[clangd] Mechanism to make update debounce responsive to rebuild speed."
This reverts commit 92570718a8.
Breaking tests: http://45.33.8.238/linux/9296/step_9.txt
2020-02-04 15:34:10 +01:00
Sam McCall 92570718a8 [clangd] Mechanism to make update debounce responsive to rebuild speed.
Summary:
Currently we delay AST rebuilds by 500ms after each edit, to wait for
further edits. This is a win if a rebuild takes 5s, and a loss if it
takes 50ms.

This patch sets debouncepolicy = clamp(min, ratio * rebuild_time, max).
However it sets min = max = 500ms so there's no policy change or actual
customizability - will do that in a separate patch.

See https://github.com/clangd/clangd/issues/275

Reviewers: hokein

Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73873
2020-02-04 12:28:20 +01:00
Sam McCall b79cb54712 [clangd] Refactor TUScheduler options into a struct. NFC 2020-02-03 11:20:48 +01:00
Haojian Wu fce8983a3c [clangd] Remove the temporary alias for clangd::DiagnosticConsumer.
Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73619
2020-01-29 14:50:58 +01:00
Sam McCall 76fa5d50f3 [clangd] Remove pesky ;. NFC 2020-01-24 16:12:00 +01:00
Sam McCall 6ef1ccecf7 [clangd] Rename DiagnosticsConsumer -> ClangdServer::Callbacks, and make it optional
Summary:
This reflects its current function better and avoids confusion with clang::DiagnosticConsumer.

The old name/constructor is left around temporarily for compatibility.
(Metagame: merging with out-of-tree changes is harder than usual this month)

Reviewers: hokein

Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73346
2020-01-24 15:59:32 +01:00
Sam McCall 7d20e80225 [clangd] Show background index status using LSP 3.15 work-done progress notifications
Summary:
It simply shows the completed/total items on the background queue, e.g.
 indexing: 233/1000
The denominator is reset to zero every time the queue goes idle.

The protocol is fairly complicated here (requires creating a remote "progress"
resource before sending updates). We implement the full protocol, but I've added
an extension allowing it to be skipped to reduce the burden on clients - in
particular the lit test takes this shortcut.

The addition of background index progress to DiagnosticConsumer seems ridiculous
at first glance, but I believe that interface is trending in the direction of
"ClangdServer callbacks" anyway. It's due for a rename, but otherwise actually
fits.

Reviewers: kadircet, usaxena95

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, jfb, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D73218
2020-01-24 12:21:08 +01:00
Sam McCall 8d7ecc1629 Revert "Revert "[clangd] Implement "textDocument/documentLink" protocol support""
This reverts commit 079ef783dd.

The revert describes a test failure without details, after offline
discussion this in in a private/unsupported build system and doesn't
seem to reflect a real upstream bug.
2020-01-02 16:36:21 +01:00
Dmitri Gribenko 079ef783dd Revert "[clangd] Implement "textDocument/documentLink" protocol support"
This reverts commit d6417f5584. The tests
depend on builtin headers, which is not intentionally supported in
clangd tests; these tests are broken in some build environments.
2019-12-16 15:21:51 +01:00
Michael Forster d6417f5584 [clangd] Implement "textDocument/documentLink" protocol support
Summary:
This adds an implementation for the "textDocument/documentLink" LSP request.

It returns links for all `#include` directives to the resolved target files.

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

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70872
2019-12-12 14:55:20 +01:00
Haojian Wu 852bafae2b [clangd] Implement cross-file rename.
Summary:
This is the initial version. The cross-file rename is purely based on
the index.

It is hidden under a command-line flag, and only available for a small set
of symbols.

Reviewers: ilya-biryukov, sammccall

Subscribers: merge_guards_bot, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69263
2019-11-26 10:04:31 +01:00
Sam McCall 765b1250f6 [clangd] Untangle Hover from XRefs, move into own file.
Summary:
This is mostly mechanical, with a few exceptions:
 - getDeducedType moved into AST.h where it belongs. It now takes
   ASTContext instead of ParsedAST, and avoids using the preprocessor.
 - hover now uses SelectionTree directly rather than via
   getDeclAtPosition helper
 - hover on 'auto' used to find the decl that contained the 'auto' and
   use that to set Kind and documentation for the hover result.
   Now we use targetDecl() to find the decl matching the deduced type instead.
   This changes tests, e.g. 'variable' -> class for auto on lambdas.
   I think this is better, but the motivation was to avoid depending on
   the internals of DeducedTypeVisitor. This functionality is removed
   from the visitor.

Reviewers: kadircet

Subscribers: mgorny, ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70357
2019-11-19 15:11:37 +01:00
Haojian Wu 5181adab61 [clangd] Expose the xref's incomplete flag to clangdServer API.
Summary: so that clangd C++ API users (via ClangdServer) can access it.

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70380
2019-11-18 13:27:19 +01:00
Haojian Wu d6d5eddcdb [clangd] Use the index-based API to do the header-source switch.
Summary:
If the file heuristic fails, we try to use the index&AST to do the
header/source inference.

Reviewers: kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

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

llvm-svn: 373320
2019-10-01 10:21:15 +00:00