Commit Graph

2809 Commits

Author SHA1 Message Date
Sam McCall 91679c95bb [clangd] Include macro expansions in documentSymbol hierarchy
Browsing macro-generated symbols is confusing.
On the one hand, it seems very *useful* to be able to see the summary of
symbols that were generated.
On the other hand, some macros spew a lot of confusing symbols into the
namespace and when used repeatedly (ABSL_FLAG) can create a lot of spam
that's hard to navigate.

Design constraints:
 - the macro expansion tree need not align with the AST, though it often
   does in practice.
   We address this by defining the nesting based on the *primary*
   location of decls, rather than their ranges.
 - DocumentSymbol.children[*].range should nest within DocumentSymbol.range
   (This constraint is not in LSP "breadcrumbs" breaks without it)
   We adjust macro ranges so they cover their "children", rather than
   just the macro expansion
 - LSP does not have a "macro expansion" symbolkind, nor does it allow a
   symbol to have no kind. I've arbitrarily picked "null" as this is
   unlikely to conflict with anything useful.

This patch makes all macros and children visible for simplicity+consistency,
though in some cases it may be better to elide the macro node.
We may consider adding heuristics for this in future (e.g. when it expands
to one decl only?) but it doesn't seem clear-cut to me.

Differential Revision: https://reviews.llvm.org/D97615
2021-03-02 17:52:24 +01:00
Sam McCall 289fee4ab7 [clangd] Show hex value of numeric constants
Don't show negative numbers
Don't show numbers <10 (hex is the same as decimal)
Show numeric enum values in hex too

Differential Revision: https://reviews.llvm.org/D97226
2021-03-02 16:33:02 +01:00
Utkarsh Saxena bf935a034b [clangd] Make categorical features 64 bit in DecisionForest Model.
CodeCompletionContext::Kind has 36 Kinds. The completion model used to
support categorical features of 32 cardinality.
Due to this clangd tests were failing asan tests due to overflow.

This patch makes the completion model support 64 cardinality of
categorical features by storing ENUM Features as uint64_t instead of
uint32_t.

Verified that this fixes the asan failures.

Latency: 6.7ms (old) VS 6.8ms (new) per 1000 predictions.

Differential Revision: https://reviews.llvm.org/D97770
2021-03-02 16:22:30 +01:00
Sam McCall 7556abf821 [clangd] findExplicitReferences impl filters nulls centrally. NFC 2021-03-02 15:55:03 +01:00
Utkarsh Saxena 7f086d74c3 Revert "[clangd] Use ML Code completion ranking as default."
CodeCompletionContext::Kind has 36 Kinds. The completion model currently
only handles categorical features of 32 cardinality.
Changing the datatype to uint64_t will solve the problem.

This reverts commit 438b5bb05a.
2021-03-02 15:04:23 +01:00
Utkarsh Saxena bad8e577f9
Fix DecisionForestBenchmark.cpp compile errors
clang-tools-extra/clangd/benchmarks/CompletionModel/DecisionForestBenchmark.cpp fails to compile since `"CompletionModel.h"` is auto-generated from clang-tools-extra/clangd/quality/model/features.json, which was changed in https://reviews.llvm.org/D94697 to remove `setFilterLength` and `setIsForbidden`, rename `setFileProximityDistance` and `setSymbolScopeDistance`, and add `setNumNameInContext` and `setFractionNameInContext`.  This patch removes calls to the two removed functions, updates calls to the two renamed functions, and adds calls to the two new functions. (`20` is an arbitrary choice for the `setNumNameInContext` argument.) It also changes the `FlipCoin` argument from float to double to silence lossy conversion warnings.

Note: I don't use this tool but encountered the build errors and took a shot at fixing them. Please holler if there's another recommended solution. Thanks!

Reviewed By: usaxena95

Differential Revision: https://reviews.llvm.org/D97620
2021-03-02 10:27:46 +01:00
Utkarsh Saxena 438b5bb05a [clangd] Use ML Code completion ranking as default.
This makes code completion use a Decision Forest based ranking algorithm to rank
completion candidates. [Esitmated 6% accuracy boost]. This was
previously hidden behind the flag --ranking-model=decision_forest. This
patch makes it the default ranking algorithm.

Note: this is a generic model, not specialized for any particular
project. clangd does not collect or upload data to train code completion.

Also treat Keywords separately as they are not recorded by the training set generator.

Differential Revision: https://reviews.llvm.org/D96353
2021-03-02 10:05:37 +01:00
David Goldman 5a2141e3a0 [clangd] Improve document symbols support for Objective-C categories and methods
- Categories will now show up as `MyClass(Category)` instead of
  `Category` and `MyCategory()` instead of `(anonymous)` in document
  symbols

- Methods will now be shown as `-selector:` or `+selector:`
  instead of `selector:` to differentiate between instance and class
  methods in document symbols

Differential Revision: https://reviews.llvm.org/D96612
2021-03-01 12:37:31 -05: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
Kadir Cetinkaya 1a5dfb7db2
[clangd][remote] Add flag to set idletimeout
By default gRPC has no idletimeout and some firewalls might drop idle
connections after a certain period. This results in idle clients
shouting into void until server resets the connection.

Differential Revision: https://reviews.llvm.org/D97536
2021-02-26 15:04:44 +01:00
Haojian Wu b218f7c4ba [clangd] NFC, remove an extra "class" keyword. 2021-02-25 09:32:36 +01:00
Kadir Cetinkaya c94ecf3f81
[clangd] Fix a race
Differential Revision: https://reviews.llvm.org/D97366
2021-02-24 12:15:16 +01:00
Kadir Cetinkaya 7c9c0a87c8
[clang][DeclPrinter] Pass Context into StmtPrinter whenever possible
ASTContext were only passed to the StmtPrinter in some places, while it
is always available in DeclPrinter. The context is used by StmtPrinter to better
print statements in some cases, like printing constants as written.

