Commit Graph

1392 Commits

Author SHA1 Message Date
Johan Vikstrom b865d5a425 [clangd] Added an early return from VisitMemberExpr in SemanticHighlighting if underlying MemberDecl is a CXXConversionDecl.
Summary:
Conversion operators contain invalid MemberLocs which caused SemanticHighlighting
to emit a lot of error logs in large files as they can occur fairly
often (for example converting StringRef to std string).
As the only thing happening was a lot of error logs being
emited there doesn't really seem to be any way to test this
(no erroneous tokens are added). But emiting as many logs as
were being emited is not wanted.

This also adds a test to guard against regressions for highlightings
disapearing from places where the conversion operators are used as their
behaviour differ from the other CXXMethodDecls.

Reviewers: hokein, ilya-biryukov

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

Tags: #clang

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

llvm-svn: 368287
2019-08-08 12:43:55 +00:00
Haojian Wu bdc022a695 [clangd] Don't include internal gtest header.
llvm-svn: 368283
2019-08-08 12:33:12 +00:00
Haojian Wu 34166ec80b [clangd] Remove a function accidently being added in rL368261.
llvm-svn: 368282
2019-08-08 12:19:01 +00:00
Haojian Wu 1c0c7ed6af [clangd] Correct the documentation, NFC.
llvm-svn: 368277
2019-08-08 10:58:16 +00:00
Johan Vikstrom 720d19b175 [clangd] Fix implicit template instatiations appearing as topLevelDecls.
Summary: The parser gives implicit template instantiations to the action's HandleTopLevelDecls callback. This makes semantic highlighting highlight these templated functions multiple times. Fixed by filtering on if a Decl is an implicit function/variable/class instantiation. Also added a testcase to semantic highlighting on this.

Reviewers: hokein, ilya-biryukov

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

Tags: #clang

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

llvm-svn: 368261
2019-08-08 07:21:06 +00:00
Sam McCall 0e8dd4a80e Code completion should not ignore default parameters in functions.
Summary:
Inorder to display the default arguments we must process the
CK_Optional chunks of CodeCompletionString while creating the Signature.

We do not create placeholders for default arguments.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

llvm-svn: 368186
2019-08-07 16:52:21 +00:00
Johan Vikstrom 57ced1e155 [clangd] Added a TextMate theme parser to the vscode extension.
Summary:
Adds a TextMate parser module to the vscode extension. It parses a theme into an array of a pair of TextMate scopes and text colors.

Reviewers: hokein, ilya-biryukov

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

Tags: #clang

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

llvm-svn: 368136
2019-08-07 08:48:52 +00:00
Sam McCall 957380714d [clangd] Unfold SourceLocation flattening from findNameLoc in preparation for adding more overloads. NFC
llvm-svn: 368083
2019-08-06 20:25:59 +00:00
Shaurya Gupta 8fbb6ce847 Fixed toHalfOpenFileRange assertion fail
Summary:
- Added new function that gets Expansion range with both ends in the same file.
- Fixes the crash at https://github.com/clangd/clangd/issues/113

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

Tags: #clang

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

llvm-svn: 368058
2019-08-06 17:01:12 +00:00
Ilya Biryukov 56bdb0c508 [clangd] Compute scopes eagerly in IncludeFixer
Summary:
Computing lazily leads to crashes. In particular, computing scopes may
produce diagnostics (from inside template instantiations) and we
currently do it when processing another diagnostic, which leads to
crashes.

Moreover, we remember and access 'Scope*' when computing scopes. This
might lead to invalid memory access if the Scope is deleted by the time
we run the delayed computation. We did not actually construct an example
when this happens, though.

From the VCS and review history, it seems the optimization was
introduced in the initial version without a mention of any performance
benchmarks justifying the performance gains. This led me to a
conclusion that the optimization was premature, so removing it to avoid
crashes seems like the right trade-off at that point.

Reviewers: sammccall

Reviewed By: sammccall

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

Tags: #clang

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

llvm-svn: 368019
2019-08-06 11:37:50 +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
Sam McCall 801d3304e9 [clangd] Expose -offset-encoding=utf-32, which has been implemented for ages
llvm-svn: 367812
2019-08-05 08:14:17 +00:00
Sam McCall 6b09e9c864 [clangd] Fix error message with incorrect TextDocumentcontentChangeEvent.rangeLength
llvm-svn: 367811
2019-08-05 08:14:13 +00:00
Ilya Biryukov 25082817eb [clangd] Fix a crash when presenting values for Hover
Summary:
We should pass the expression type, not a variable type when printing
the resulting value. Variable type may be different from what the
pretty-printing function expects, e.g. have references.

