aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra/clangd/CodeComplete.cpp
AgeCommit message (Collapse)AuthorFilesLines
7 days[clangd] Improve Markup Rendering (#140498)tcottin1-1/+5
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-18[Clang][AST][NFC] Introduce `NamespaceBaseDecl` (#149123)Yanzuo Liu1-1/+0
Add `NamespaceBaseDecl` as common base class of `NamespaceDecl` and `NamespaceAliasDecl`. This simplifies `NestedNameSpecifier` a bit. Co-authored-by: Matheus Izvekov <mizvekov@gmail.com>
2025-07-12[Clang][AST][NFC] (`RecordDecl` -> `CXXRecordDecl`)`::isInjectedClassName` ↵Yanzuo Liu1-1/+1
(#148195) Move `RecordDecl::isInjectedClassName` to `CXXRecordDecl::isInjectedClassName`. C language doesn't have the term "injected class name". Co-authored-by: Matheus Izvekov <mizvekov@gmail.com>
2025-05-12[clangd] Add CodePatterns config option under Completion (#137613)Noustaa1-2/+10
Allows enabling/disabling code pattern & snippet suggestions during code completion. Resolves https://github.com/clangd/clangd/discussions/1867
2025-04-01[clang] improved preservation of template keyword (#133610)Matheus Izvekov1-1/+0
2025-03-20[clangd] Add `HeaderInsertion` config option (#128503)Mythreya1-1/+1
This is the config file equivalent of the `--header-insertion` command line option Fixes https://github.com/clangd/clangd/issues/2032
2025-01-15[clangd] Augment code completion results with documentation from the index. ↵Bevin Hansson1-0/+27
(#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
2024-12-27[clangd] Allow specifying what headers are always included via "" or <> (#67749)kleines Filmröllchen1-5/+9
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-10-06[clangd] Add ArgumentLists config option under Completion (#111322)Nathan Ridge1-8/+18
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-09-30[clangd] [C++20] [Modules] Support code complete for C++20 modules (#110083)Chuanqi Xu1-1/+4
According to https://github.com/ChuanqiXu9/clangd-for-modules/issues/9, I surprisingly found the support for C++20 modules doesn't support code completion well. After debugging, I found there are problems: (1) We forgot to call `adjustHeaderSearchOptions` in code complete. This may be an easy oversight. (2) In `CodeCompleteOptions::getClangCompleteOpts`, we may set `LoadExternal` as false when index is available. But we have support modules with index. So it is conflicting. Given modules are opt in now, I think it makes sense to to set LoadExternal as true when modules are enabled. This is a small fix and I wish it can land faster.
2024-04-11[clangd] Avoid using CompletionItemKind.Text for macro completions from the ↵Nathan Ridge1-3/+13
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-03-20[clangd] Handle variable templates consistently with class templates in code ↵Nathan Ridge1-1/+2
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-11[clangd] Avoid libFormat's objective-c guessing heuristic where possible ↵Nathan Ridge1-2/+2
(#84133) This avoids a known libFormat bug where the heuristic can OOM on certain large files (particularly single-header libraries such as miniaudio.h). The OOM will still happen on affected files if you actually try to format them (this is harder to avoid since the underlyting issue affects the actual formatting logic, not just the language-guessing heuristic), but at least it's avoided during non-modifying operations like hover, and modifying operations that do local formatting like code completion. Fixes https://github.com/clangd/clangd/issues/719 Fixes https://github.com/clangd/clangd/issues/1384 Fixes https://github.com/llvm/llvm-project/issues/70945
2023-12-13[clangd] Use StringRef::{starts,ends}_with (NFC)Kazu Hirata1-10/+10
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-11-12[clangd] Correctly identify the next token after the completion point (#69153)Nathan Ridge1-1/+41
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-09-28[clangd][CodeComplete] Improve FunctionCanBeCallYounan Zhang1-3/+3
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-05[clang] NFCI: Change returned LanguageOptions pointer to referenceJan Svoboda1-3/+3
2023-08-28Reland "[clang-repl] support code completion at a REPL."Fred Fu1-0/+1
Original commit message: " This patch enabled code completion for ClangREPL. The feature was built upon three existing Clang components: a list completer for LineEditor, a CompletionConsumer from SemaCodeCompletion, and the ASTUnit::codeComplete method. The first component serves as the main entry point of handling interactive inputs. Because a completion point for a compiler instance has to be unchanged once it is set, an incremental compiler instance is created for each code completion. Such a compiler instance carries over AST context source from the main interpreter compiler in order to obtain declarations or bindings from previous input in the same REPL session. The most important API codeComplete in Interpreter/CodeCompletion is a thin wrapper that calls with ASTUnit::codeComplete with necessary arguments, such as a code completion point and a ReplCompletionConsumer, which communicates completion results from SemaCodeCompletion back to the list completer for the REPL. In addition, PCC_TopLevelOrExpression and CCC_TopLevelOrExpression` top levels were added so that SemaCodeCompletion can treat top level statements like expression statements at the REPL. For example, clang-repl> int foo = 42; clang-repl> f<tab> From a parser's persective, the cursor is at a top level. If we used code completion without any changes, PCC_Namespace would be supplied to Sema::CodeCompleteOrdinaryName, and thus the completion results would not include foo. Currently, the way we use PCC_TopLevelOrExpression and CCC_TopLevelOrExpression is no different from the way we use PCC_Statement and CCC_Statement respectively. Differential revision: https://reviews.llvm.org/D154382 " The new patch also fixes clangd and several memory issues that the bots reported and upload the missing files.
2023-08-28Revert "Reland "[clang-repl] support code completion at a REPL.""Vassil Vassilev1-1/+0
This reverts commit 5ab25a42ba70c4b50214b0e78eaaccd30696fa09 due to forgotten files.
2023-08-28Reland "[clang-repl] support code completion at a REPL."Fred Fu1-0/+1
Original commit message: " This patch enabled code completion for ClangREPL. The feature was built upon three existing Clang components: a list completer for LineEditor, a CompletionConsumer from SemaCodeCompletion, and the ASTUnit::codeComplete method. The first component serves as the main entry point of handling interactive inputs. Because a completion point for a compiler instance has to be unchanged once it is set, an incremental compiler instance is created for each code completion. Such a compiler instance carries over AST context source from the main interpreter compiler in order to obtain declarations or bindings from previous input in the same REPL session. The most important API codeComplete in Interpreter/CodeCompletion is a thin wrapper that calls with ASTUnit::codeComplete with necessary arguments, such as a code completion point and a ReplCompletionConsumer, which communicates completion results from SemaCodeCompletion back to the list completer for the REPL. In addition, PCC_TopLevelOrExpression and CCC_TopLevelOrExpression` top levels were added so that SemaCodeCompletion can treat top level statements like expression statements at the REPL. For example, clang-repl> int foo = 42; clang-repl> f<tab> From a parser's persective, the cursor is at a top level. If we used code completion without any changes, PCC_Namespace would be supplied to Sema::CodeCompleteOrdinaryName, and thus the completion results would not include foo. Currently, the way we use PCC_TopLevelOrExpression and CCC_TopLevelOrExpression is no different from the way we use PCC_Statement and CCC_Statement respectively. Differential revision: https://reviews.llvm.org/D154382 " The new patch also fixes clangd and several memory issues that the bots reported.
2023-07-05[clangd][c++20] Drop first template argument in code completion in some ↵Jens Massberg1-3/+31
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-06-27[clang][Sema] Add CodeCompletionContext::CCC_ObjCClassForwardDeclDavid Goldman1-7/+24
- 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-05[clangd] Move completion signatures and labelDetailsSam McCall1-1/+5
(When clients support it, otherwise keep the existing rendering). In VSCode this makes the signature darker. Differential Revision: https://reviews.llvm.org/D151253
2023-05-16Migrate {starts,ends}with_insensitive to {starts,ends}_with_insensitive (NFC)Kazu Hirata1-1/+1
This patch migrates uses of StringRef::{starts,ends}with_insensitive to StringRef::{starts,ends}_with_insensitive so that we can use names similar to those used in std::string_view. Note that the llvm/ directory has migrated in commit 6c3ea866e93003e16fc55d3b5cedd3bc371d1fde. I'll post a separate patch to deprecate StringRef::{starts,ends}with_insensitive. Differential Revision: https://reviews.llvm.org/D150506
2023-04-27[clangd] Add batch fixes for include-cleaner diagnosticsHaojian Wu1-1/+1
For each unused-include/missing-include diagnostic, we provide fix-all alternative to them. This patch also adds LSP ChangeAnnotation support. Differential Revision: https://reviews.llvm.org/D147684
2023-03-17[clangd] Refine logic on $0 in completion snippetsYounan Zhang1-3/+2
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-02-24[clangd] Avoid using CompletionItemKind.Text for macro completionsNathan Ridge1-11/+12
Fixes https://github.com/clangd/clangd/issues/1484 Differential Revision: https://reviews.llvm.org/D144703
2023-02-09[clangd] Fix getQueryScopes for using-directive with inline namespaceTom Praschan1-37/+74
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-01-09[clangd] Full support for #import insertionsDavid Goldman1-5/+13
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-07[clang-tools-extra] Remove remaining uses of llvm::Optional (NFC)Kazu Hirata1-1/+0
This patch removes the unused "using" declaration and removes #include "llvm/ADT/Optional.h". 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
2023-01-07[clang-tools-extra] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata1-12/+12
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to clean up the "using" declarations, #include "llvm/ADT/Optional.h", etc. 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
2023-01-07[clang-tools-extra] Add #include <optional> (NFC)Kazu Hirata1-0/+1
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with 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-07[clangd] Allow to build Clangd without decision forestIlya Biryukov1-0/+11
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-06[clangd] Use std::nullopt instead of None (NFC)Kazu Hirata1-2/+1
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-06[clang][Tooling] Add support for generating #import editsDavid Goldman1-1/+2
And make use of this from clangd's CodeComplete and IncludeFixer, although currently they are both restricted only to #include symbols. Differential Revision: https://reviews.llvm.org/D128677
2022-12-06[clangd] Add new IncludeDirective to IncludeHeaderWithReferencesDavid Goldman1-4/+12
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-03[clang-tools-extra] Use std::nullopt instead of None (NFC)Kazu Hirata1-4/+4
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-11-21Don't use Optional::getPointer (NFC)Kazu Hirata1-4/+4
Since std::optional does not offer getPointer(), this patch replaces X.getPointer() with &*X to make the migration from llvm::Optional to std::optional easier. 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 Differential Revision: https://reviews.llvm.org/D138466
2022-11-17[clangd] Add heuristic for dropping snippet when completing member function ↵Tom Praschan1-0/+2
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-02[clangd] Add scoped enum constants to all-scopes-completionTom Praschan1-1/+1
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[clangd] Index unscoped enums in class scope for code completionTom Praschan1-1/+7
Fixes https://github.com/clangd/clangd/issues/1082 Differential Revision: https://reviews.llvm.org/D136925
2022-10-31[clangd] Populate ranges and symbol origin for paramname completionsKadir Cetinkaya1-1/+10
Differential Revision: https://reviews.llvm.org/D136951
2022-09-21[clangd] Return earlier when snippet is emptyTom Praschan1-2/+3
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-08[clangd] Set Incompleteness for spec fuzzyfind requestsKadir Cetinkaya1-6/+10
Differential Revision: https://reviews.llvm.org/D133479
2022-09-08[clangd][ObjC] Improve completions for protocols + category namesDavid Goldman1-15/+26
- 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-08-09LLVM_FALLTHROUGH => [[fallthrough]]. NFCFangrui Song1-1/+1
2022-07-24Remove redundaunt override specifiers (NFC)Kazu Hirata1-1/+1
Identified with modernize-use-override.
2022-07-19Argument name support for function pointer signature hintsQwinci1-2/+4
Fixes https://github.com/clangd/clangd/issues/1068 Reviewed By: nridge Differential Revision: https://reviews.llvm.org/D125120
2022-07-12[clang, clang-tools-extra] Use has_value instead of hasValue (NFC)Kazu Hirata1-1/+1
2022-07-01[clangd][ObjC] Fix ObjC method definition completionDavid Goldman1-1/+1
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