aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaCodeComplete.cpp
AgeCommit message (Collapse)AuthorFilesLines
2022-06-25Don't use Optional::hasValue (NFC)Kazu Hirata1-2/+2
2022-06-20[clang] Don't use Optional::getValue (NFC)Kazu Hirata1-1/+1
2022-06-20[clang] Don't use Optional::hasValue (NFC)Kazu Hirata1-2/+2
2022-06-15[clang] Use correct visibility parameters when following a Using declarationFurkan Usta1-2/+6
Fixes https://github.com/clangd/clangd/issues/1137 Reviewed By: kadircet Differential Revision: https://reviews.llvm.org/D127629
2022-05-24[libclang] add supporting for indexing/visiting C++ conceptsAlex Lorenz1-0/+3
This commit builds upon recently added indexing support for C++ concepts from https://reviews.llvm.org/D124441 by extending libclang to support indexing and visiting concepts, constraints and requires expressions as well. Differential Revision: https://reviews.llvm.org/D126031
2022-04-16Add some helpers to better check Scope's kind. NFCJun Zhang1-2/+1
Signed-off-by: Jun Zhang <jun@junz.org>
2022-04-15[clang][lex] NFC: Use FileEntryRef in PreprocessorLexer::getFileEntry()Jan Svoboda1-1/+1
This patch changes the return type of `PreprocessorLexer::getFileEntry()` so that its clients may stop using the deprecated APIs of `FileEntry`. Reviewed By: bnbarham Differential Revision: https://reviews.llvm.org/D123772
2022-03-18Use llvm::append_range instead of push_back loops where applicable. NFCI.Benjamin Kramer1-2/+1
2022-03-17[clang] AddObjCKeyValueCompletions - use castAs<> instead of getAs<> to ↵Simon Pilgrim1-2/+2
avoid dereference of nullptr The pointers are always dereferenced, so assert the cast is correct instead of returning nullptr
2022-02-11[clang][sema] - remove CodeCompleter nullptr checksSimon Pilgrim1-4/+3
All paths have already dereferenced the CodeCompleter pointer in the ResultBuilder constructor
2022-01-26[CodeCompletion][clangd] Clean __uglified parameter names in completion & hoverSam McCall1-7/+8
Underscore-uglified identifiers are used in standard library implementations to guard against collisions with macros, and they hurt readability considerably. (Consider `push_back(Tp_ &&__value)` vs `push_back(Tp value)`. When we're describing an interface, the exact names of parameters are not critical so we can drop these prefixes. This patch adds a new PrintingPolicy flag that can applies this stripping when recursively printing pieces of AST. We set it in code completion/signature help, and in clangd's hover display. All three features also do a bit of manual poking at names, so fix up those too. Fixes https://github.com/clangd/clangd/issues/736 Differential Revision: https://reviews.llvm.org/D116387
2022-01-21[CodeComplete] fix nullptr crash in 612f5ed8823120Sam McCall1-3/+4
2022-01-12[clang][CodeComplete] Perform approximate member search in basesKadir Cetinkaya1-4/+10
Differential Revision: https://reviews.llvm.org/D117037
2022-01-11[CodeCompletion] Complete designators for fields in anonymous structs/unionsSam McCall1-1/+9
Fixes https://github.com/clangd/clangd/issues/836 Differential Revision: https://reviews.llvm.org/D116717
2022-01-09[clang] Use true/false instead of 1/0 (NFC)Kazu Hirata1-1/+1
Identified with modernize-use-bool-literals.
2022-01-04[CodeCompletion] Signature help for aggregate initialization.Sam McCall1-66/+185
The "parameter list" is the list of fields which should be initialized. We introduce a new OverloadCandidate kind for this. It starts to become harder for CC consumers to handle all the cases for params, so I added some extra APIs on OverloadCandidate to abstract them. Includes some basic support for designated initializers. The same aggregate signature is shown, the current arg jumps after the one you just initialized. This follows C99 semantics for mixed designated/positional initializers (which clang supports in C++ as an extension) and is also a useful prompt for C++ as C++ designated initializers must be in order. Related bugs: - https://github.com/clangd/clangd/issues/965 - https://github.com/clangd/clangd/issues/306 Differential Revision: https://reviews.llvm.org/D116326
2022-01-04[CodeComplete] drop unused Scope param. NFCSam McCall1-5/+4
2022-01-03Silence a "not all control paths return a value" warning; NFCAaron Ballman1-0/+1
2022-01-03[CodeCompletion] Signature help for braced constructor callsSam McCall1-14/+36
Implementation is based on the "expected type" as used for designated-initializers in braced init lists. This means it can deduce the type in some cases where it's not written: void foo(Widget); foo({ /*help here*/ }); Only basic constructor calls are in scope of this patch, excluded are: - aggregate initialization (no help is offered for aggregates) - initializer_list initialization (no help is offered for these constructors) Fixes https://github.com/clangd/clangd/issues/306 Differential Revision: https://reviews.llvm.org/D116317
2022-01-03[CodeCompletion] Signature help for template argument listsSam McCall1-4/+134
Provide signature while typing template arguments: Foo< ^here > Here the parameters are e.g. "typename x", and the result type is e.g. "struct" (class template) or "int" (variable template) or "bool (std::string)" (function template). Multiple overloads are possible when a template name is used for several overloaded function templates. Fixes https://github.com/clangd/clangd/issues/299 Differential Revision: https://reviews.llvm.org/D116352
2022-01-02[clang] Remove redundant member initialization (NFC)Kazu Hirata1-1/+1
Identified with readability-redundant-member-init.
2021-12-24Remove redundant return and continue statements (NFC)Kazu Hirata1-1/+0
Identified with readability-redundant-control-flow.
2021-11-18[clang][clangd] Improve signature help for variadic functions.Adam Czachorowski1-1/+2
This covers both C-style variadic functions and template variadic w/ parameter packs. Previously we would return no signatures when working with template variadic functions once activeParameter reached the position of the parameter pack (except when it was the only param, then we'd still show it when no arguments were given). With this commit, we now show signathure help correctly. Additionally, this commit fixes the activeParameter value in LSP output of clangd in the presence of variadic functions (both kinds). LSP does not allow the activeParamter to be higher than the number of parameters in the active signature. With "..." or parameter pack being just one argument, for all but first argument passed to "..." we'd report incorrect activeParameter value. Clients such as VSCode would then treat it as 0, as suggested in the spec) and highlight the wrong parameter. In the future, we should add support for per-signature activeParamter value, which exists in LSP since 3.16.0. This is not part of this commit. Differential Revision: https://reviews.llvm.org/D111318
2021-11-10[CodeCompletion] Generally consider header files without extensionChristian Kandeler1-10/+15
Real-world use case: The Qt framework's headers have the same name as the respective class defined in them, and Qt's traditional qmake build tool uses -I (rather than -isystem) to pull them in. Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D112996
2021-10-06PR50644: Do not warn on a declaration of `operator"" _foo`.Richard Smith1-3/+1
Also do not warn on `#define _foo` or `#undef _foo`. Only global scope names starting with _[a-z] are reserved, not the use of such an identifier in any other context.
2021-09-20[clang] Fix a few comment more typos to cycle botsNico Weber1-1/+1
2021-08-19[CodeCompletion] Provide placeholders for known attribute argumentsSam McCall1-10/+36
Completion now looks more like function/member completion: used alias(Aliasee) abi_tag(Tags...) Differential Revision: https://reviews.llvm.org/D108109
2021-08-19[CodeComplete] Only complete attributes that match the current LangOptsSam McCall1-1/+2
Differential Revision: https://reviews.llvm.org/D108111
2021-08-12[CodeComplete] Basic code completion for attribute names.Sam McCall1-0/+127
Only the bare name is completed, with no args. For args to be useful we need arg names. These *are* in the tablegen but not currently emitted in usable form, so left this as future work. C++11, C2x, GNU, declspec, MS syntax is supported, with the appropriate spellings of attributes suggested. `#pragma clang attribute` is supported but not terribly useful as we only reach completion if parens are balanced (i.e. the line is not truncated) There's no filtering of which attributes might make sense in this grammatical context (e.g. attached to a function). In code-completion context this is hard to do, and will only work in few cases :-( There's also no filtering by langopts: this is because currently the only way of checking is to try to produce diagnostics, which requires a valid ParsedAttr which is hard to get. This should be fairly simple to fix but requires some tablegen changes to expose the logic without the side-effect. Differential Revision: https://reviews.llvm.org/D107696
2021-06-25[clang] Rename StringRef _lower() method calls to _insensitive()Martin Storsjö1-4/+4
This is mostly a mechanical change, but a testcase that contains parts of the StringRef class (clang/test/Analysis/llvm-conventions.cpp) isn't touched.
2021-06-08[clang] p1099 using enum part 2Nathan Sidwell1-0/+3
This implements the 'using enum maybe-qualified-enum-tag ;' part of 1099. It introduces a new 'UsingEnumDecl', subclassed from 'BaseUsingDecl'. Much of the diff is the boilerplate needed to get the new class set up. There is one case where we accept ill-formed, but I believe this is merely an extended case of an existing bug, so consider it orthogonal. AFAICT in class-scope the c++20 rule is that no 2 using decls can bring in the same target decl ([namespace.udecl]/8). But we already accept: struct A { enum { a }; }; struct B : A { using A::a; }; struct C : B { using A::a; using B::a; }; // same enumerator this patch permits mixtures of 'using enum Bob;' and 'using Bob::member;' in the same way. Differential Revision: https://reviews.llvm.org/D102241
2021-05-27Add support for #elifdef and #elifndefAaron Ballman1-0/+12
WG14 adopted N2645 and WG21 EWG has accepted P2334 in principle (still subject to full EWG vote + CWG review + plenary vote), which add support for #elifdef as shorthand for #elif defined and #elifndef as shorthand for #elif !defined. This patch adds support for the new preprocessor directives.
2021-05-04Introduce -Wreserved-identifierserge-sans-paille1-6/+5
Warn when a declaration uses an identifier that doesn't obey the reserved identifier rule from C and/or C++. Differential Revision: https://reviews.llvm.org/D93095
2021-04-19[clang] NFC: Fix range-based for loop warnings related to decl lookupJan Svoboda1-2/+2
2021-03-16[CodeCompletion] Avoid spurious signature help for init-list argsSam McCall1-2/+3
Somewhat surprisingly, signature help is emitted as a side-effect of computing the expected type of a function argument. The reason is that both actions require enumerating the possible function signatures and running partial overload resolution, and doing this twice would be wasteful and complicated. Change #1: document this, it's subtle :-) However, sometimes we need to compute the expected type without having reached the code completion cursor yet - in particular to allow completion of designators. eb4ab3358cd4dc834a761191b5531b38114f7b13 did this but introduced a regression - it emits signature help in the wrong location as a side-effect. Change #2: only emit signature help if the code completion cursor was reached. Currently there is PP.isCodeCompletionReached(), but we can't use it because it's set *after* running code completion. It'd be nice to set this implicitly when the completion token is lexed, but ConsumeCodeCompletionToken() makes this complicated. Change #3: call cutOffParsing() *first* when seeing a completion token. After this, the fact that the Sema::Produce*SignatureHelp() functions are even more confusing, as they only sometimes do that. I don't want to rename them in this patch as it's another large mechanical change, but we should soon. Change #4: prepare to rename ProduceSignatureHelp() to GuessArgumentType() etc. Differential Revision: https://reviews.llvm.org/D98488
2021-03-16[CodeCompletion] Don't track preferred types if code completion is disabled.Sam McCall1-1/+21
Some of this work isn't quite trivial. (As requested in D96058) Differential Revision: https://reviews.llvm.org/D98459
2021-02-22[clang][CodeComplete] Ensure there are no crashes when completing with ↵Kadir Cetinkaya1-14/+16
ParenListExprs as LHS Differential Revision: https://reviews.llvm.org/D96950
2021-02-11[CodeComplete] Member completion: heuristically resolve some dependent base ↵Sam McCall1-2/+71
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-08[clang][CodeComplete] Fix crash on ParenListExprsKadir Cetinkaya1-2/+16
Fixes https://github.com/clangd/clangd/issues/676. Differential Revision: https://reviews.llvm.org/D95935
2021-02-04[CodeComplete] Guess type for designated initializersSam McCall1-15/+47
This enables: - completion in { .x.^ } - completion in { .x = { .^ } } - type-based ranking of candidates for { .x = ^ } Differential Revision: https://reviews.llvm.org/D96058
2021-01-25[clangd] Fix a crash when indexing invalid ObjC method declarationAdam Czachorowski1-1/+3
This fix will make us not crash, but ideally we would handle this case better. Differential Revision: https://reviews.llvm.org/D94919
2021-01-22[CodeComplete] Add ranged for loops code pattern.Nathan James1-0/+23
Add code pattersn for c++ `range for` loops and objective c `for...in` loops. Reviewed By: kadircet Differential Revision: https://reviews.llvm.org/D95131
2020-12-07[clang] Add a new nullability annotation for swift async: _Nullable_resultErik Pilkington1-0/+4
_Nullable_result generally like _Nullable, except when being imported into a swift async method. rdar://70106409 Differential revision: https://reviews.llvm.org/D92495
2020-11-16Convert TypeSpecifierSign from Specifiers.h to a scoped enum; NFCThorsten1-1/+1
2020-11-10[NFC, Refactor] Rename the (scoped) enum DeclaratorContext's enumerators to ↵Faisal Vali1-2/+2
remove duplication Since these are scoped enumerators, they have to be prefixed by DeclaratorContext, so lets remove Context from the name, and return some characters to the multiverse. Patch was reviewed here: https://reviews.llvm.org/D91011 Thank you to aaron, bruno, wyatt and barry for indulging me.
2020-08-17[clang] Make signature help work with dependent argsKadir Cetinkaya1-18/+35
Fixes https://github.com/clangd/clangd/issues/490 Differential Revision: https://reviews.llvm.org/D85826
2020-07-01[CodeComplete] Add code completion after function equalslh1231-0/+49
Summary: Provide `default` and `delete` completion after the function equals. Reviewers: kadircet, sammccall Tags: #clang Differential Revision: https://reviews.llvm.org/D82548
2020-06-30[CodeComplete] Tweak completion for else.Nathan James1-15/+20
If an `if` statement uses braces for its `then` block, suggest braces for the `else` and `else if` completion blocks, Otherwise don't suggest them. Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D82626
2020-06-26[CodeComplete] Add code completion for using alias.Kadir Cetinkaya1-0/+18
Add code completion for using alias. Patch By @lh123 ! Reviewers: kadircet Differential Revision: https://reviews.llvm.org/D82535
2020-06-26[CodeComplete] Tweak code completion for `typename`.Kadir Cetinkaya1-3/+1
Summary: Currently, clangd always completes `typename` as `typename qualifier::name`, I think the current behavior is not useful when the code completion is triggered in `template <>`. So I tweak it to `typename identifier`. Patch by @lh123 ! Reviewers: sammccall, kadircet Reviewed By: kadircet Subscribers: ilya-biryukov, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D82373