Differential Revision: https://reviews.llvm.org/D97043
2021-02-23 09:42:19 +01:00
Shafik Yaghmour 50542d504d Modify TypePrinter to differentiate between anonymous struct and unnamed struct
Currently TypePrinter lumps anonymous classes and unnamed classes in one group "anonymous" this is not correct and can be confusing in some contexts.

Differential Revision: https://reviews.llvm.org/D96807
2021-02-22 14:16:43 -08:00
Sam McCall f0e69272c6 [clangd] Shutdown sequence for modules, and doc threading requirements
This allows modules to do work on non-TUScheduler background threads.

Differential Revision: https://reviews.llvm.org/D96755
2021-02-22 23:14:47 +01:00
Sam McCall 2d9cfcfef0 [clangd] Narrow and document a loophole in blockUntilIdle
blockUntilIdle of a parent can't always be correctly implemented as
  return ChildA.blockUntilIdle() && ChildB.blockUntilIdle()
The problem is that B can schedule work on A while we're waiting on it.

I believe this is theoretically possible today between CDB and background index.
Modules open more possibilities and it's hard to reason about all of them.

I don't have a perfect fix, and the abstraction is too good to lose. this patch:
 - calls out why we block on workscheduler first, and asserts correctness
 - documents the issue
 - reduces the practical possibility of spuriously returning true significantly

This function is ultimately only for testing, so we're driving down flake rate.

Differential Revision: https://reviews.llvm.org/D96856
2021-02-22 23:08:52 +01:00
Kadir Cetinkaya 6329ce75da
[clangd] Expose absoluteParent helper
Will be used in other components that need ancestor traversal.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D96123
2021-02-19 13:40:21 +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
Kirill Bobyrev 19db870a0d
[clangd] Drop template argument lists from completions followed by <
Now, given `template <typename T> foo() {}` when user types `fo^<int>()` the
completion snippet will not contain `<int>()`.

Also, when the next token is opening parenthesis (`(`) and completion snippet
contains template argument list, it is still emitted.

This patch complements D81380.

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

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D89870
2021-02-18 13:06:11 +01:00
Haojian Wu 7048cb5371 [clangd] IndexedFiles should include Fils from RefSlab and RelationSlab.
This looks like an oversight.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D96845
2021-02-17 15:41:09 +01:00
Haojian Wu e030de7e5a [clangd] Pass file when possible to resolve URI.
Some URI scheme needs the hint path to do a correct resolution, we pass
one of the open files as hint path.

This is not perfect, and it might not work for opening files across
project, but it would fix a bug with our internal scheme.

in the long run, removing URIs from all the index internals is a more proper fix.

Differential Revision: https://reviews.llvm.org/D96844
2021-02-17 15:33:50 +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
Kadir Cetinkaya cdef5a7161
[clangd] Fix windows buildbots after ecea7218fb 2021-02-16 20:57:08 +01:00
Kadir Cetinkaya ecea7218fb
[clangd] Treat paths case-insensitively depending on the platform
Path{Match,Exclude} and MountPoint were checking paths case-sensitively
on all platforms, as with other features, this was causing problems on
windows. Since users can have capital drive letters on config files, but
editors might lower-case them.

This patch addresses that issue by:
- Creating regexes with case-insensitive matching on those platforms.
- Introducing a new pathIsAncestor helper, which performs checks in a
  case-correct manner where needed.

Differential Revision: https://reviews.llvm.org/D96690
2021-02-16 20:20:53 +01:00
Sam McCall b6e52d8fa7 [clangd] Give modules access to filesystem, scheduler, and index.
This finally makes it possible to implement useful modules.

Differential Revision: https://reviews.llvm.org/D96726
2021-02-16 15:30:08 +01:00
Sam McCall 40cc63ea6e [clangd] Modules can have a public API. NFC
Differential Revision: https://reviews.llvm.org/D96730
2021-02-16 15:22:57 +01:00
Nathan Ridge 9510b09402 [clangd] Factor out the heuristic resolver code into its own class
The patch also does some cleanup on the interface of the entry
points from TargetFinder into the heuristic resolution code.

Since the heuristic resolver is created in a place where the
ASTContext is available, it can store the ASTContext and the
NameFactory hack can be removed.

Differential revision: https://reviews.llvm.org/D92290
2021-02-16 04:10:52 -05: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
Nathan James 022920c25b
[clangd] Retire clang-tidy-checks flag.
In clangd-12 the ability to override what clang tidy checks should run was moved into config.
For the 13 release its a wise progression to remove the command line option for this.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D96508
2021-02-13 14:14:22 +00:00
Kadir Cetinkaya d25fbaa4a4
[clangd] Fix unsued private field warning 2021-02-13 13:20:15 +01:00
Kadir Cetinkaya 2423a3863e
[clangd] Introduce Modules
Modules can be used to augment clangd's behaviours in various features.

Differential Revision: https://reviews.llvm.org/D96244
2021-02-12 18:37:16 +01:00
Sam McCall 8dd6dd947c [clangd] Work around presumed MSVC stdlib bug
http://45.33.8.238/win/33161/step_4.txt
2021-02-12 18:00:43 +01:00
Nathan James ba3ea9c60f
[clangd] Fix clang tidy provider when multiple config files exist in directory tree
Currently Clang tidy provider searches from the root directory up to the target directory, this is the opposite of how clang-tidy searches for config files.
The result of this is .clang-tidy files are ignored in any subdirectory of a directory containing a .clang-tidy file.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D96204
2021-02-12 16:55:46 +00:00
David Goldman 07c5a800dc Improve hover scopes for Objective-C code
- Instead of `AppDelegate::application:didFinishLaunchingWithOptions:` you
will now see `-[AppDelegate application:didFinishLaunchingWithOptions:]`

- Also include categories in the name when printing the scopes, e.g. `Class(Category)` and `-[Class(Category) method]`

