1723 Commits

Author SHA1 Message Date
Jan Svoboda
5746002ebb [clang] NFCI: Change returned LanguageOptions pointer to reference 2023-09-05 13:23:53 -07:00
Sam McCall
a8c9b9f140 [clangd] Support ConceptReference in generic AST wrangling code
Now we can store it in DynTypedNode, we can target these nodes
(SelectionTree) and resolve them (FindTarget).
This makes Hover, go-to-def etc work in all(?) cases.

Also support it in DumpAST.

Differential Revision: https://reviews.llvm.org/D159299
2023-09-04 14:58:25 +02:00
Kadir Cetinkaya
16b8b3e59f
[clangd][tests] Bump timeouts in TUSchedulerTests to 60 secs
There are some slow/congested bots, that can't go idle in 10 secs, see https://github.com/llvm/llvm-project/issues/64964

Differential Revision: https://reviews.llvm.org/D159338
2023-09-01 12:19:10 +02:00
Kadir Cetinkaya
69feef0e82
[clangd][tests] Assert for idleness of scheduler
We could fail going idle in 5 seconds and get spurious errors
afterwards. See https://github.com/llvm/llvm-project/issues/64964.

Differential Revision: https://reviews.llvm.org/D159337
2023-09-01 12:19:09 +02:00
Aaron Ballman
a02f9a7756 Revert "[clang] Enable sized deallocation by default in C++14 onwards"
This reverts commit 2916b125f686115deab2ba573dcaff3847566ab9.

Reverting due to failures on:
https://lab.llvm.org/buildbot/#/builders/216/builds/26407
https://lab.llvm.org/staging/#/builders/247/builds/5659
http://45.33.8.238/win/83485/step_7.txt
2023-08-29 09:36:59 -04:00
wangpc
2916b125f6 [clang] Enable sized deallocation by default in C++14 onwards
Since C++14 has been released for about nine years and most standard
libraries have implemented sized deallocation functions, it's time to
make this feature default again.

Reviewed By: rnk, aaron.ballman, #libc, ldionne, Mordante, MaskRay

Differential Revision: https://reviews.llvm.org/D112921
2023-08-29 15:42:50 +08:00
Ilya Biryukov
d703dcdfb0 [AST] Fix crash in evaluation of OpaqueExpr in Clangd
The code mistakenly returns the value as evaluated whenever the
temporary is allocated, but not yet evaluated.

I could only reproduce in Clangd and could not come up with an example
that would crash the compiler. Clangd runs more evaluations for hover
than the language would allow.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D158985
2023-08-28 17:10:44 +02:00
Nathan Ridge
f0f53cb4bf [clangd] Do not ignore qualifier in heuristic resolution of dependent MemberExpr
Fixes https://github.com/llvm/llvm-project/issues/64841

Differential Revision: https://reviews.llvm.org/D158873
2023-08-25 16:54:29 -04:00
Nathan Ridge
1994e1173b [clangd] Avoid null result in FindRecordTypeAt()
Fixes https://github.com/clangd/clangd/issues/1743

Differential Revision: https://reviews.llvm.org/D158851
2023-08-25 11:50:19 -04:00
Kadir Cetinkaya
8c21544286
[clangd] Bump timeouts for LSPServerTests
We seem to be hitting limits in some windows build bots, see
https://github.com/clangd/clangd/issues/1712#issuecomment-1686478931.

So bumping the timeouts to 60 seconds and completely dropping them for sync
requests. As mentioned in the comment above, this should improve things,
considering even the tests that don't touch any complicated scheduler is
failing.

Differential Revision: https://reviews.llvm.org/D158426
2023-08-22 16:20:15 +02:00
Sam McCall
23459f13fc [Lex] Preambles should contain the global module fragment.
For applications like clangd, the preamble remains an important optimization
when editing a module definition. The global module fragment is a good fit for
it as it by definition contains only preprocessor directives.
Before this patch, we would terminate the preamble immediately at the "module"
keyword.

Differential Revision: https://reviews.llvm.org/D158439
2023-08-22 11:55:51 +02:00
Yuanjing Hong
dc10bd43a1 [clangd] don't add inlay hint for dependent type in structured binding
Currently clangd will display useless inlay hint for dependent type in
structured binding, e.g.

```
template <class T>
void foobar(T arg) {
  auto [a/*: <dependent type>*/, b/*: <dependent type>*/] = arg;
}
```

Differential Revision: https://reviews.llvm.org/D157956
2023-08-21 11:10:40 +08:00
Nathan Ridge
8ee710a40c [clangd] Parameter hints for calls through function pointers
Fixes https://github.com/clangd/clangd/issues/1734