Reviewers: sammccall

Reviewed By: sammccall

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

Tags: #clang

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

llvm-svn: 367687
2019-08-02 15:23:04 +00:00
Haojian Wu 13a81444cd [clangd][vscode] clang-format the the extension code.
Summary:
As we are going to grow the extension in the near future, it is time to
formalize the TS code format/style of our extension (although we'd lose the
history).

We use default options of clang-format:
- 80 max line length
- 2 space indent

Reviewers: ilya-biryukov, sammccall, jvikstrom

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

Tags: #clang

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

llvm-svn: 367684
2019-08-02 14:24:02 +00:00
Simon Pilgrim 4cfd015beb Fix "not all control paths return a value" warning. NFCI.
llvm-svn: 367678
2019-08-02 12:55:04 +00:00
Sam McCall ad66e95b0d [clangd] Remove bad assert: nothing relies on it, and the reasons it was true no longer hold.
llvm-svn: 367672
2019-08-02 10:39:46 +00:00
Sam McCall ac7864ec01 [clangd] Add new helpers to make tweak tests scale better. Convert most tests. NFC
Summary:
TweakTests.cpp has some pretty good helpers added for the first few
tweaks, but they have some limitations:
 - many assertion failures point at the wrong line
 - need lots of input/output tests, setup code is duplicated across both
 - local helpers make it hard to split the file as it grows

The new helpers in TweakTests.h are based on old ones (same operations)
but try to address these issues and generally make tests more terse
while improving error messages.

This patch converts everything except ExtractVariable (which is complex
and has changes in flight, so will be converted later).
It's LOC-neutral, despite not being able to get rid of the old helpers
until ExtractVariable is done.

Reviewers: ilya-biryukov

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

Tags: #clang

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

llvm-svn: 367667
2019-08-02 09:12:39 +00:00
Harlan Haskins a02f85768d [clang-tools-extra] Adopt FileManager's error-returning APIs
The FileManager has been updated to return llvm::ErrorOr from getFile
and getDirectory, this commit updates all the callers of those APIs from
clang.

llvm-svn: 367617
2019-08-01 21:32:01 +00:00
Ilya Biryukov 2fe0a14b5a [clangd] Add missing braces to completion tests. NFC
llvm-svn: 367541
2019-08-01 11:05:06 +00:00
Johan Vikstrom e5b5742eed [clangd] Fix buildbot failure from ambigous ArrayRef ctor
llvm-svn: 367529
2019-08-01 09:08:41 +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 abe3c29a8c [clangd] Ignore semicolons, whitespace, and comments in SelectionTree.
Summary:
Whitespace and comments are a clear bugfix: selecting some
comments/space near a statement doesn't mean you're selecting the
surrounding block.

Semicolons are less obvious, but for similar reasons: these tokens
aren't actually claimed by any AST node (usually), so an AST-based model
like SelectionTree shouldn't take them into account.

Callers may still sometimes care about semis of course:
 - when the selection is an expr with a non-expr parent, selection of
   the semicolon indicates intent to select the statement.
 - when a statement with a trailing semi is selected, we need to know
   its range to ensure it can be removed.
SelectionTree may or may not play a role here, but these are separate questions
from its core function of describing which AST nodes were selected.

The mechanism here is the TokenBuffer from syntax-trees. We use it in a
fairly low-level way (just to get boundaries of raw spelled tokens). The
actual mapping of AST nodes to coordinates continues to use the (fairly
mature) SourceLocation based logic. TokenBuffer/Syntax trees
don't currently offer an alternative to getFileRange(), I think.

Reviewers: SureYeaah, kadircet

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

Tags: #clang

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

llvm-svn: 367453
2019-07-31 17:52:40 +00:00
Shaurya Gupta 8eb5ba583c [Clangd] NFC: Added FIXME in ExtractVariable tests
llvm-svn: 367406
2019-07-31 10:08:29 +00:00
Jan Korous c32e10794d [clangd][NFC] Fix typo in comment
llvm-svn: 367361
2019-07-30 22:18:04 +00:00
Jan Korous 2ee6497e8f [clangd][NFC] Typo in comment
llvm-svn: 367354
2019-07-30 20:39:39 +00:00
Haojian Wu debf4817f4 [clangd] Fix a regression in rL366996.
Summary: That patch made the tweak always annotate the whole file by accident.

Reviewers: jvikstrom

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

Tags: #clang

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

