Commit Graph

6928 Commits

Author SHA1 Message Date
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
Stephen Kelly f2f920b987 [clang-tidy] Simplify inaccurate erase check
The normalization of matchers means that this now works in all language
modes.

Differential Revision: https://reviews.llvm.org/D96139
2021-02-13 13:51:27 +00:00
Stephen Kelly 1709bb8c73 [clang-tidy] Simplify static assert check
Differential Revision: https://reviews.llvm.org/D96223
2021-02-13 13:49:01 +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
Yitzhak Mandelbaum 33f35a4b79 [clang-tidy] Fix `TransformerClangTidyCheck`'s handling of include insertions.
Currently, all include insertions are directed to the main file. However,
Transformer rules can specify alternative destinations for include
insertions. This patch fixes the code to associate the include with the correct
file.

This patch was tested manually. The clang tidy unit test framework does not
support testing changes to header files. Given that this is a bug fix for a live
bug, the patch relies on manual testing rather than blocking on upgrading the
unit test framework.

Differential Revision: https://reviews.llvm.org/D96542
2021-02-12 16:23:53 +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
Alex Hoppen 7e3b9aba60 [Timer] On macOS count number of executed instructions
In addition to wall time etc. this should allow us to get less noisy
values for time measurements.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D96049
2021-02-11 17:26:37 +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
poelmanc 98146c1f5d
[clang-tidy] fix modernize-use-nullptr false positive with spaceship operator comparisons
`clang-tidy -std=c++20` with `modernize-use-nullptr` mistakenly inserts `nullptr` in place of the comparison operator if the comparison internally expands in the AST to a rewritten spaceship operator. This can be reproduced by running the new `modernize-use-nullptr-cxx20.cpp` test without applying the supplied patch to `UseNullptrCheck.cpp`; the current clang-tidy will mistakenly replace:
```result = (a1 < a2);```
with
```result = (a1 nullptr a2);```

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D95714
2021-02-09 14:02:45 +00: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
poelmanc 5229edd667
[clang-tidy] fix modernize-loop-convert to retain needed array-like operator[]
`modernize-loop-convert` handles //array-like// objects like vectors fairly well, but strips slightly too much information from the iteration expression by converting:
```
  Vector<Vector<int>> X;
  for (int J = 0; J < X[5].size(); ++J)
    copyArg(X[5][J]);
```
to
```
  Vector<Vector<int>> X;
  for (int J : X) // should be for (int J : X[5])
    copyArg(J);
```
The `[5]` is a call to `operator[]` and gets stripped by `LoopConvertCheck::getContainerString`. This patch fixes that and adds several test cases.

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D95771
2021-02-07 16:36:34 +00: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
Stephen Kelly 2cba22c23a [clang-tidy] Simplify implementation of container-size-empty
Use IgnoreUnlessSpelledInSource to make the matcher code smaller and
more visibly-related to the code.

Differential Revision: https://reviews.llvm.org/D91303
2021-02-05 14:03:41 +00: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
Simon Pilgrim edc8f0b407 TypeMismatchCheck.cpp - fix Wdocumentation warning. NFCI. 2021-02-05 10:57:39 +00: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
Stephen Kelly c0199b2a21 [clang-tidy] Use new mapping matchers
Use mapAnyOf() and matchers based on it.

Use of binaryOperation() means that modernize-loop-convert and
readability-container-size-empty can now be used with rewritten binary
operators.

Differential Revision: https://reviews.llvm.org/D94131
2021-02-03 23:21:17 +00: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 08274d7d5d [clang-include-fixer] Pre-reserve vector size. NFC 2021-02-03 08:30:45 +01:00
Nathan James 4454a9cd77 [NFC] Fix typo in comment 2021-02-03 05:18:07 +00:00
Nathan James c97592c5df [clang-tidy] Fix crash in readability-identifier-naming check
`isParamInMainLikeFunction` didn't check if the function had an identifer name before calling getName() which could lead to an assert.
2021-02-03 05:11:56 +00: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
Fangrui Song af6be9a7bb [test] Fix unused FileCheck prefixes in clang-tidy and one llvm/test/Reduce test 2021-02-01 22:51:29 -08: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