Differential Revision: https://reviews.llvm.org/D158249
2023-08-18 23:40:59 -04:00
Nathan Ridge
744b111434 [clangd] Bail gracefully if given an assembly or IR source file
The previous behaviour is to try to parse such files, and in some
cases assert or hang in components that don't expect these forms of
input, like TokenBuffer.

Fixes https://github.com/llvm/llvm-project/issues/62090

Differential Revision: https://reviews.llvm.org/D149236
2023-08-18 23:26:32 -04:00
Nathan Ridge
d9cb76bc4d [clang] Support function pointer types with attributes when extracting parameter names for signature help
Fixes https://github.com/clangd/clangd/issues/1729

Differential Revision: https://reviews.llvm.org/D157952
2023-08-18 00:27:15 -04:00
Kadir Cetinkaya
373fcd5d73
[clang] Use RecoveryExprs for broken defaultargs, instead of OpaqueValueExprs
This makes sure we can preserve invalid-ness for consumers of this
node, it prevents crashes. It also aligns better with rest of the places that
store invalid expressions.

Differential Revision: https://reviews.llvm.org/D157868
2023-08-16 10:22:16 +02:00
David Goldman
9fe632ba18 [clang][HeaderSearch] Treat framework headers as Angled for suggestPath
- Rename the IsSystem flag to be IsAngled since that's how callers
  actually use the flag.

- Since frameworks by convention use <> style includes, make sure
  we treat them as Angled

Also update clangd's custom logic for frameworks accordingly.

Differential Revision: https://reviews.llvm.org/D156704
2023-08-09 15:51:02 -04:00
Kadir Cetinkaya
734da23e21
[clangd] Dont assert on specific uris for diagnostics docs
To enable customization of links in downstream projects without
breaking tests (and also ease of pointing at different links in the future).
Just check for existence instead.

Differential Revision: https://reviews.llvm.org/D157071
2023-08-04 11:09:19 +02:00
Kadir Cetinkaya
43974333dd
[include-cleaner] Unify always_keep with rest of the keep logic
Depends on D156122

Differential Revision: https://reviews.llvm.org/D156123
2023-08-02 12:47:53 +02:00
Jens Massberg
8af016aefd [clangd][c++20] Add concept semantic highlighting test case
Differential Revision: https://reviews.llvm.org/D155581
2023-08-02 10:37:30 +02:00
Younan Zhang
b1193c13a5 [clangd] Avoid unexpected desugaring in isSugaredTemplateParameter
This is a follow-up to D151785, addressing https://github.com/clangd/clangd/issues/1703.

The previous approach of peeling pointer types during a traversal
using getPointeeType might have produced unexpected results; since
the method would implicitly desugar the type if the type being passed
in could not be cast to a Pointer-like Type.

Reviewed By: nridge

Differential Revision: https://reviews.llvm.org/D156300
2023-08-01 20:12:35 +08:00
Christian Kandeler
535f34dd80 [index][clangd] Consider labels when indexing function bodies
It's valuable to have document highlights for labels and be able to find
references to them.

Reviewed By: nridge

Differential Revision: https://reviews.llvm.org/D150124
2023-08-01 09:07:05 +02:00
Haojian Wu
dcb28244fa [clangd] Respect IWYU keep pragma for standard headers.
see the issue https://github.com/llvm/llvm-project/issues/64191

Differential Revision: https://reviews.llvm.org/D156650
2023-07-31 13:21:54 +02:00
Sam McCall
d97a3419c0 [clangd] Loose include-cleaner matching for verbatim headers
This updates clangd to take advantage of the APIs added in D155819.
The main difficulties here are around path normalization.

For layering and performance reasons Includes compares paths lexically, and so
we should have consistent paths that can be compared across addSearchPath() and
add(): symlinks resolved or not, relative or absolute.
This patch spells out that requirement, for most tools consistent use of
FileManager/HeaderSearch is enough.

For clangd this does not work: IncludeStructure doesn't hold FileEntrys due to
the preamble/main-file split. It records paths, but canonicalizes them first.
We choose to use this canonical form as our common representation, so we have
to canonicalize the directory entries too. This is done in preamble-build and
recorded in IncludeStructure, as canonicalization is quite expensive.

Differential Revision: https://reviews.llvm.org/D155878
2023-07-27 19:20:53 +02:00
Viktoriia Bakalova
3c6a7b0045 [clangd] Revert the symbol collector behavior to old pre-include-cleaner-library behavior due to a regression.
Differential Revision: https://reviews.llvm.org/D156403
2023-07-27 10:34:35 +00:00
Sam McCall
290a98c7b0 [clangd] Allow indexing of __reserved_names outside system headers
The special handling for these names was added in
055d8090d1
and the motivation was the C++ standard library.