llvm-svn: 367313
2019-07-30 14:17:45 +00:00
Kadir Cetinkaya 38496d5bd9 [clangd] Ignore diags from builtin files
Summary:
This fixes a case where we show diagnostics on arbitrary lines, in an
internal codebase.

Open for ideas on unittesting this.

Reviewers: ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

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

llvm-svn: 367303
2019-07-30 10:26:51 +00:00
Bjorn Pettersson f0f63cab7f [clangd] Fix NDEBUG build problem introduced by rL366698
Sprinkled some #ifndef NDEBUG in Selection.cpp to make
it possible to build with NDEBUG defined.

The problem was introduced in rL366698 when using dlog
for some debug printouts. The dlog macro expands to
DEBUG_WITH_TYPE, which isn't using it's arguments in
optimized builds (when NDEBUG is defined).

llvm-svn: 367178
2019-07-27 17:09:15 +00:00
Sam McCall 91e8eac73a [clangd] Support extraction of binary "subexpressions" like a + [[b + c]].
Summary:
These aren't formally subexpressions in C++, in this case + is left-associative.
However informally +, *, etc are usually (mathematically) associative and users
consider these subexpressions.

We detect these and in simple cases support extracting the partial expression.
As well as builtin associative operators, we assume that overloads of them
are associative and support those too.

Reviewers: SureYeaah

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

Tags: #clang

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

llvm-svn: 367121
2019-07-26 15:29:52 +00:00
Shaurya Gupta 76ba1cf1f1 [Clangd] Disable ExtractVariable for all types of assignments
Reviewers: sammccall, kadircet

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

Tags: #clang

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

llvm-svn: 367113
2019-07-26 14:08:27 +00:00
Sam McCall 7ee0867a85 [clangd] Fix background index not triggering on windows due to case mismatch.
Summary:
This isn't a general fix to all paths where we assume case-sensitivity, it's
a minimally-invasive fix targeting the llvm 9 branch.

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

Tags: #clang

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

llvm-svn: 367112
2019-07-26 14:07:11 +00:00
Haojian Wu 18fa729a39 [clangd] Fix the annotate tweak after rL366893
Summary:
After rL366893, the annoate tweak is not activated when we select the
whole file (the commonAncestor is TUDecl but we intend to return null).

This patch fixes this, and also avoid traversing the TUDecl.

Reviewers: sammccall

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

Tags: #clang

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

llvm-svn: 366996
2019-07-25 08:48:05 +00:00
Sam McCall 85d2fe7861 [clangd] Provide help text to users who run `clangd` in a terminal.
Reviewers: hokein

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

Tags: #clang

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

llvm-svn: 366992
2019-07-25 08:00:54 +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
Sam McCall 9842310a2a [clangd] Add categories to help options, and only show clangd options.
Summary:
Restricting the categories prevents extra unwanted options from creeping into
help (D60663), and removes a bunch of noise from --help-hidden.

While here, remove `static` from the opts in favor of an anon namespace, to
reduce the noise level.

Reviewers: hokein

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

Tags: #clang

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

llvm-svn: 366900
2019-07-24 12:41:52 +00:00
Sam McCall bdc6b6e410 [clangd] SelectionTree treats TranslationUnitDecl (mostly) consistently with other containers.
Summary:
Previously TranslationUnitDecl would never be selected.
This means root() is never null, and returns a reference.

commonAncestor() is in principle never null also, but returning TUDecl
here requires tweaks to be careful not to traverse it (this was already
possible when selecting multiple top-level decls, and there are associated bugs!)
Instead, never allow commonAncestor() to return TUDecl, return null instead.

Reviewers: hokein

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

Tags: #clang

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

llvm-svn: 366893
2019-07-24 12:14:56 +00:00
Sam McCall 2ff40ca367 [clangd] Fix SelectionTree traversal of qualified types
Summary:
QualifiedTypeLoc isn't treated like a regular citizen by RecursiveASTVisitor.
This meant we weren't intercepting the traversal of its inner TypeLoc.

Most of the changes here are about exposing kind() so we can improve the
precision of our tests.

This should fix the issue raised in D65067.

Reviewers: hokein

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

Tags: #clang

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

llvm-svn: 366882
2019-07-24 09:39:11 +00:00
Sam McCall 6076788c5b [clangd] Reformat use of cl::opt: use unqualified name and don't bin-pack attributes. NFC
Reviewers: kadircet

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

Tags: #clang

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

llvm-svn: 366880
2019-07-24 09:33:27 +00:00
Haojian Wu ec4d8cdd59 [clangd] Bump vscode-clangd v0.0.16
CHANGELOG:
- detect C++ language based on some well-known file paths
- upgrade the lsp-client and lsp-server dependencies

