Commit Graph

190 Commits

Author SHA1 Message Date
Kadir Cetinkaya f71404c37c
[clangd] Replace usages of dummy with more descriptive words
Dummy is a word with inappropriate associations. This patch updates the
references to it in clangd code base with more precise ones.

The only user-visible change is the default variable name used when extracting a
variable. It will be named as `placeholder` from now on.

Differential Revision: https://reviews.llvm.org/D99065
2021-03-22 12:49:24 +01:00
Sam McCall 7d2fba8ddb [clangd] ObjC fixes for semantic highlighting and xref highlights
- highlight references to protocols in class/protocol/extension decls
- support multi-token selector highlights in semantic + xref highlights
  (method calls and declarations only)
- In `@interface I(C)`, I now references the interface and C the category
- highlight uses of interfaces as types
- added semantic highlightings of protocol names (as "interface") and
  category names (as "namespace").
  These are both standard kinds, maybe "extension" will be standardized...
- highlight `auto` as "class" when it resolves to an ObjC pointer
- don't highlight `self` as a variable even though the AST models it as one

Not fixed: uses of protocols in type names (needs some refactoring of
unrelated code first)

Differential Revision: https://reviews.llvm.org/D97617
2021-03-03 20:16:08 +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
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
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
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 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
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
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
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
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
Quentin Chateau bda7d0af97 [clangd] Improve goToDefinition on auto and dectype
locateSymbolAt (used in goToDeclaration) follows the
deduced type instead of failing to locate the declaration.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D92977
2020-12-15 16:32:22 +01:00
Haojian Wu 63ec9e40d1 [clangd] Go-to-definition on pure virtual method decls jumps to all overrides.
Reviewed By: usaxena95

Differential Revision: https://reviews.llvm.org/D92299
2020-12-14 08:56:24 +01:00
Nathan Ridge 3d2c681f28 [clangd] Avoid type hierarchy crash on incomplete type
Fixes https://github.com/clangd/clangd/issues/597

Differential Revision: https://reviews.llvm.org/D92077
2020-11-25 03:45:00 -05:00
Nathan Ridge 5b6f47595b [clangd] Sort results of incomingCalls request by container name
Differential Revision: https://reviews.llvm.org/D92009
2020-11-24 03:29:02 -05:00
Nathan Ridge 3e6e6a2db6 [clangd] Call hierarchy (XRefs layer, incoming calls)
Support for outgoing calls is left for a future change.

Differential Revision: https://reviews.llvm.org/D91122
2020-11-23 20:43:38 -05:00
Utkarsh Saxena 130da802ff Revert "Revert "[clangd] Implement textDocument/implementation (Xref layer)""
This reverts commit 0016ab6f36.