Differential Revision: https://reviews.llvm.org/D68590
2021-02-12 10:27:32 -05:00
Sam McCall cea9f05432 [clangd] Move command handlers into a map in ClangdLSPServer. NFC
Differential Revision: https://reviews.llvm.org/D96507
2021-02-12 15:57:43 +01:00
Haojian Wu ee4dd0f876 [clangd] Remove the cross-file-rename option.
and simplify the code.

Differential Revision: https://reviews.llvm.org/D96578
2021-02-12 15:38:55 +01:00
Haojian Wu 573348ab9b [clangd] Retire the cross-file-rename command-line flag.
This patch only focuses on the flag. Removing actual single-file mode
(and the flag in RenameOption) will come in a follow-up.

Differential Revision: https://reviews.llvm.org/D96495
2021-02-11 20:28:50 +01:00
Haojian Wu 6c47eafb39 [clang][index] report references from unreslovedLookupExpr.
Fix https://github.com/clangd/clangd/issues/675

Differential Revision: https://reviews.llvm.org/D96262
2021-02-11 11:08:26 +01:00
Sam McCall 5c55d3747b [CodeComplete] Member completion: heuristically resolve some dependent base exprs
Today, inside a template, you can get completion for:

Foo<T> t;
t.^

t has dependent type Foo<T>, and we use the primary template to find its members.
However we also want this to work:

t.foo.bar().^

The type of t.foo.bar() is DependentTy, so we attempt to resolve using similar
heuristics (e.g. primary template).

Differential Revision: https://reviews.llvm.org/D96376
2021-02-11 11:03:40 +01:00
Sam McCall bda5e57742 [clangd] Remove redundant -fno-delayed-template-parsing in tests. NFCI
We now (since a while) turn this off centrally in ParsedAST and CodeComplete.
2021-02-10 22:20:23 +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
Kirill Bobyrev b60428c7ea [clangd] Fix false positive in local rename collision detetction
Fixes https://github.com/clangd/clangd/issues/685

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D96247
2021-02-09 11:51:18 +01:00
Sam McCall fed995ef90 [clangd] Trace queue state for each TUScheduler action.
The new trace event includes what's already in the queue when adding.
For tracers that follow contexts, the trace event will span the time that the action
spends in the queue.
For tracers that follow threads, the trace will be a tiny span on the enqueuing thread.

Differential Revision: https://reviews.llvm.org/D96027
2021-02-05 17:56:51 +01:00
Kadir Cetinkaya d1978fa4bf
[clangd] Deduplicate scopes in IncludeFixer queries
Differential Revision: https://reviews.llvm.org/D95942
2021-02-05 14:02:50 +01:00
Aleksandr Platonov 91698fe45f [clangd] Take into account what is in the index (symbols, references, etc.) at indexes merge
Current indexes merge logic skip data from the static index if the file is in the dynamic index, but sometimes the dynamic index does not contain references (e.g. preamble (dynamic) index vs background (static) index).
This problem is masked with the fact, that the preamble index file list consists of file URI's and other indexes file lists consist of file paths.
This patch introduces the index contents (symbols, references, etc.), which makes indexes merge more flexible and makes it able to use URI's for the index file list.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D94952
2021-02-05 13:35:07 +03:00
Kirill Bobyrev e8a2b7c915 [clangd] Improve name conflict detection
Follow-up on D95925: adds better detection for function arguments and also
checks for conflicts in muli-variable init statements in ForStmt.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D96009
2021-02-04 21:37:41 +01:00
Kirill Bobyrev 5eec9a380a
[clangd] Detect rename conflicits within enclosing scope
This patch allows detecting conflicts with variables defined in the current
CompoundStmt or If/While/For variable init statements.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D95925
2021-02-04 09:45:42 +01:00
Utkarsh Saxena 54afcade3b
[clangd] Report xref for base methods.
See: https://github.com/clangd/clangd/issues/668

```
struct A { virtual void foo() = 0; };
struct B : A { void foo() override; };
```

Find refs on `B::foo()` will show:
- decls of `A::foo()` (new)
- decls of `B::foo()`
- refs to `A::foo()` (new)
- refs to `B::foo()`.

Differential Revision: https://reviews.llvm.org/D95852
2021-02-03 12:07:43 +01:00
Sam McCall 6ac3fd9706 [clangd] Fix race in Global CDB shutdown
I believe the atomic write can be reordered after the notify, and that
seems to be happening on mac m1: http://45.33.8.238/macm1/2654/step_8.txt
In practice maybe seq_cst is enough? But no reason not to lock here.

https://bugs.llvm.org/show_bug.cgi?id=48998
2021-02-02 15:24:14 +01:00
Utkarsh Saxena fbeff2ec2b
[clangd] Report only decl of overridding method in xref.
See: https://github.com/clangd/clangd/issues/668

```
struct A { virtual void foo() = 0; };
struct B : A { void foo() override; };
```

Find refs on `A::foo()` will show:
- decls of `A::foo()`
- decls of `B::foo()`
- refs to `A::foo()`
- no refs to `B::foo()`.

Differential Revision: https://reviews.llvm.org/D95812
2021-02-02 13:06:20 +01:00
Conrad Poelman 0b70c86e20
clang-extra: fix incorrect use of std::lock_guard by adding variable name (identified by MSVC [[nodiscard]] error)
`std::lock_guard` is an RAII class that needs a variable name whose scope determines the guard's lifetime. This particular usage lacked a variable name, meaning the guard could be destroyed before the line that it was indented to protect.

This line was identified by building clang with the latest MSVC preview release, which declares the std::lock_guard constructor to be `[[nodiscard]]` to draw attention to such issues.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D95725
2021-02-02 06:02:59 +01:00
Sam McCall 1eb7fd089e [clangd] Remove some obsolete options that are now always on
- always collect main-file refs when indexing
 - always build preambles asynchronously
 - always use dex for fast preamble index

Retire associated flags

