150 Commits

Author SHA1 Message Date
Mythreya Kuricheti
0977a6d9e7
[clang][CodeComplete] Consider qualifiers of explicit object parameters in overload suggestions (#154041)
Fixes https://github.com/llvm/llvm-project/issues/109608
2025-08-21 02:32:41 -04:00
Mythreya Kuricheti
d0cde323c3
[clang][CodeComplete] Do not suggest unqualified members in explicit-object member functions (#153760)
Fixes https://github.com/llvm/llvm-project/issues/141291
2025-08-20 01:24:04 -04:00
Harald-R
ff0093cecd
[clangd] Use resolved path when checking AngledHeaders/QuotedHeaders in IncludeInserter (#148371)
This makes IncludeInserter's behavior consistent with include-cleaner,
as discussed in https://github.com/llvm/llvm-project/pull/140594.
2025-08-08 03:57:28 -04:00
Mythreya Kuricheti
3466cdb769
[clang][CodeComplete] skip explicit obj param when creating signature string (#146649)
Fixes clangd/clangd#2284
2025-07-31 02:12:25 -04:00
tcottin
51994891e3
[clangd] Improve Markup Rendering (#140498)
This is a preparation for fixing clangd/clangd#529.

It changes the Markup rendering to markdown and plaintext.

- Properly separate paragraphs using an empty line between
- Dont escape markdown syntax for markdown output except for HTML
- Dont do any formatting for markdown because the client is handling the
actual markdown rendering
2025-07-25 02:45:56 +02:00
Mythreya
d9d9ab8698
[clang][CodeComplete] skip explicit obj param in code completion string (#146258)
Fixes clangd/clangd#2339
2025-07-01 08:33:56 -04:00
Noustaa
bfd2ef7659
[clangd] Add CodePatterns config option under Completion (#137613)
Allows enabling/disabling code pattern & snippet suggestions
during code completion.

Resolves https://github.com/clangd/clangd/discussions/1867
2025-05-12 14:22:27 -04:00
Mythreya
9cdbc47144
[clangd] Add HeaderInsertion config option (#128503)
This is the config file equivalent of the `--header-insertion` command line option

Fixes https://github.com/clangd/clangd/issues/2032
2025-03-20 02:22:29 -04:00
Bevin Hansson
030d48b7db
[clangd] Augment code completion results with documentation from the index. (#120099)
When looking up code completions from Sema, there is no associated
documentation. This is due to crash issues with stale preambles.
However, this also means that code completion results from other
than the main file do not have documentation in certain cases,
which is a bad user experience.

This patch performs a lookup into the index using the code
completion result declarations to find documentation, and
attaches it to the results.

Fixes clangd/clangd#2252
Fixes clangd/clangd#564
2025-01-15 01:14:20 -05:00
kleines Filmröllchen
1f90797f6a
[clangd] Allow specifying what headers are always included via "" or <> (#67749)
Projects can now add config fragments like this to their .clangd:

```yaml
Style:
  QuotedHeaders: "src/.*"
  AngledHeaders: ["path/sdk/.*", "third-party/.*"]
```

to force headers inserted via the --header-insertion=iwyu mode matching
at least one of the regexes to have <> (AngledHeaders) or ""
(QuotedHeaders) around them, respectively. For other headers (and in
conflicting cases where both styles have a matching regex), the current
system header detection remains.

Fixes https://github.com/clangd/clangd/issues/1247
2024-12-27 14:14:29 -05:00
Nathan Ridge
61fe67a401
[clangd] support outgoing calls in call hierarchy (#117673)
This reverts commit ce0f11325e0c62c5b81391589e9b93b412a85bc1.
2024-12-05 10:10:42 +01:00
Augie Fackler
ce0f11325e Revert "[clangd] Re-land "support outgoing calls in call hierarchy" (#117673)"
This reverts commit 7be3326200ef382705d8e6b2d7dc5378af96b34a.

Per https://protobuf.dev/programming-guides/dos-donts/#add-required
this will re-land tomorrow without the required fields.
2024-12-04 15:58:56 -05:00
Nathan Ridge
7be3326200
[clangd] Re-land "support outgoing calls in call hierarchy" (#117673)
Co-authored-by: Quentin Chateau <quentin.chateau@gmail.com>
2024-12-04 01:07:57 -05:00
Nathan Ridge
d77cab823f
Revert "[clangd] Support outgoing calls in call hierarchy (#77556)" (#117668)
This reverts commit ca184cfc088a843e545e5f04b48813e6f9bfba77.
2024-11-26 00:08:33 -05:00
Nathan Ridge
ca184cfc08
[clangd] Support outgoing calls in call hierarchy (#77556)
Co-authored-by: Quentin Chateau <quentin.chateau@gmail.com>
2024-11-25 23:58:33 -05:00
Nathan Ridge
18ca7ad339
[clangd] Add ArgumentLists config option under Completion (#111322)
The new config option is a more flexible version of
--function-arg-placeholders, allowing users more detailed control of
what is inserted in argument list position when clangd completes the
name of a function in a function call context.

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

Co-authored-by: MK-Alias <ImNotReadingThis@maininator.com>
2024-10-06 20:32:54 -04:00
kadir çetinkaya
2cdbc9cff3
[clangd] Use TargetOpts from preamble when building ASTs (#88381)
Building ASTs with compile flags that are incompatible to the ones used
for the Preamble are not really supported by clang and can trigger
crashes.

In an ideal world, we should be re-using not only TargetOpts, but the
full ParseInputs from the Preamble to prevent such failures.

Unfortunately current contracts of ThreadSafeFS makes this a non-safe
change for certain implementations. As there are no guarantees that the
same ThreadSafeFS is going to be valid in the Context::current() we're
building the AST in.
2024-04-18 16:58:16 +02:00
Nathan Ridge
7aa371687a
[clangd] Avoid using CompletionItemKind.Text for macro completions from the index (#88236)
This was fixed in https://github.com/clangd/clangd/issues/1484 for Sema
completions but the fix did not apply to index completions.

Fixes https://github.com/clangd/clangd/issues/2002
2024-04-11 19:34:53 -04:00
Nathan Ridge
807fd07646
[clangd] Handle variable templates consistently with class templates in code completion (#85740)
The option --function-arg-placeholders=0 results in placeholders being
omitted for class template argument lists. This patch extends the same
treatment to variable template argument lists.

Fixes https://github.com/clangd/clangd/issues/1976
2024-03-20 02:44:04 -04:00
Qwinci
7bad74e667
[clangd] Show argument names for function pointer struct fields (#69011)
Show argument names in signature help when calling a function pointer
struct field.
2024-03-05 23:33:55 -05:00
Kazu Hirata
d5953e3e30 [clangd] Use StringRef::{starts,ends}_with (NFC)
This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
2023-12-13 23:26:09 -08:00
Nathan Ridge
cee598720f
[clangd] Correctly identify the next token after the completion point (#69153)
The code was previously using Lexer::findNextToken() which does not
handle being passed the completion point as input.

Fixes https://github.com/clangd/clangd/issues/1785
2023-11-12 02:13:22 -05:00
Younan Zhang
23ef8bf9c0 [clangd][CodeComplete] Improve FunctionCanBeCall
From two aspects:

- For function templates, emit additional template argument
placeholders in the context where it can't be a call in order
to specify an instantiation explicitly.

- Consider expressions with base type specifier such as
'Derived().Base::foo^' a function call.

Reviewed By: nridge

Differential Revision: https://reviews.llvm.org/D156605
2023-09-28 21:42:02 +08: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
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
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
Sam McCall
3f9f146371 [clangd] Move completion signatures and labelDetails
(When clients support it, otherwise keep the existing rendering).

In VSCode this makes the signature darker.

Differential Revision: https://reviews.llvm.org/D151253
2023-06-05 18:05:18 +02:00
Kadir Cetinkaya
0d1be98a67
[clang][USR] Prevent crashes on incomplete FunctionDecls
FunctionDecls can be created with null types (D124351 added such a new
code path), to be filled in later. But parsing can stop before
completing the Decl (e.g. if code completion
point is reached).
Unfortunately most of the methods in FunctionDecl and its derived
classes assume a complete decl and don't perform null-checks.
Since we're not encountring crashes in the wild along other code paths
today introducing extra checks into quite a lot of places didn't feel
right (due to extra complexity && run time checks).
I believe another alternative would be to change Parser & Sema to never
create decls with invalid types, but I can't really see an easy way of
doing that, as most of the pieces are structured around filling that
information as parsing proceeds.

Differential Revision: https://reviews.llvm.org/D149733
2023-05-15 18:05:48 +02:00
Younan Zhang
138adb0980 [clangd] Refine logic on $0 in completion snippets
We have a workaround from D128621 that makes $0 no longer being
a placeholder to conform a vscode feature. However, we have to
refine the logic as it may suppress the last parameter placeholder
for constructor of base class because not all patterns of completion
are compound statements.

This fixes clangd/clangd#1479

Reviewed By: nridge

Differential Revision: https://reviews.llvm.org/D145319
2023-03-17 17:57:24 +08:00
Nathan Ridge
c4972d3729 [clangd] Avoid using CompletionItemKind.Text for macro completions
Fixes https://github.com/clangd/clangd/issues/1484

Differential Revision: https://reviews.llvm.org/D144703
2023-02-24 04:41:27 -05:00
Tom Praschan
ce87b03143 [clangd] Fix getQueryScopes for using-directive with inline namespace
For example, in the following code

```

using namespace std::string_literals;

int main() {
    strin^ // Completes `string` instead of `std::string`
}
```

The using declaration would make completion drop the std namespace, even though it shouldn't.

printNamespaceScope() skips inline namespaces, so to fix this use
printQualifiedName() instead

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

Differential Revision: https://reviews.llvm.org/D140915
2023-02-09 20:53:33 +01:00
Jordan Rupprecht
3432f4bf86 [test] Split out Annotations from TestingSupport
The Annotations helper class does not have a gtest or gmock dependency, but because it's bundled with the rest of TestingSupport, it gets one. By splitting it out, a target can use it without being forced to use LLVM's copy of gtest.

Reviewed By: GMNGeoffrey, sammccall, gribozavr2

Differential Revision: https://reviews.llvm.org/D141175
2023-01-12 13:40:47 -08:00
David Goldman
042dd99484 [clangd] Full support for #import insertions
These are still disabled by default, but will work in ObjC code if you
enable the `-import-insertions` flag.

Completion requires ASTSignals to be available; before ASTSignals are
available, we will always use #include. Once they are available, the
behavior varies as follows:

- For source files, use #import if the ObjC language flag is enabled
- For header files:
  - If the ObjC language flag is disabled, use #include
  - If the header file contains any #imports, use #import
  - If the header file references any ObjC decls, use #import
  - Otherwise, use #include

IncludeFixer support is similar, but it does not rely upon ASTSignals,
instead it does the above checks excluding the scan for ObjC symbols.

Differential Revision: https://reviews.llvm.org/D139458
2023-01-09 09:48:30 -05:00
Nathan Ridge
6761ba7639 [clangd] Avoid triggering linkage computation for decl with unstable linkage in SymbolRelevanceSignals::computeASTSignals()
Fixes https://github.com/clangd/clangd/issues/1427

Differential Revision: https://reviews.llvm.org/D140379
2022-12-20 21:56:36 -05:00
Ilya Biryukov
c9b325088d [clangd] Allow to build Clangd without decision forest
Make it possible to disable building the decision forest ranking
model for clangd.  To unbreak build of Clangd on PPC32 in gentoo, see
https://bugs.gentoo.org/829602

Based on D138520.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D139107
2022-12-07 13:52:22 +01:00
David Goldman
51f1ae52b0 [clangd] Add new IncludeDirective to IncludeHeaderWithReferences
The IncludeDirective contains both Include (the current behavior) and Import,
which we can use in the future to provide #import suggestions for
Objective-C files/symbols.

Differential Revision: https://reviews.llvm.org/D128457
2022-12-06 13:47:07 -05:00
Kazu Hirata
649ef3386b [clang-tools-extra] Use std::nullopt instead of llvm::None (NFC)
This patch mechanically replaces None with std::nullopt where the
compiler would warn if None were deprecated.  The intent is to reduce
the amount of manual work required in migrating from Optional to
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-05 21:49:31 -08:00
Tom Praschan
0e00611cbc [clangd] Add heuristic for dropping snippet when completing member function pointer
This implements the 1st heuristic mentioned in https://github.com/clangd/clangd/issues/968#issuecomment-1002242704:

When completing a function that names a non-static member of a class, and we are not inside that class's scope, assume the reference will not be a call (and thus don't add the snippetSuffix)

Reviewed By: nridge

Differential Revision: https://reviews.llvm.org/D137040
2022-11-17 00:37:16 +01:00
Tom Praschan
990c189379 [clangd] Add scoped enum constants to all-scopes-completion
This was originally part of https://reviews.llvm.org/D136925, but we decided to move it to a separate patch.
In case it turns out to be controversial, it can be reverted more easily.

Differential Revision: https://reviews.llvm.org/D137104
2022-11-02 20:38:01 +01:00
Tom Praschan
a68bcd81dc [clangd] Index unscoped enums in class scope for code completion
Fixes https://github.com/clangd/clangd/issues/1082

Differential Revision: https://reviews.llvm.org/D136925
2022-11-02 12:50:50 +01:00
Kadir Cetinkaya
da5ded4fc9
[clangd] Populate ranges and symbol origin for paramname completions
Differential Revision: https://reviews.llvm.org/D136951
2022-10-31 11:34:06 +01:00
Tom Praschan
60528c690a [clangd] Return earlier when snippet is empty
Fixes github.com/clangd/clangd/issues/1216

If the Snippet string is empty, Snippet.front() would trigger a crash.
Move the Snippet->empty() check up a few lines to avoid this. Should not
break any existing behavior.

Differential Revision: https://reviews.llvm.org/D134137
2022-09-21 00:45:26 +02:00
Kadir Cetinkaya
71c4fb1d64
[clangd] Set Incompleteness for spec fuzzyfind requests
Differential Revision: https://reviews.llvm.org/D133479
2022-09-08 18:34:25 +02:00
David Goldman
e09c750498 [clangd][ObjC] Improve completions for protocols + category names
- Render protocols as interfaces to differentiate them from classes
  since a protocol and class can have the same name. Take this one step
  further though, and only recommend protocols in ObjC protocol completions.

- Properly call `includeSymbolFromIndex` even with a cached
  speculative fuzzy find request

- Don't use the index to provide completions for category names,
  symbols there don't make sense

Differential Revision: https://reviews.llvm.org/D132962
2022-09-08 11:30:26 -04:00
Nathan Ridge
2eba08fd9a [clangd] Do not try to use $0 as a placeholder in completion snippets
$0 can only be used as a tab stop, not as a placeholder (e.g.
`${0:expression}` is not valid)

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

Differential Revision: https://reviews.llvm.org/D128621
2022-07-24 03:01:18 -04:00
Qwinci
3f73c57935 Argument name support for function pointer signature hints
Fixes https://github.com/clangd/clangd/issues/1068

Reviewed By: nridge

Differential Revision: https://reviews.llvm.org/D125120
2022-07-19 20:02:26 -04:00
David Goldman
dc6c1f181b [clangd][ObjC] Fix ObjC method definition completion
D124637 improved filtering of method expressions, but not method
definitions. With this change, clangd will now filter ObjC method
definition completions based on their entire selector instead of
only the first selector fragment.

Differential Revision: https://reviews.llvm.org/D128821
2022-07-01 10:02:47 -04:00
Kazu Hirata
b8df4093e4 [clang, clang-tools-extra] Don't use Optional::{hasValue,getValue} (NFC) 2022-06-25 11:55:33 -07:00
David Goldman
bc1f24332a [clangd] Improve ObjC protocol suggestions from the index
When querying the index during an ObjC protocol name lookup for code
completion, we should only suggest ObjC protocols.

Differential Revision: https://reviews.llvm.org/D127125
2022-06-15 15:02:37 -04:00
Furkan Usta
462def25ec
[clang] Use correct visibility parameters when following a Using declaration
Fixes https://github.com/clangd/clangd/issues/1137

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D127629
2022-06-15 15:52:59 +02:00