It turns out some projects like using these names anyway, in particular the
linux kernel. D153946 proposed making this a config option, but there are
some implementation issues with the config system.

As an alternative, this patch tweaks the heuristic so we only drop these symbols
in system headers. This does the right thing for linux and the C++ standard
library, at least.

Fixes https://github.com/clangd/clangd/issues/1680
Fixes https://github.com/llvm/llvm-project/issues/63862

Differential Revision: https://reviews.llvm.org/D155381
2023-07-21 23:30:31 +02:00
Sam McCall
d9d9a2cb2f [clangd] Use index for go-to-type
This ensures it finds the definition even if not visible.

Differential Revision: https://reviews.llvm.org/D155898
2023-07-21 23:10:33 +02:00
Sam McCall
ee032bccc9 [clangd] Add BlockEnd comments for control flow statements
These mark the end of CompoundStmts bodies of if/while/for/switch.
To identify which statement is being ended, we include abbreviated
text of the condition/loop variable.

Differential Revision: https://reviews.llvm.org/D155421
2023-07-21 22:57:46 +02:00
Sam McCall
e289ee99ce [clangd] enable unused-include warnings for standard library headers
Other <angle-quoted> headers are still excluded.

Differential Revision: https://reviews.llvm.org/D155385
2023-07-19 23:43:47 +02:00
Viktoriia Bakalova
1f7c7d4bdd [clangd] Update symbol collector to use include-cleaner.
Differential Revision: https://reviews.llvm.org/D152900
2023-07-19 13:47:02 +00:00
Jens Massberg
e9ab43dd44 [clangd][c++20] Add concept Hover tests.
Concepts aren't fully supporteb by hover yet. For the currently
supported case we add a test here to prevent regressions in the future.

Differential Revision: https://reviews.llvm.org/D155558
2023-07-18 10:19:46 +02:00
daiyousei-qz
9e6a342fda [clangd] Implement end-definition-comment inlay hints
This patch implements a new inlay hint feature proposed in https://github.com/clangd/clangd/issues/1634. It introduces a new inlay hint kind BlockEnd which shows a comment-like hint after a definition brace pair, including function/type/namespace. For example,
```
void foo() {
} ^
```
In the code shown above, a hint should be displayed at ^ labelling `// foo`. Such hint only shows when there's no trailing character after the position except whitespaces and optionally ';'.

Also, new configurations are introduced in the inlay hints block
```
InlayHints:
    BlockEnd: Yes # toggling the feature
```

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D150635
2023-07-16 01:19:02 +02:00
Viktoriia Bakalova
96e50797d6 [clangd] Fix the range for include reference to itself.
Differential Revision: https://reviews.llvm.org/D155215
2023-07-14 12:51:14 +00:00
Haojian Wu
5649b24c48 [clangd] Fix an assertion failure in NamedDecl::getName during the prepareRename
getName method required to be called on a simple-identifier NamedDecl,
otherwise it will trigger an assertion.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D153617
2023-07-14 09:17:46 +02:00
Haojian Wu
85c6d57eb3 [Format][Tooling] Fix HeaderIncludes::insert not respect the main-file header.
Differential Revision: https://reviews.llvm.org/D154963
2023-07-13 10:41:46 +02:00
Jens Massberg
7ec9e20480 [clangd][c++20]Check for correct auto location in DeducedTypeVisitor
In case of a constrained auto the correct location has to chosen.

Differential Revision: https://reviews.llvm.org/D154623
2023-07-10 11:33:42 +02:00
Jens Massberg
8af9a373ad Add missing semantic highlighing for concepts.
Differential Revision: https://reviews.llvm.org/D154580
2023-07-06 16:28:57 +02:00
Jens Massberg
1af0e34477 [clangd][c++20] Drop first template argument in code completion in some contexts.
In case of a top level context the first template argument of a concept
should be dropped. Currently the indexer doesn't support different
signatures for different contexts (for an index entry always the default
`Symbol` context is used). Thus we add a hack which checks if we are in
a top level context and have a concept and in that case removes the
first argment of the signature and snippet suffix. If there is only a
single argument, the signature and snippet suffix are completly
removed. The check for the first argument is done by simply looking for
the first comma which should be sufficient in most cases.

Additionally extend test environment to support adding artificial index
entries with signature and completion snippet suffix.