Differential Revision: https://reviews.llvm.org/D95571
2021-02-01 17:24:03 +01:00
Sam McCall 8712df7a62 [clangd] references: decls of overrides of x are refs to x, not decls
This requires a second index query for refs to overrides, as the refs
call doesn't tell you which ref points at which symbol.

Differential Revision: https://reviews.llvm.org/D95451
2021-02-01 17:19:19 +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
Sam McCall b63cd4db91 [clangd] Rename: merge index/AST refs path-insensitively where needed
If you have c:\foo open, and C:\foo indexed (case difference) then these
need to be considered the same file. Otherwise we emit edits to both,
and editors do... something that isn't pretty.

Maybe more centralized normalization is called for, but it's not trivial
to do this while also being case-preserving. see
https://github.com/clangd/clangd/issues/108

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

Differential Revision: https://reviews.llvm.org/D95759
2021-02-01 15:15:21 +01:00
xgupta 94fac81fcc [Branch-Rename] Fix some links
According to the [[ https://foundation.llvm.org/docs/branch-rename/ | status of branch rename ]], the master branch of the LLVM repository is removed on 28 Jan 2021.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D95766
2021-02-01 16:43:21 +05:30
Sam McCall 7de711ecca Reland [clangd] Quote/escape argv included in log messages.
... but don't apply it where we're using hasSubstr

This reverts commit 7a8008d0e8.
2021-01-31 16:39:47 +01:00
Sam McCall 7a8008d0e8 Revert "[clangd] Quote/escape argv included in log messages."
This reverts commit 0962f1d72b.
http://45.33.8.238/win/32346/step_9.txt
2021-01-31 16:22:00 +01:00
Sam McCall 60053a9ce2 [clangd] Remove references to old future-based API. NFC 2021-01-31 12:13:20 +01:00
Sam McCall 0962f1d72b [clangd] Quote/escape argv included in log messages.
https://github.com/clangd/clangd/issues/637
2021-01-31 12:00:08 +01:00
Sam McCall 7d1b499cae Revert "[clangd] Extract symbol-scope logic out of Quality, add tests. NFC"
On second thought, this can't properly be reused for highlighting.

Consider this example, which Quality wants to consider function-scope,
but highlighting must consider class-scope:

void foo() {
  class X {
    int ^y;
  };
}
2021-01-29 14:59:16 +01:00
Sam McCall d0817b5f18 [clangd] Extract symbol-scope logic out of Quality, add tests. NFC
This prepares for reuse from the semantic highlighting code.

There's a bit of yak-shaving here:
 - when the enum is moved into the clangd namespace, promote it to a
   scoped enum. This means teaching the decision forest infrastructure
   to deal with scoped enums.
 - AccessibleScope isn't quite the right name: e.g. public class members
   are treated as accessible, but still have class scope. So rename to
   SymbolScope.
 - Rename some QualitySignals members to avoid name conflicts.
   (the string) SymbolScope -> Scope
   (the enum) Scope -> ScopeKind
2021-01-29 14:44:28 +01:00
Haojian Wu f25a57e248 [clangd] Add include-fixer fixit for field_incomplete_or_sizeless diagnostic.
Differential Revision: https://reviews.llvm.org/D95439
2021-01-29 08:22:23 +01:00
Sam McCall c3df9d58c7 [clangd] Parse Diagnostics block, and nest ClangTidy block under it.
(ClangTidy configuration block hasn't been in any release, so we should be OK
to move it around like this)

Differential Revision: https://reviews.llvm.org/D95362
2021-01-28 01:36:23 +01:00
Sam McCall 29472bb769 [clangd] Log warning when using legacy (theia) semantic highlighting.
The legacy protocol will be removed on trunk after the 12 branch cut,
and gone in clangd 13.

Differential Revision: https://reviews.llvm.org/D95031
2021-01-28 01:29:28 +01:00
Kadir Cetinkaya af20232b8e
[clangd] Treat "null" optional fields as missing
Clangd currently throws away any protocol messages whenever an optional
field has an unexpected type. This patch changes the behaviour to treat
`null` fields as missing.

This enables clangd to be more tolerant against small violations to the
LSP spec.

Fixes https://github.com/clangd/vscode-clangd/issues/134

Differential Revision: https://reviews.llvm.org/D95229
2021-01-27 15:51:33 +01:00
Sam McCall 12de8e1399 [clangd] Work around GCC bug 66735 2021-01-27 15:32:05 +01:00
Nathan James 7730599c41
[clangd] FindTarget resolves base specifier
FindTarget on the virtual keyword or access specifier of a base specifier will now resolve to type of the base specifier.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D95338
2021-01-26 18:59:29 +00:00
Nathan James d92413a45e
[clangd] Selection handles CXXBaseSpecifier
Selection now includes the virtual and access modifier as part of their range for cxx base specifiers.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D95231
2021-01-26 18:58:53 +00:00
Kadir Cetinkaya 9190f17a7c
[clangd] Add std::size_t to StdSymbol mapping
This is a common symbol that's missing from our mapping because
cppreference yields multiple headers.

Add it manually by picking cstddef to prevent insertion of some stdlib-internal
headers instead.

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

Differential Revision: https://reviews.llvm.org/D95423
2021-01-26 17:53:07 +01:00
Simon Pilgrim 110837fbf6 Fix signed/unsigned comparison warning. NFCI. 2021-01-26 15:04:49 +00:00
Haojian Wu 68dbd1aefe [clangd] Add include-fixer fixit for no_member_template diagnostic.
Differential Revision: https://reviews.llvm.org/D95365
2021-01-26 10:11:06 +01:00
Kadir Cetinkaya 64cdba65bb
[clangd] Fix filename completion at the end of file
Fixes https://github.com/clangd/clangd/issues/433

Differential Revision: https://reviews.llvm.org/D95419
2021-01-26 09:45:21 +01:00
Duncan P. N. Exon Smith f4d02fbe41 Frontend: Take VFS and MainFileBuffer by reference in PrecompiledPreamble::CanReuse, NFC
Clarify that `PrecompiledPreamble::CanReuse` requires non-null arguments
for `VFS` and `MainFileBuffer`, taking them by reference instead of by
pointer.

Differential Revision: https://reviews.llvm.org/D91297
2021-01-25 17:50:56 -08:00
Sam McCall 118c33ef47 [clangd] Allow configuration database to be specified in config.
This allows for more flexibility than -compile-commands-dir or ancestor
discovery.

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

Differential Revision: https://reviews.llvm.org/D95057
2021-01-25 23:15:48 +01:00
Quentin Chateau 3680cb99a7 [clangd] ignore parallelism level for quick tasks
This allows quick tasks without dependencies that
need to run fast to run ASAP. This is mostly useful
for code formatting.

----------------------------

This fixes something that's been annoying me:
- Open your IDE workspace and its 20 open files
- Clangd spends 5 minutes parsing it all
- In the meantime you start to work
- Save a file, trigger format-on-save, which hangs because clangd is busy
- You're stuck waiting until clangd is done parsing your files before the formatting and save takes place

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D94875
2021-01-25 23:03:43 +01:00
Nathan James 71af5a19cb Reland"[clangd][NFC] Simplify handing on methods with no params"
This reverts commit 9d9ceb3745.

First time round caused some build bot failures due to older compilers not patched with the Defect Report about full specialization being allowed at class scope.
2021-01-25 20:19:57 +00:00
Keith Smiley 9d9ceb3745 Revert "[clangd][NFC] Simplify handing on methods with no params"
This broke the build http://lab.llvm.org:8011/#/builders/7/builds/1405

This reverts commit f05b492aae.

Differential Revision: https://reviews.llvm.org/D95385
2021-01-25 11:56:18 -08:00
Nathan James f05b492aae [clangd][NFC] Simplify handing on methods with no params
Add bind methods handling the case when a method has an empty params interface and when it has no parameters.

Remove ShutdownParams and ExitParams from Protocol, In LSP they aren't defined, instead the methods are defined to have void as the params. This signature now better reflects that.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D95270
2021-01-25 19:08:10 +00:00
Sam McCall 7e506b30a1 [clangd] Allow diagnostics to be suppressed with configuration
This has been specifically requested:
  https://github.com/clangd/vscode-clangd/issues/114
and various issues can be addressed with this as a workaround, e.g.:
  https://github.com/clangd/clangd/issues/662

Differential Revision: https://reviews.llvm.org/D95349
2021-01-25 15:59:07 +01:00
Adam Czachorowski 00054382b9 [clangd] Fix a crash when indexing invalid ObjC method declaration
This fix will make us not crash, but ideally we would handle this case
better.

Differential Revision: https://reviews.llvm.org/D94919
2021-01-25 15:43:11 +01:00
Sam McCall 60cd75a098 [clangd] Inject context provider rather than config into ClangdServer. NFC
This is a step towards allowing CDB behavior to being configurable.

Previously ClangdServer itself created the configs and installed them into
contexts. This was natural as it knows how to deal with resulting diagnostics.

However this prevents config being used in CDB, which must be created before
ClangdServer. So we extract the context provider (config loader) as a separate
object, which publishes diagnostics to a ClangdServer::Callbacks itself.

Now initialization looks like:
 - First create the config::Provider
 - Then create the ClangdLSPServer, passing config provider
 - Next, create the context provider, passing config provider + diagnostic callbacks
 - now create the CDB, passing context provider
 - finally create ClangdServer, passing CDB, context provider, and diagnostic callbacks

Differential Revision: https://reviews.llvm.org/D95087
2021-01-22 14:34:30 +01:00
Aleksandr Platonov 7388c34685 [clangd][SwapIndex] ensure that the old index is alive while we are using it via the function returned by `SwapIndex::indexedFiles()` call
Without this patch the old index could be freed, but there still could be tries to access it via the function returned by `SwapIndex::indexedFiles()` call.
This leads to hard to reproduce clangd crashes at code completion.
This patch keeps the old index alive until the function returned by `SwapIndex::indexedFiles()` call is alive.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D95206
2021-01-22 16:26:39 +03:00
Kadir Cetinkaya 4cca222279
[clangd] Add documentation for building and testing clangd
Adds minimal cmake configuration required to build and test clangd,
while telling target names. Should be helpful for people unfamiliar with the
LLVM repo.

See https://github.com/clangd/clangd/issues/579 for a request.

Differential Revision: https://reviews.llvm.org/D91186
2021-01-22 11:53:31 +01:00
Haojian Wu facea4a2d4 [clangd] Fix a missing override keyword, NFC. 2021-01-21 11:06:43 +01:00
Hans Wennborg 8ba442bc21 Revert "Following up on PR48517, fix handling of template arguments that refer"
Combined with 'da98651 - Revert "DR2064:
decltype(E) is only a dependent', this change (5a391d3) caused verifier
errors when building Chromium. See https://crbug.com/1168494#c1 for a
reproducer.

Additionally it reverts changes that were dependent on this one, see
below.

> Following up on PR48517, fix handling of template arguments that refer
> to dependent declarations.
>
> Treat an id-expression that names a local variable in a templated
> function as being instantiation-dependent.
>
> This addresses a language defect whereby a reference to a dependent
> declaration can be formed without any construct being value-dependent.
> Fixing that through value-dependence turns out to be problematic, so
> instead this patch takes the approach (proposed on the core reflector)
> of allowing the use of pointers or references to (but not values of)
> dependent declarations inside value-dependent expressions, and instead
> treating template arguments as dependent if they evaluate to a constant
> involving such dependent declarations.
>
> This ends up affecting a bunch of OpenMP tests, due to OpenMP
> imprecisely handling instantiation-dependent constructs, bailing out
> early instead of processing dependent constructs to the extent possible
> when handling the template.
>
> Previously committed as 8c1f2d15b8, and
> reverted because a dependency commit was reverted.

This reverts commit 5a391d38ac.

It also restores clang/test/SemaCXX/coroutines.cpp to its state before
da986511fb.

Revert "[c++20] P1907R1: Support for generalized non-type template arguments of scalar type."

> Previously committed as 9e08e51a20, and
> reverted because a dependency commit was reverted. This incorporates the
> following follow-on commits that were also reverted:
>
> 7e84aa1b81 by Simon Pilgrim
> ed13d8c667 by me
> 95c7b6cadb by Sam McCall
> 430d5d8429 by Dave Zarzycki

This reverts commit 4b574008ae.

Revert "[msabi] Mangle a template argument referring to array-to-pointer decay"

> [msabi] Mangle a template argument referring to array-to-pointer decay
> applied to an array the same as the array itself.
>
> This follows MS ABI, and corrects a regression from the implementation
> of generalized non-type template parameters, where we "forgot" how to
> mangle this case.

This reverts commit 18e093faf7.
2021-01-20 15:55:35 +01:00
Haojian Wu 42830f8bdc [clangd] Extend find-refs to include overrides.
find-references on `virtual void meth^od() = 0` will include override references.

Differential Revision: https://reviews.llvm.org/D94390
2021-01-20 13:23:20 +01:00
Kadir Cetinkaya a1d4649a5b
[clangd] Fix division by zero when computing scores
NameMatch could be a float close to zero, in such cases we were
dividing by zero and moreover propogating a "NaN" to clients, which is invalid
per JSON.

This fixes the issue by only using Quality scores whenever the NameMatch is low,
as we do in CodeCompletion ranking.

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

Differential Revision: https://reviews.llvm.org/D94755
2021-01-20 12:50:25 +01:00
Sam McCall 2ab5fd2c85 [clangd] Retire some flags for uncontroversial, stable features.
And mark a couple to be retired afther the next release branch.

Differential Revision: https://reviews.llvm.org/D94727
2021-01-20 11:47:12 +01:00
Sam McCall e6be5c7cd6 [clangd] Remove the recovery-ast options.
These force a couple of flags or that are now on by default.
So the flags don't currently do anything unless the compile command has
-fno-recovery-ast explicitly.

(For turning recovery *off* for debugging we can inject the flag with config)

This leaves the command-line flags around with no effect, I'm planning to add
a "retired flag" mechanism shortly in a separate patch.

Differential Revision: https://reviews.llvm.org/D94724
2021-01-20 11:23:57 +01:00
Sam McCall de4ba7073b [clangd] Move DirBasedCDB broadcasting onto its own thread.
This is on the critical path (it blocks getting the compile command for
the first file).

It's not trivially fast: it involves processing all filenames in the CDB
and doing some IO to look for shadowing CDBs.

And we may make this slower soon - making CDB configurable implies evaluating
the config for each listed to see which ones really are owned by the
broadcasted CDB.

Differential Revision: https://reviews.llvm.org/D94606
2021-01-20 11:22:55 +01:00
Sam McCall 536a1b0ea2 [clangd] Allow CDBs to have background work to block on.
In preparation for moving DirectoryBasedCompilationDatabase broadcasting off
the main thread.

Differential Revision: https://reviews.llvm.org/D94603
2021-01-20 11:11:01 +01:00
Utkarsh Saxena 17846ed5af [clangd] Use ASTSignals in Heuristics CC Ranking.
Differential Revision: https://reviews.llvm.org/D94927
2021-01-19 19:48:42 +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
Richard Smith 4b574008ae [c++20] P1907R1: Support for generalized non-type template arguments of scalar type.
Previously committed as 9e08e51a20, and
reverted because a dependency commit was reverted. This incorporates the
following follow-on commits that were also reverted:

7e84aa1b81 by Simon Pilgrim
ed13d8c667 by me
95c7b6cadb by Sam McCall
430d5d8429 by Dave Zarzycki
2021-01-18 21:05:01 -08:00
Utkarsh Saxena 275716d6db [clangd] Derive new signals in CC from ASTSignals.
This patch only introduces new signals but does not use their value
in scoring a CC candidate. Usage of these signals in CC ranking in both
heiristics and ML model will be introduced in later patches.

Differential Revision: https://reviews.llvm.org/D94473
2021-01-18 17:37:27 +01:00
Utkarsh Saxena 9abbc05097
[clangd] Use !empty() instead of size()>0 2021-01-17 15:26:40 +01:00
Utkarsh Saxena 0f9908a7c9
[clangd] Use empty() instead of size()>0 2021-01-17 15:13:01 +01:00
Utkarsh Saxena d5047d762f [clangd] Update CC Ranking model with better sampling.
A better sampling strategy was used to generate the dataset for this
model.
New signals introduced in this model:
- NumNameInContext: Number of words in the context that matches the name
of the candidate.
- FractionNameInContext: Fraction of the words in context matching the
name of the candidate.

We remove the signal `IsForbidden` from the model and down rank
forbidden signals aggresively.

Differential Revision: https://reviews.llvm.org/D94697
2021-01-15 18:13:24 +01:00
Adam Czachorowski c77c3d1d18 [clangd] Set correct CWD when using compile_flags.txt
This fixes a bug where clangd would attempt to set CWD to the
compile_flags.txt file itself.

Differential Revision: https://reviews.llvm.org/D94699
2021-01-15 14:26:24 +01:00
Adam Czachorowski aeaeb9e6bd [clangd] Make ExpandAutoType not available on template params.
We cannot expand auto when used inside a template param (C++17 feature),
so do not offer it there.

Differential Revision: https://reviews.llvm.org/D94719
2021-01-15 14:19:05 +01:00
Ilya Golovenko 9cc221b99b [clangd] exclude symbols from document outline which do not originate from the main file
Differential Revision: https://reviews.llvm.org/D94753
2021-01-15 13:23:12 +03:00
Sam McCall 4183999e0f [clangd] Reduce logspam for CDB scanning 2021-01-14 23:55:02 +01:00
Utkarsh Saxena 8b09cf7956
[clangd] Trivial: Documentation fix in ASTSignals. 2021-01-14 18:38:42 +01:00
Utkarsh Saxena 2f395b7092 [clangd] Make AST-based signals available to runWithPreamble.
Many useful signals can be derived from a valid AST which is regularly updated by
the ASTWorker. `runWithPreamble` does not have access to the ParsedAST
but it can be provided access to some signals derived from a (possibly
stale) AST.

Differential Revision: https://reviews.llvm.org/D94424
2021-01-14 18:34:50 +01:00
Sam McCall 17fb21f875 [clangd] Remove another option that was effectively always true. NFC 2021-01-14 17:19:47 +01:00
Aleksandr Platonov 2e25be0b61 [clangd] Add main file macros into the main-file index.
This patch is a try to fix `WorkspaceSymbols.Macros` test after D93796.
If a macro definition is in the preamble section, then it appears to be in the preamble (static) index and not in the main-file (dynamic) index.
Thus, a such macro could not be found at a symbol search according to the logic that we skip symbols from the static index if the location of these symbols is inside the dynamic index files.
To fix this behavior this patch adds main file macros into the main-file (dynamic) index.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D94477
2021-01-14 15:10:17 +03:00
Kazu Hirata fb98a1be43 Fix the warnings on unused variables (NFC) 2021-01-13 13:32:40 -08:00
Sam McCall 0bbc6a6bb6 [clangd] Remove some old CodeCompletion options that are never (un)set. NFC 2021-01-13 18:01:48 +01:00
Utkarsh Saxena a4f3866882 [clangd] Remove "decision-forest-base" experimental flag.
The value of this flag can only be fine tuned by using A/B testing on large
user base.
We do not expect individual users to use and fine tune this flag.

Differential Revision: https://reviews.llvm.org/D94513
2021-01-13 17:54:38 +01:00
Sam McCall 466acd6948 [clangd] Avoid reallocating buffers for each message read:
- reuse std::string we read messages into
 - when reading line-wise, use SmallVector<128> and read in chunks of 128
   (this affects headers, which are short, and tests, which don't matter)

Differential Revision: https://reviews.llvm.org/D93653
2021-01-13 17:40:33 +01:00
Sam McCall 66d5994bd3 [clangd] Explicitly avoid background-indexing the same file twice.
This used to implicitly never happen due to only discovering each CDB
once.

We may want to carefully support reindexing one day, but we need to do
it carefully (tricky tradeoffs) and it would need further support in
background indexer.

Making this explicit here rather than just turning off rebroadcast in
background index for a few reasons:
- allows *new* files in the same CDB to be indexed
- relying on bugs-at-a-distance cancelling each other out is bound to bite us
- gets us closer to actually supporting reindexing, which requires similar tracking

Differential Revision: https://reviews.llvm.org/D94503
2021-01-13 17:29:30 +01:00
Sam McCall 90164ba957 [clangd] Split out a base class for delegating GlobalCompilationDatabases. NFC
This prepares for adding another delegatable method (blockUntilIdle) to GCDB.
2021-01-13 16:20:33 +01:00
Nathan Ridge 4718ec0166 [clangd] Avoid recursion in TargetFinder::add()
Fixes https://github.com/clangd/clangd/issues/633

Differential Revision: https://reviews.llvm.org/D94382
2021-01-12 13:57:54 -05:00
Nathan James 31732e6f52
[clangd] Remove ScratchFS from tests
This can lead to issues if files in the tmp directory we don't care about / control are found.
This was partially addressed in D94321, but this is a more permanent fix.
Fixes https://github.com/clangd/clangd/issues/354

Reviewed By: adamcz, sammccall

Differential Revision: https://reviews.llvm.org/D94359
2021-01-11 16:14:26 +00:00
Haojian Wu a2dbf3443a [clangd] Fix -check mode doesn't respect any tidy configs.
Differential Revision: https://reviews.llvm.org/D94411
2021-01-11 16:43:33 +01:00
Haojian Wu 1677c86124 [clangd] Add metrics for go-to-implementation.
Differential Revision: https://reviews.llvm.org/D94393
2021-01-11 10:26:50 +01:00
Nathan James 467cbd2981
[clangd][NFC] Remove unnecessary copy in CodeComplete
All tests still pass with ASAN so fairly confident no use-after-free going on here.
2021-01-09 02:32:23 +00:00
Haojian Wu 8e36d21fab [clangd] Add go-to-def metric.
to track the number of different "special" go-to-def request.

Differential Revision: https://reviews.llvm.org/D94289
2021-01-08 21:03:59 +01:00
Adam Czachorowski 2e1bb7940a [clangd] Add missing "override" to fix the build.
Follow-up to d4af86581e

Differential Revision: https://reviews.llvm.org/D94314
2021-01-08 17:24:47 +01:00
Adam Czachorowski d4af86581e [clangd] Fix type printing in the presence of qualifiers
When printing QualType with qualifiers like "const", or pointing to an
elaborated type, we would print garbage like:
  std::const std::vector<int>&
with the initial std:: being calculated correctly, but inserted in the
wrong place and the second std:: not removed (due to elaborated type).

This affected, among others, ExtractFunction and ExpandAuto tweaks.

This change introduces a new callback to PrintingPolicy, which allows us
to influence the printing of namespace qualifiers. In the future, the
same callback can be used to improve handling of "using namespace"
directives as well.

Fixes:
  https://github.com/clangd/clangd/issues/640 (ExtractFunction)
  https://github.com/clangd/clangd/issues/264 (ExpandAuto)
  First point of https://github.com/clangd/clangd/issues/524

Differential Revision: https://reviews.llvm.org/D94259
2021-01-08 17:00:39 +01:00
Haojian Wu ed3b1f9061 [clangd] go-to-implementation on a base class jumps to all subclasses.
Differential Revision: https://reviews.llvm.org/D92749
2021-01-08 13:50:57 +01:00
Haojian Wu c909512fdb [clangd] Cleanup a remaining Optional<SymbolID> usage, NFC. 2021-01-08 13:44:20 +01:00
Haojian Wu b83b7d0873 [clangd] NFC, avoid potential ODR violation. 2021-01-08 13:29:11 +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
Nathan James 3505d8dc07 [clangd][NFC] Use PathRef for getCorrespondingHeaderOrSource 2021-01-07 02:41:19 +00:00
Nathan James 0bfe100145
[NFC] Test case refactor 2021-01-06 20:00:15 +00:00
Aleksandr Platonov 979228f120 [clangd][fuzzyFind] Do not show stale symbols in the result.
This is follow up to D93393.
Without this patch `MergedIndex::fuzzyFind()` returns stale symbols from the static index even if these symbols were removed.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D93796
2021-01-06 11:17:12 +03: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 7af6a13450
[NFC] Switch up some dyn_cast calls 2021-01-02 19:56:27 +00:00
Adam Czachorowski 0999408aea [clangd] Add error handling (elog) in code completion.
Differential Revision: https://reviews.llvm.org/D93220
2020-12-28 15:22:54 +01:00
Sam McCall 74b3acefc7 [clangd] Fix case mismatch crash on in CDB on windows after 92dd077af1
See https://github.com/clangd/clangd/issues/631
2020-12-23 22:42:45 +01:00
Aleksandr Platonov 2522fa053b [clangd] Do not take stale definition from the static index.
This is follow up to D93393.
Without this patch clangd takes the symbol definition from the static index if this definition was removed from the dynamic index.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D93683
2020-12-23 18:21:38 +03:00
Sam McCall 3dbe471a26 [clangd] Use atomics instead of locks to track periodic memory trimming
Instead of always locking/unlocking a contended mutex, we now do one atomic read
in the common case, and one read + one exchange if the timer has expried.

Also use this for memory profiling which has similar/compatible requirements.

Differential Revision: https://reviews.llvm.org/D93726
2020-12-22 22:32:22 +01:00
Arthur Eubanks b2e734d5f4 Revert "[clangd] zap a few warnings"
This reverts commit 95c7b6cadb.

Depends on a reverted change.
2020-12-22 10:34:03 -08:00
Nathan James 4b3633cf2c
[clangd] Reuse buffer for JSONTransport::sendMessage
Allocate a Buffer in the JSONTransport to be used when sending messages to the client.
This gets reused each time a message is sent, reducing in fewer malloc, which is always a bonus.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D93531
2020-12-22 11:30:56 +00:00
Quentin Chateau b8c37153d5 [clangd] Trim memory periodically when using glibc malloc
This diff addresses the issue of the ever increasing memory usage of clangd. The key to understand what happens is to use `malloc_stats()`: malloc arenas keep getting bigger, although the actual memory used does not. It seems some operations while bulding the indices (both dynamic and background) create this problem. Specifically, 'FileSymbols::update' and 'FileSymbols::buildIndex' seem especially affected.

This diff adds a call to `malloc_trim()` periodically in
ClangdLSPServer.

Fixes: https://github.com/clangd/clangd/issues/251
Fixes: https://github.com/clangd/clangd/issues/115

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D93452
2020-12-22 08:54:28 +01:00
Quentin Chateau 3fa2d37eb3 [clangd][NFC] Improve clangd status messages
clangd actions have various naming schemes, the most
common being PascalCase. This commit applies PascalCase
to all clangd actions, and fix the status rendering
in `renderTUAction` to look more consistent.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D93546
2020-12-21 20:19:25 +01:00
Sam McCall 2b62e62328 [clangd] Fix windows path handling in .clang-tidy parsing 2020-12-19 02:24:25 +01:00
Sam McCall 2fced5a07b [clangd] Don't cancel requests based on "updates" with same content
There's an unfortunate collision between two features:
 - we implicitly cancel certain requests when the file changes, to avoid
   the queue getting clogged building old revisions to service stale requests
 - we "reparse-if-needed" by synthesizing a file change, e.g. on didSave

We could explicitly mark these synthetic requests to avoid this, but
looking for changes in file content clutters our APIs less and is
arguably the correct thing to do in any case.

Fixes https://github.com/clangd/clangd/issues/620
2020-12-19 02:03:40 +01:00
Sam McCall b0615642f6 [clangd] Make our printing policies for Hover more consistent, especially tags
Different cases were using a bunch of different variants of the printing policy.
Each of these had something going for it, but the result was inconsistent.

Goals:
  - single printing policy used (almost) everywhere
  - avoid unidiomatic tags like `class vector<class X>`
  - be informative and easy to understand

For tags, the solution I wound up with is: we print only the outer tag and only
in the simplest cases where this elaboration won't cause confusion.

For example:
 - class X
 - enum Foo
 - vector<int>
 - X*

This seems to strike a nice balance of providing plenty of info/context in common
cases while never being confusing.

Differential Revision: https://reviews.llvm.org/D93553
2020-12-19 00:52:55 +01:00
Sam McCall 95c7b6cadb [clangd] zap a few warnings 2020-12-18 16:34:34 +01:00
Quentin Chateau c46c7c9bcf [clangd] Smarter hover on auto and decltype
Only show the keyword as the hover "Name".

Show whether the type is deduced or undeduced as
the hover "Documentation".

Show the deduced type (if any) as the "Definition".

Don't show any hover information for:
- the "auto" word of "decltype(auto)"
- "auto" in lambda parameters
- "auto" in template arguments

---------------

This diff is a suggestion based on what @sammccall  suggested in https://reviews.llvm.org/D92977 about hover on "auto". It somehow "hacks" onto the "Documentation" and "Definition" fields of `HoverInfo`. It sure looks good on VSCode, let me know if this seem acceptable to you.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D93227
2020-12-18 16:27:09 +01:00