Commit Graph

69 Commits

Author SHA1 Message Date
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 cb9be3fa55 [clangd] Remove the hanging lit exit-signal.test.
The test was introduced in
19ac0eaf07.

The test keeps hanging after running "check-clangd", remove it now
and will add it back later after investigations.
2019-12-04 12:35:16 +01:00
Sam McCall 19ac0eaf07 [clangd] Shutdown cleanly on signals.
Summary:
This avoids leaking PCH files if editors don't use the LSP shutdown protocol.

This is one fix for https://github.com/clangd/clangd/issues/209
(Though I think we should *also* be unlinking the files)

Reviewers: kadircet, jfb

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70684
2019-11-27 12:38:49 +01:00
Nathan Ridge b2e6c2b995 [clangd] Inactive regions support as an extension to semantic highlighting
Differential Revision: https://reviews.llvm.org/D67536
2019-11-21 19:40:55 -05:00
Ilya Biryukov c814f4c459 [clangd] Do not highlight keywords in semantic highlighting
Summary:
Editors are good at highlightings the keywords themselves.
Note that this only affects highlightings of builtin types spelled out
as keywords in the source code. Highlightings of typedefs to builtin
types are unchanged.

Reviewers: hokein

Reviewed By: hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69431
2019-10-28 12:03:09 +01:00
Nathan Ridge 37e31e629d [clangd] Improve semantic highlighting in dependent contexts (fixes #154)
Reviewers: hokein

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

Tags: #clang

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

llvm-svn: 374799
2019-10-14 18:26:13 +00:00
Nico Weber eecef1e5a5 clangd tests: use extended regex with sed
The escaped parens seem to confuse the combination of lit, cygwin
quoting, and cygwin's sed. unxutils sed in cmd.exe is fine with both
forms, so use the extended regex form that doesn't need an escaped
paren.

llvm-svn: 374753
2019-10-14 03:44:47 +00:00
Nico Weber 282b36c1ce convert another test to unix line endings
llvm-svn: 374752
2019-10-14 02:21:12 +00:00
Nico Weber 61d2655690 convert a test to unix line endings
llvm-svn: 374751
2019-10-14 02:14:18 +00:00
Nico Weber a05d254b82 fix typo in 374747
llvm-svn: 374750
2019-10-14 01:44:29 +00:00
Nico Weber 1f1703f5c7 Prefer 'env not' over 'not env' in tests.
That way, lit's builtin 'env' command can be used for the 'env' bit.

Also it's clearer that way that the 'not' shouldn't cover 'env'
failures.

llvm-svn: 374749
2019-10-14 01:41:56 +00:00
Nico Weber 9f1bb5b9a8 Make symbols.test pass on Windows.
See commit message of r374746 for details.

Hopefully final bit of PR43592.

llvm-svn: 374747
2019-10-14 01:19:53 +00:00
Nico Weber 3e54997e77 Make code-action-request.test and request-reply.test pass on Windows.
clangd's test:// scheme expands to /clangd-test on non-Win and to
C:/clang-test on Win, so it can't be mixed freely with
file:///clangd-test since that's wrong on Windows. This makes both
tests consistenly use the test:// scheme. (Alternatively, we could use
the //INPUT_DIR pattern used in a few other tests.)

Part of PR43592.

llvm-svn: 374746
2019-10-14 01:00:33 +00:00
Nico Weber c445c0cb0a Don't run background-index.test on Windows.
The test had a "UNSUPPORTED: win32" line, but the spelling of that
changed in r339307 a year ago. Finally update this test too.

Part of PR43592.

llvm-svn: 374745
2019-10-14 00:45:02 +00:00
Nico Weber 5d8870bc76 Add missing "REQUIRES: shell" to system-include-extractor.test
Part of PR43592.

llvm-svn: 374730
2019-10-13 17:43:16 +00:00
Nico Weber 29f7e17cb8 Try to get clangd tests passing on Windows.
Part of PR43592. See also r328645.

llvm-svn: 373932
2019-10-07 17:55:05 +00:00
Utkarsh Saxena 55925da4c9 [clangd] Add semantic selection to ClangdLSPServer.
Summary:
This adds semantic selection to the LSP Server.
Adds support for serialization of input request and the output reply.
Also adds regression tests for the feature.

Currently we do not support multi cursor.The LSP Server only accepts single position in the request as opposed to many position in the spec.

Spec:
https://github.com/microsoft/language-server-protocol/blob/dbaeumer/3.15/specification.md#textDocument_selectionRange

Reviewers: hokein

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

Tags: #clang

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

llvm-svn: 372753
2019-09-24 13:38:33 +00:00
Ilya Biryukov e237520a8f [clangd] Add a new highlighting kind for typedefs
Summary:
We still attempt to highlight them as underlying types, but fallback to
the generic 'typedef' highlighting kind if the underlying type is too
complicated.

Reviewers: hokein

Reviewed By: hokein

Subscribers: nridge, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

llvm-svn: 371402
2019-09-09 14:33:10 +00:00
Johan Vikstrom becbdc66dc [clangd] Add highlighting for macro expansions.
Summary: https://github.com/clangd/clangd/issues/134

Reviewers: hokein, ilya-biryukov

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

Tags: #clang

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

llvm-svn: 370482
2019-08-30 15:47:27 +00:00
Nathan Ridge bd0f840f83 [clangd] Add distinct highlightings for static fields and methods
Reviewers: hokein, ilya-biryukov, jvikstrom

Reviewed By: hokein

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

Tags: #clang

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

llvm-svn: 370429
2019-08-30 03:37:24 +00:00
Nathan Ridge 86a4a530f4 [clangd] Add a distinct highlighting for local variables
Summary:
It's useful to be able to distinguish local variables from namespace
scope variables.

Reviewers: hokein, jvikstrom

Reviewed By: hokein

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

Tags: #clang

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

llvm-svn: 370103
2019-08-27 19:39:11 +00:00
Haojian Wu 0a6000f2cb [clangd] Send highlighting diff beyond the end of the file.
Summary: This would make the client life (tracking the changes) easier.

Reviewers: jvikstrom

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

Tags: #clang

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

llvm-svn: 369884
2019-08-26 08:38:45 +00:00
Johan Vikstrom 17587b36d1 [clangd] Added special HighlightingKind for function parameters.
Summary: This means that function parameters are no longer highlighted as variable.other.cpp but instead as variable.parameter.cpp which is the more "correct" TextMate scope for them.

Reviewers: hokein, ilya-biryukov

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

Tags: #clang

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

llvm-svn: 369238
2019-08-19 07:51:39 +00:00
Haojian Wu 8b49173a82 [clangd] Use raw rename functions to implement the rename.
Summary:
The API provided by refactoring lib doesn't provide enough flexibility
to get clangd's rename to behave as we expect. Instead, we replace it
with the low-level rename functions, which give us more control.

Bonus:
- performance, previously we visit the TU to find all occurrences,
  now we just visit top-level decls from main file;
- fix a bug where we wrongly filter out the main file replacement due to the
  different relative/absolute file path;

Reviewers: sammccall

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

Tags: #clang

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

llvm-svn: 368429
2019-08-09 10:55:22 +00:00
Johan Vikstrom d73d994746 [clangd] Added semantic highlighting support for primitives.
Summary:
Adds a new HighlightingKind "Primitive". Adds a special case for TypeLocs that have an underlying TypePtr that is are builtin types, adding them as primitives.
The primary reason for this change is because otherwise typedefs that typedef primitives `typedef int A` would not get highlighted (so in the example `A` would not get any highlightings.)

Reviewers: hokein, ilya-biryukov

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

Tags: #clang

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

llvm-svn: 368291
2019-08-08 13:10:30 +00:00
Haojian Wu f25163498b [clangd] Add a callback mechanism for handling responses from client.
Summary:
The callback will be invoked in clangd when we receive a reply from the client.

This is a prerequisite of implementing a generic mechanism for chainable
refactorings (e.g. extract variable and rename), this would allow server to
trigger a new request to the LSP client after receiving a reply from the client.

Reviewers: sammccall

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

Tags: #clang

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

llvm-svn: 367845
2019-08-05 12:48:09 +00:00
Johan Vikstrom c2653ef27c [clangd] Duplicate lines of semantic highlightings sent removed.
Summary: Added a class for diffing highlightings and removing duplicate lines. Integrated into the highlighting generation flow. Only works correctly if all tokens are on a single line. Also returns empty lines if the IDE should remove previous highlightings on a line.

Reviewers: hokein, sammccall, ilya-biryukov

Subscribers: MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits

Tags: #clang

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

llvm-svn: 367521
2019-08-01 08:08:44 +00:00
Sam McCall 8faffec4e2 [clangd] Also accept flags from CLANGD_FLAGS variable.
This simplifies various workflows, particularly in debugging/development.
e.g. editors will tend to propagate flags, so you can run
`env CLANGD_FLAGS=-input-mirror-file=/tmp/mirror vim foo.cc` rather than
change the configuration in a persistent way.
(This also gives us a generic lever when we don't know how to customize
the flags in some particular LSP client).

While here, add a test for this and other startup logging, and fix a
couple of direct writes to errs() that should have been logs.

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

llvm-svn: 366991
2019-07-25 07:54:48 +00:00
Haojian Wu f429ab60e6 [clangd] Implement "prepareRename"
Summary:
- "prepareRename" request is added in LSP v3.12.0
- also update the vscode-client dependency to pick-up the rename bug fix[1]

[1]: https://github.com/microsoft/vscode-languageserver-node/issues/447

Reviewers: sammccall

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

Tags: #clang

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

llvm-svn: 366873
2019-07-24 07:49:23 +00:00
Kadir Cetinkaya 91e5f4b46b Revert "Revert r366458, r366467 and r366468"
This reverts commit 9c377105da.

[clangd][BackgroundIndexLoader] Directly store DependentTU while loading shard

Summary:
We were deferring the population of DependentTU field in LoadedShard
until BackgroundIndexLoader was consumed. This actually triggers a use after
free since the shards FileToTU was pointing at could've been moved while
consuming the Loader.

Reviewers: sammccall

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

Tags: #clang

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

llvm-svn: 366559
2019-07-19 10:18:52 +00:00
Azharuddin Mohammed 9c377105da Revert r366458, r366467 and r366468
r366458 is causing test failures. r366467 and r366468 had to be reverted as
they were casuing conflict while reverting r366458.

r366468 [clangd] Remove dead code from BackgroundIndex
r366467 [clangd] BackgroundIndex stores shards to the closest project
r366458 [clangd] Refactor background-index shard loading

llvm-svn: 366551
2019-07-19 09:26:33 +00:00
Kadir Cetinkaya f3ae501d36 [clangd] Handle windows line endings in QueryDriver
Summary:
The previous patch did not fix the end mark. D64789
fixes second case of https://github.com/clangd/clangd/issues/93

Patch by @lh123 !

Reviewers: sammccall, kadircet

Reviewed By: kadircet

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

Tags: #clang-tools-extra, #clang

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

llvm-svn: 366545
2019-07-19 09:08:22 +00:00
Kadir Cetinkaya 006d1915e2 [clangd] BackgroundIndex stores shards to the closest project
Summary:
Changes persistance logic to store shards at the directory of closest
CDB. Previously we were storing all shards to directory of the CDB that
triggered indexing, it had its downsides.

For example, if you had two TUs coming from a different CDB but depending on the
same header foo.h, we will store the foo.h only for the first CDB, and it would
be missing for the second and we would never persist it since it was actually
present in the memory and persisted before.

This patch still stores only a single copy of a shard, but makes the directory a
function of the file name. So that the shard place will be unique even with
multiple CDBs accessing the file. This directory is determined as the first
directory containing a CDB in the file's parent directories, if no such
directory exists we make use of the home directory.

Reviewers: sammccall

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

Tags: #clang

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

llvm-svn: 366467
2019-07-18 17:20:41 +00:00
Johan Vikstrom 51cdd51807 [clangd] Added highlightings for template parameters and specializations.
Summary: Template parameters and specializations were not being highlighted before. This adds highlightings to those types of tokens by adding two Visit* methods.

Reviewers: hokein, sammccall, ilya-biryukov

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

Tags: #clang

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

llvm-svn: 366420
2019-07-18 09:56:38 +00:00
Kadir Cetinkaya 6011a285ed [clangd] Handle windows line endings in QueryDriver
Summary: fixes second case of https://github.com/clangd/clangd/issues/93

Reviewers: sammccall

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

Tags: #clang

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

llvm-svn: 366320
2019-07-17 13:14:02 +00:00
Johan Vikstrom 17b4a932fa [clangd] Added highlighting for members and methods.
Summary: Added highlighting for members and methods.

Reviewers: hokein, sammccall, ilya-biryukov

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

Tags: #clang

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

llvm-svn: 366047
2019-07-15 08:12:21 +00:00
Johan Vikstrom d02f17daed [clangd] Added highlighting to enum constants.
Summary: VSCode does not have a scope for enum constants. So they were placed under "constant.other.enum" as that seems to be the most correct scope for enum constants. However, this makes theia color them blue (the same color it uses for keywords).

Reviewers: hokein, sammccall, ilya-biryukov

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

Tags: #clang

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

llvm-svn: 366045
2019-07-15 07:41:12 +00:00
Nathan Ridge 087b044c49 [clangd] Implement typeHierarchy/resolve for subtypes
Summary:
This allows the client to resolve subtypes one level at a time.

For supertypes, this is not necessary, because we eagerly compute
supertypes and return all levels.

Reviewers: sammccall

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

Tags: #clang

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

llvm-svn: 365986
2019-07-13 03:24:48 +00:00
Russell Gallop de54e2c4df Revert "[clangd] Implement typeHierarchy/resolve for subtypes"
Causing test failure on Windows bot

This reverts commit 5b9484e559.

llvm-svn: 365899
2019-07-12 13:35:58 +00:00
Haojian Wu 210a9b6aee [clangd] Move the expandAuto tweak from global namespace into annoymous namespace.
llvm-svn: 365885
2019-07-12 09:38:53 +00:00
Nathan Ridge 5b9484e559 [clangd] Implement typeHierarchy/resolve for subtypes
Summary:
This allows the client to resolve subtypes one level at a time.

For supertypes, this is not necessary, because we eagerly compute
supertypes and return all levels.

Reviewers: sammccall

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

Tags: #clang

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

llvm-svn: 365867
2019-07-12 03:26:32 +00:00
Sam McCall 9470142ca5 [clangd] Implementation of auto type expansion.
Add a tweak for clangd to replace an auto keyword to the deduced type.

This way a user can declare something with auto and then have the
IDE/clangd replace auto with whatever type clangd thinks it is. In case
of long/complext types this makes is reduces writing effort for the
user.

The functionality is similar to the hover over the auto keyword.

Example (from the header):

```
/// Before:
///    auto x = Something();
///    ^^^^
/// After:
///    MyClass x = Something();
///    ^^^^^^^
```

Patch by kuhnel! (Christian Kühnel)
Differential Revision: https://reviews.llvm.org/D62855

llvm-svn: 365792
2019-07-11 16:04:18 +00:00
Johan Vikstrom b6a74e33c3 [clangd] Added highlightings for namespace specifiers.
Summary: Added highlightings for namespace specifiers.

Reviewers: hokein, sammccall, ilya-biryukov

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

Tags: #clang

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

llvm-svn: 365745
2019-07-11 09:29:16 +00:00
Johan Vikstrom eff868fdef [clangd] Added highlighting for class and enum types.
Summary: Added highlighting for non-builtin types using VisitTypeLoc. Ignoring namespace qualifiers as for now.

Reviewers: hokein, sammccall, ilya-biryukov

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

Tags: #clang

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

llvm-svn: 365602
2019-07-10 08:41:25 +00:00
Sam McCall 2f760c44e6 [clangd] Rewrite of logic to rebuild the background index serving structures.
Summary:
Previously it was rebuilding every 5s by default, which was much too frequent
in the long run - the goal was to provide an early build. There were also some
bugs. There were also some bugs, and a dedicated thread was used in production
but not tested.

 - rebuilds are triggered by #TUs built, rather than time. This should scale
   more sensibly to fast vs slow machines.
 - there are two separate indexed-TU thresholds to trigger index build: 5 TUs
   for the first build, 100 for subsequent rebuilds.
 - rebuild is always done on the regular indexing threads, and is affected by
   blockUntilIdle. This means unit/lit tests run the production configuration.
 - fixed a bug where we'd rebuild after attempting to load shards, even if there
   were no shards.
 - the BackgroundIndexTests don't really test the subtleties of the rebuild
   policy (for determinism, we call blockUntilIdle, so rebuild-on-idle is enough
   to pass the tests). Instead, we expose the rebuilder as a separate class and
   have fine-grained tests for it.

Reviewers: kadircet

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

Tags: #llvm

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

llvm-svn: 365531
2019-07-09 18:30:49 +00:00
Haojian Wu ee08036df8 [clangd] Deduplicate clang-tidy diagnostic messages.
Summary:
Clang-tidy checks may emit duplicated messages (clang-tidy tool
deduplicate them in its custom diagnostic consumer), and we may show
multiple duplicated diagnostics in the UI, which is really bad.

This patch makes clangd do the deduplication, and revert the change
rL363889.

Reviewers: sammccall

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

Tags: #clang

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

llvm-svn: 365204
2019-07-05 12:57:56 +00:00
Kadir Cetinkaya 04531ba3a2 [clangd] Query driver reads stderr and passes driver as first argument
Summary:
gcc invokes cc1 through a path deduced from argv[0] therefore it must
be correctly set.
Also it prints the search path to stderr not stdout, this also applies to clang.

Reviewers: sammccall

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

Tags: #clang

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

llvm-svn: 365132
2019-07-04 11:34:23 +00:00
Johan Vikstrom c1ead0e1b5 [clangd] Add missing changes for 365111
llvm-svn: 365112
2019-07-04 08:06:48 +00:00
Johan Vikstrom a848dab7a3 [clangd] Emit publishSemanticHighlighting in LSP if enabled
Summary: Emit publishSemanticHighlighting in LSP if enabled

Reviewers: hokein, kadircet

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

Tags: #clang

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

llvm-svn: 365111
2019-07-04 07:53:12 +00:00