Differential Revision: https://reviews.llvm.org/D154450
2023-07-05 12:04:24 +02:00
Kadir Cetinkaya
a59b24be47
[clangd] Downgrade deprecated warnings to hints
This tries to improve adoption of noisy warnings in existing codebases.
Hints have a lot less visual clutter in most of the editors, and DiagnosticTags
already imply a custom decorations per LSP.

Differential Revision: https://reviews.llvm.org/D154443
2023-07-04 16:07:08 +02:00
Kadir Cetinkaya
9841daf270
[clang][tooling] Fix early termination when there are nested expansions
This also does some cleanups, I am happy to undo them (or send as
separate patches):
- Change the early exit to stop only once we hit an expansion inside the
  main file, to make sure we keep following the nested expansions.
- Add more tests to cover all the cases mentioned in the implementation
- Drop the adjustments for prev/next tokens. We do the final checks
  based on the expansion locations anyway, so any intermediate mapping
  was a no-op.

Differential Revision: https://reviews.llvm.org/D154335
2023-07-03 16:58:04 +02:00
Haojian Wu
21b6da35f1 [clangd] Don't show header for namespace decl in Hover
The header for namespace symbol is barely useful.

Differential Revision: https://reviews.llvm.org/D154068
2023-06-29 17:11:19 +02:00
Haojian Wu
8ceb4190fe [clangd] Fix some typos, NFC 2023-06-28 14:05:21 +02:00
Kadir Cetinkaya
bd89f9ec29
[clangd] Always allow diagnostics from stale preambles
We've been running this internally for months now, without any
stability or correctness concerns. It has ~40% speed up on incremental
diagnostics latencies (as preamble can get invalidated through code completion
etc.).

Differential Revision: https://reviews.llvm.org/D153882
2023-06-28 10:41:45 +02:00
David Goldman
a42ce094d9 [clang][Sema] Add CodeCompletionContext::CCC_ObjCClassForwardDecl
- Use this new context in Sema to limit completions to seen ObjC class
  names

- Use this new context in clangd to disable include insertions when
  completing ObjC forward decls

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D150978
2023-06-27 16:25:40 -04:00
Haojian Wu
8aa88ee5e0 [clangd] Fix the flaky FindTarget unittest after 1b66840
after 1b66840, FindTarget will report multiple refs with the same
location, make the sort order of the refs deterministic in
FindTargetTests.
2023-06-27 09:48:41 +02:00
David Goldman
1b66840f71 [clangd][ObjC] Support ObjC class rename from implementation decls
Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D152720
2023-06-26 14:43:37 -04:00
Jens Massberg
6f065bfd63 [clangd][c++20]Consider rewritten binary operators in TargetFinder
In C++20 some binary operations can be rewritten, e.g. `a != b`
can be rewritten to `!(a == b)` if `!=` is not explicitly defined.
The `TargetFinder` hasn't considered the corresponding `CXXRewrittenBinaryOperator` yet. This resulted that the definition of such operators couldn't be found
when navigating to such a `!=` operator, see https://github.com/clangd/clangd/issues/1476.

In this patch we add support of `CXXRewrittenBinaryOperator` in `FindTarget`.
In such a case we redirect to the inner binary operator of the decomposed form.
E.g. in case that `a != b` has been rewritten to `!(a == b)` we go to the
`==` operator. The `==` operator might be implicitly defined (e.g. by a `<=>`
operator), but this case is already handled, see the new test.

I'm not sure if I the hover test which is added in this patch is the right one,
but at least is passed with this patch and fails without it :)

Note, that it might be a bit missleading that hovering over a `!=` refers to
"instance method operator==".

Differential Revision: https://reviews.llvm.org/D153331
2023-06-26 11:26:10 +02:00
Elliot Goodrich
b0abd4893f [llvm] Add missing StringExtras.h includes
In preparation for removing the `#include "llvm/ADT/StringExtras.h"`
from the header to source file of `llvm/Support/Error.h`, first add in
all the missing includes that were previously included transitively
through this header.
2023-06-25 15:42:22 +01:00
Haojian Wu
6585dd3b83 [clangd] Replace the hacky include-cleaner macro-reference implementation.
Now MainFileMacros preserves enough information, we perform a just-in-time
convertion to interop with include-cleaner::Macro for include-cleaer features.

Differential Revision: https://reviews.llvm.org/D147034
2023-06-23 14:08:55 +02:00
Haojian Wu
7298bcf7f0 [clangd] Store offsets in MacroOccurrence
Remove the existing `Rng` field.

From the review comment: https://reviews.llvm.org/D147034

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D153259
2023-06-23 09:21:08 +02:00