llvm-svn: 366877
2019-07-24 08:14:29 +00:00
Haojian Wu 0e7bbb1122 [clangd] Update a stale comment, NFC.
llvm-svn: 366875
2019-07-24 07:57:25 +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
Shaurya Gupta b0ed5bea88 [Clangd] Fixed ExtractVariable for certain types of Exprs
Summary:

- Modified ExtractVariable for extraction of MemberExpr, DeclRefExpr and Assignment Expr
- Removed extraction from label statements.
- Fixed unittests

Reviewers: sammccall, kadircet

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

Tags: #clang

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

llvm-svn: 366869
2019-07-24 05:42:55 +00:00
Sam McCall 4389cb9cf1 [clangd] Log version, cwd, args, and transport on startup. NFC
Reviewers: hokein

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

Tags: #clang

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

llvm-svn: 366811
2019-07-23 14:30:28 +00:00
Sam McCall 7fc8f415ea [clangd] Add dlog()s for SelectionTree, enabling -debug-only=SelectionTree.cpp
Summary:
SelectionTree is a RecursiveASTVisitor which processes getSourceRange() for
every node. This is a lot of surface area with the AST, as getSourceRange()
is specialized for *many* node types.
And the resulting SelectionTree depends on the source ranges of many
visited nodes, and the order of traversal.

Put together, this means we really need a traversal log to debug when we
get an unexpected SelectionTree. I've built this ad-hoc a few times, now
it's time to check it in.

Example output:
```
D[14:07:44.184] Computing selection for </usr/local/google/home/sammccall/test.cc:1:7, col:8>
D[14:07:44.184]  push: VarDecl const auto x = 42
D[14:07:44.184]   claimRange: </usr/local/google/home/sammccall/test.cc:1:12, col:13>
D[14:07:44.184]   push: NestedNameSpecifierLoc (empty NestedNameSpecifierLoc)
D[14:07:44.184]   pop: NestedNameSpecifierLoc (empty NestedNameSpecifierLoc)
D[14:07:44.184]   push: QualifiedTypeLoc const auto
D[14:07:44.184]   pop: QualifiedTypeLoc const auto
D[14:07:44.184]    claimRange: </usr/local/google/home/sammccall/test.cc:1:7, col:11>
D[14:07:44.184]    hit selection: </usr/local/google/home/sammccall/test.cc:1:7, col:8>
D[14:07:44.184]   skip: IntegerLiteral 42
D[14:07:44.184]    skipped range = </usr/local/google/home/sammccall/test.cc:1:16>
D[14:07:44.184]  pop: VarDecl const auto x = 42
D[14:07:44.184]   claimRange: </usr/local/google/home/sammccall/test.cc:1:1, col:18>
D[14:07:44.184]  skip: VarDecl int y = 43
D[14:07:44.184]   skipped range = </usr/local/google/home/sammccall/test.cc:2:1, col:9>
D[14:07:44.184] Built selection tree
TranslationUnitDecl
  VarDecl const auto x = 42
     .QualifiedTypeLoc const auto

```

Reviewers: hokein

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

Tags: #llvm

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

llvm-svn: 366698
2019-07-22 15:55:53 +00:00
Sam McCall 1df6be211e [clangd] Set buffer name for main file. NFCI
llvm-svn: 366675
2019-07-22 11:12:16 +00:00
Ilya Biryukov af5d3b02fb [clangd] Log input code of failed highlighting tests. NFC
llvm-svn: 366674
2019-07-22 10:05:11 +00:00
Ilya Biryukov 8bb8915d43 [clangd] Provide a way to publish highlightings in non-racy manner
Summary:
By exposing a callback that can guard code publishing results of
'onMainAST' callback in the same manner we guard diagnostics.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: javed.absar, MaskRay, jkorous, arphaman, kadircet, hokein, jvikstrom, cfe-commits

Tags: #clang

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

llvm-svn: 366577
2019-07-19 13:51:01 +00:00
Kadir Cetinkaya 9dc0160d26 [clangd] Disable background-index on lit-tests by default
Summary:
Since background-index can perform disk writes, we don't want to turn
it on tests that won't clear it.

Reviewers: sammccall

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

Tags: #clang

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

llvm-svn: 366575
2019-07-19 13:40:30 +00:00
Shaurya Gupta 20a0e7caaf [Clangd] Fixed ExtractVariable test
llvm-svn: 366568
2019-07-19 12:11:04 +00:00