Fix: Consume error from Expected<T>.
2020-11-18 19:09:16 +01:00
Utkarsh Saxena 0016ab6f36 Revert "[clangd] Implement textDocument/implementation (Xref layer)"
This reverts commit 43243208fa.
2020-11-18 18:05:16 +01:00
Utkarsh Saxena 43243208fa
[clangd] Implement textDocument/implementation (Xref layer)
Xref layer changes for textdocument/implementation (https://microsoft.github.io/language-server-protocol/specification#textDocument_implementation)

This currently shows all functions (implementations) that overrides a virtual function.

Differential Revision: https://reviews.llvm.org/D91702
2020-11-18 17:06:47 +01:00
Kadir Cetinkaya 0df197516b
[clangd] Value initialize SymbolIDs
We were default initializing SymbolIDs before, which would leave
indeterminate values in underlying std::array.

This patch updates the underlying data initalization to be value-init and adds a
way to check for validness of a SymbolID.

Differential Revision: https://reviews.llvm.org/D90397
2020-11-02 11:37:47 +01:00
Sam McCall 0e94836989 [clangd] Go-to-definition from non-renaming alias is unambiguous.
It's not helpful to show the alias itself as an option.
This fixes a regression accepted in f24649b77d.

Differential Revision: https://reviews.llvm.org/D89238
2020-10-28 20:17:35 +01:00
Nathan Ridge 245b61a330 [clangd] Increase the TooMany limit for index-based textual navigation to 5
Differential Revision: https://reviews.llvm.org/D90134
2020-10-27 01:49:09 -04:00
Kirill Bobyrev 1704704e76
[clangd] NFC: Update FIXME comment regarding lack of c/dtor support
Both `SymbolKind` and `indexSymbolKindToSymbolKind` support constructors and
separate them into a different category from regular methods.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D89935
2020-10-26 15:31:59 +01:00
Haojian Wu f24649b77d [clangd] Don't set the Underlying bit on targets of UsingDecls.
With this patch, we don't treat `using ns::X` as a first-class declaration like `using Z = ns::Y`, reference to X that goes through this using-decl is considered a direct reference (without the Underlying bit).

Fix the workaround in https://reviews.llvm.org/D87225 and https://reviews.llvm.org/D74054.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D88472
2020-10-07 10:01:04 +02:00
Aleksandr Platonov d8ba6b4ab3 [clangd] findNearbyIdentifier(): guaranteed to give up after 2^N lines
As @kadircet mentions in D84912#2184144, `findNearbyIdentifier()` traverses the whole file if there is no identifier for the word.
This patch ensures give up after 2^N lines in any case.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D87891
2020-09-29 19:54:55 +03:00
Nathan Ridge cc6d1f8029 [clangd] When finding refs for a renaming alias, do not return refs to underlying decls
Fixes https://github.com/clangd/clangd/issues/515

Differential Revision: https://reviews.llvm.org/D87225
2020-09-28 21:18:31 -04:00
Utkarsh Saxena 9b1666f3ce [clangd] Rename evaluate() to evaluateHeuristics()
Since we have 2 scoring functions (heuristics and decision forest),
renaming the existing evaluate() function to be more descriptive of the
Heuristics being evaluated in it.

Differential Revision: https://reviews.llvm.org/D88431
2020-09-28 20:05:01 +02:00
Sam McCall 98756d865b [clangd] Fix comment. NFC 2020-09-24 10:49:39 +02:00
Nathan Ridge ca842c825a [clangd] Handle templates more consistently in type hierarchy
If the tree includes types derived from all specializations of
a template, do not misleadingly label the root node with the
name of a single specialization.

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

Differential Revision: https://reviews.llvm.org/D86861
2020-09-01 19:18:37 -04:00
Nathan Ridge e33ec9d904 [clangd] Target member of dependent base made visible via a using-decl
Fixes https://github.com/clangd/clangd/issues/307

Differential Revision: https://reviews.llvm.org/D86047
2020-08-18 03:03:49 -04:00
David Goldman cb29c33984 [clangd][ObjC] Improve xrefs for protocols and classes
Summary:
Previously clangd would jump to forward declarations for protocols
and classes instead of their definition/implementation.

Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83501
2020-08-11 12:36:31 -04:00
Haojian Wu a70161808b [clangd] Include the underlying decls in go-to-definition.
Fixes https://github.com/clangd/clangd/issues/277

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D74054
2020-08-07 11:39:49 +02:00
Haojian Wu 5191f70ab1 [clangd] Support new/deleta operator in TargetFinder.
Differential Revision: https://reviews.llvm.org/D85028
2020-08-03 14:10:21 +02:00
Haojian Wu 638f0cf565 [clangd] Be more explicit on testing the optional DefLoc in LocatedSymbol.
And also fix a bug where we may return a meaningless location.

Differential Revision: https://reviews.llvm.org/D84919
2020-07-31 14:34:56 +02:00
Aleksandr Platonov 05b1734661 [clangd] findNearbyIdentifier(): fix the word search in the token stream.
Without this patch the word occurrence search always returns the first token of the file.
Despite of that, `findNeardyIdentifier()` returns the correct result (but inefficently) until there are several matched tokens with the same value `floor(log2(<token line> - <word line>))` (e.g. several matched tokens on the same line).

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D84912
2020-07-30 12:45:58 +03:00
Aleksandr Platonov c911803d5d
[clangd] Remove TokenBuffer usage in TypeHierarchy
Summary:
This patch mostly reverts D74850.
We could not use `AST.getTokens()` here, because it does not have tokens from the preamble.

Reviewers: sammccall, kadircet

Reviewed By: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D84144
2020-07-20 21:00:49 +02:00
Nico Weber 7e2d27bc55 Fix two -Wrange-loop-analysis warnings that Xcode 12 beta incorrectly complains about
Xcode 12 beta apparently has the Wrange-loop-analysis changes from
half a year ago, but it seems to lack https://reviews.llvm.org/D72212
which made the warning usable again.
2020-07-04 20:41:33 -04:00
lh123 84ced55d9b [clangd] Remove redundant `findRefs` calls. NFC.
Summary:
Remove redundant `findRefs` calls.

Reviewers: sammccall, kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82714
2020-06-30 18:10:52 +08:00
Eric Christopher 937c135dd5 As part of using inclusive language within the llvm project,
migrate away from the use of blacklist and whitelist.
2020-06-19 15:41:06 -07:00
Nathan Ridge 7759f70fb0 [clangd] Support typeHierarchy/resolve for children of parents as well
Summary:
The initial implementation of typeHierarchy/resolve only supported
cases where an initial request was made for children, and then
typeHierarchy/resolve was used to get additional levels of children.

However, a client may also want to make an initial request for
parents, and then show other children of those parents, so support
typeHierarchy/resolve for items returned in response to a request
for parents as well.

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D81845
2020-06-15 11:59:23 -04:00
Kadir Cetinkaya 538c2753f3
[clangd] locateMacroAt handles patched macros
Summary: Depends on D79992.

This patch changes locateMacroAt to perform #line directive substitution
for macro identifier locations.

We first check whether a location is inside a file included through
built-in header. If so we check whether line directive maps it back to
the main file, and afterwards use TokenBuffers to find exact location of
the identifier on the line.

Instead of performing the mapping in locateMacroAt, we could also store
a mapping inside the ParsedAST whenever we use a patched preamble. But
that would imply adding more responsibility to ParsedAST and paying for
the mapping even when it is not going to be used.

====

Go-To-Definition:

Later on these locations are used for serving go-to-definition requests,
this enables jumping to definition inside the preamble section in
presence of patched macros.

=====

Go-To-Refs:

Macro references in main file are collected separetely and stored as a
map from macro's symbol id to reference ranges. Those ranges are
computed inside PPCallbacks, hence we don't have access to TokenBuffer.

In presence of preamble patch, any reference to a macro inside the
preamble section will unfortunately have the wrong range. They'll point
into the patch rather than the main file. Hence during findReferences,
we won't get any ranges reported for those.

Fixing those requires:
- Lexing the preamble section to figure out "real range" of a patched
  macro definition
- Postponing range/location calculations until a later step in which we
  have access to tokenbuffers.

This patch trades some accuracy in favor of code complexity. We don't do
any patching for references inside the preamble patch but get any
reference inside the main file for free.

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80198
2020-05-29 12:46:54 +02:00
Sam McCall a56141b8f9 [clangd] Highlight related control flow.
Summary:
This means e.g. highlighting "return" will show other returns/throws
from the same function, highlighting a case will show all the
return/breaks etc.

This is a bit of an abuse of textDocument/highlight, but seems useful.

Reviewers: adamcz

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D78454
2020-05-28 13:25:11 +02:00
Sam McCall b752a2743a [clangd] Log use of heuristic go-to-def. NFC
Generally:
 - found results using this method -> log
 - no results using this method -> vlog
 - method wasn't applied because ineligible -> no log
2020-05-25 10:19:34 +02:00
Kadir Cetinkaya d870016bfc
[clangd] Get rid of Inclusion::R
Summary:
This is only used by documentlink and go-to-definition. We are pushing
range detection logic from Inclusion creation to users. This would make using
stale preambles easier.

For document links we make use of the spelledtokens stored in tokenbuffers to
figure out file name range.

For go-to-def, we keep storing the line number we've seen the include directive.

Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79315
2020-05-05 12:23:58 +02:00
Sam McCall ad97ccf6b2 [clangd] Move non-clang base pieces into separate support/ lib. NFCI
Summary:
This enforces layering, reduces a sprawling clangd/ directory, and makes life
easier for embedders.

Reviewers: kbobyrev

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79014
2020-04-29 15:57:12 +02:00
Nathan Ridge 230cae89db [clangd] Enable textual fallback for go-to-definition on dependent names
Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D76451
2020-04-26 00:38:38 -04:00
Sam McCall 3f1c2bf171 [clangd] go-to-def on names in comments etc that are used nearby.
Summary:
This is intended as a companion to (and is inspired by) D72874 which attempts to
resolve these cases using the index.
The intent is we'd try this strategy after the AST-based approach but before the
index-based (I think local usages would be more reliable than index matches).

Reviewers: nridge

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75479
2020-04-22 19:46:41 +02:00
Reid Kleckner ba1ffd25c1 [OpenMP][NFC] Remove the need to include `OpenMPClause.h`
See rational here: https://reviews.llvm.org/D76173#1922916
Time to compile Attr.h in isolation goes from 2.6s to 1.8s.

Original patch by Johannes, plus some additions from Reid to fix some
clang tooling targets.

Effect on transitive includes is marginal, though:

$ diff -u <(sort thedeps-before.txt) <(sort thedeps-after.txt) \
   | grep '^[-+] ' | sort | uniq -c | sort -nr
    104 -    /usr/local/google/home/rnk/llvm-project/clang/include/clang/AST/OpenMPClause.h
     87 -    /usr/local/google/home/rnk/llvm-project/llvm/include/llvm/Frontend/OpenMP/OMPContext.h
     19 -    /usr/local/google/home/rnk/llvm-project/llvm/include/llvm/ADT/SmallSet.h
     19 -    /usr/local/google/home/rnk/llvm-project/llvm/include/llvm/ADT/SetVector.h
     14 -    /usr/include/c++/9/set
...

Differential Revision: https://reviews.llvm.org/D76184
2020-04-03 13:27:52 -07:00
Haojian Wu b420065969 [clangd] Fix an assertion crash in ReferenceFinder.
Summary: The assertion is almost correct, but it fails on refs from non-preamble

Reviewers: sammccall

Reviewed By: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77222
2020-04-02 09:29:20 +02:00