summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Reland "[AST] Traverse the class type loc inside the member type loc.""Haojian Wu2019-12-091-2/+2
| | | | | | | | | | | | Summary: added a unittest which causes "TL.getClassTInfo" is null. Reviewers: ilya-biryukov Subscribers: mgorny, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D71186
* Revert "[AST] Traverse the class type loc inside the member type loc."Sterling Augustine2019-12-051-2/+2
| | | | | | | This reverts commit 7f93cb62280a73e3e899d49c45be8bfbac634b7d. The assertion at RecursiveASTVisitor.h:1169 fails when passed a TypeLocNode. Not sure if the correct fix is to use getTypeLocClass or something else.
* [clangd] Highlighting dependent types in more contextsNathan Ridge2019-12-051-1/+18
| | | | | | | | | | | | | | Fixes https://github.com/clangd/clangd/issues/214. Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70746
* [clangd] Find reference to template parameter in 'sizeof...' expressionNathan Ridge2019-12-051-0/+7
| | | | | | | | | | | | | | Fixes https://github.com/clangd/clangd/issues/213. Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70740
* [AST] Traverse the class type loc inside the member type loc.Haojian Wu2019-12-051-2/+2
| | | | | | | | | | | | | | | Summary: We are missing this currently. This would fix https://github.com/clangd/clangd/issues/216. Reviewers: ilya-biryukov Subscribers: mgorny, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70849
* [clangd] Inactive regions support as an extension to semantic highlightingNathan Ridge2019-11-211-7/+36
| | | | Differential Revision: https://reviews.llvm.org/D67536
* [clangd] Implement semantic highlightings via findExplicitReferencesIlya Biryukov2019-11-051-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: To keep the logic of finding locations of interesting AST nodes in one place. The advantage is better coverage of various AST nodes, both now and in the future: as new nodes get added to `findExplicitReferences`, semantic highlighting will automatically pick them up. The drawback of this change is that we have to traverse declarations inside our file twice in order to highlight dependent names, 'auto' and 'decltype'. Hopefully, this should not affect the actual latency too much, most time should be spent in building the AST and not traversing it. Reviewers: hokein Reviewed By: hokein Subscribers: nridge, merge_guards_bot, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69673
* [clangd] Add missing highlights for using decls.Haojian Wu2019-10-291-0/+5
| | | | | | | | | | Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69506
* [clangd] Do not highlight keywords in semantic highlightingIlya Biryukov2019-10-281-69/+69
| | | | | | | | | | | | | | | | | | Summary: Editors are good at highlightings the keywords themselves. Note that this only affects highlightings of builtin types spelled out as keywords in the source code. Highlightings of typedefs to builtin types are unchanged. Reviewers: hokein Reviewed By: hokein Subscribers: merge_guards_bot, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69431
* [clangd] Improve semantic highlighting in dependent contexts (fixes #154)Nathan Ridge2019-10-141-1/+56
| | | | | | | | | | | | Reviewers: hokein Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67901 llvm-svn: 374799
* Make most clangd unittests pass on WindowsNico Weber2019-10-131-2/+8
| | | | | | | | | | | | | | | | | | | | The Windows triple currently turns on delayed template parsing, which confuses several unit tests that use templates. For now, just explicitly disable delayed template parsing. This isn't ideal, but: - the Windows triple will soon no longer use delayed template parsing by default - there's precedent for this in the clangd unit tests already - let's get the clangd tests pass on Windows first before making behavioral changes Part of PR43592. llvm-svn: 374718
* [clangd] Collect missing macro references.Haojian Wu2019-10-071-0/+14
| | | | | | | | | | | | | | Summary: Semantic highlghting is missing a few macro references. Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68458 llvm-svn: 373889
* [clangd] Collect macros in the preamble region of the main fileHaojian Wu2019-09-241-4/+4
| | | | | | | | | | | | | | | | Summary: - store all macro references in the ParsedAST; - unify the two variants of CollectMainFileMacros; Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67496 llvm-svn: 372725
* [clangd] Collect location of macro definition in the ParsedASTHaojian Wu2019-09-101-11/+13
| | | | | | | | | | | | allows semantic hightlighting macro definition Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67264 llvm-svn: 371504
* [clangd] Add a new highlighting kind for typedefsIlya Biryukov2019-09-091-6/+10
| | | | | | | | | | | | | | | | | | | Summary: We still attempt to highlight them as underlying types, but fallback to the generic 'typedef' highlighting kind if the underlying type is too complicated. Reviewers: hokein Reviewed By: hokein Subscribers: nridge, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67290 llvm-svn: 371402
* [clangd] Highlight typedefs to template parameters as template parametersIlya Biryukov2019-09-091-1/+16
| | | | | | | | | | | | | | | | | | | | | | | Summary: Template parameters were handled outside `addType`, this led to lack of highlightings for typedefs to template types. This was never desirable, we want to highlight our typedefs as their underlying type. Note that typedefs to more complicated types, like pointers and references are still not highlighted. Original patch by Johan Vikström. Reviewers: hokein, jvikstrom Reviewed By: hokein Subscribers: nridge, javed.absar, kristof.beyls, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66516 llvm-svn: 371379
* [clangd] Improve output of semantic highlighting tests in case of failuresIlya Biryukov2019-09-091-2/+37
| | | | | | | | | | | | | | | | | | | | | Summary: Instead of matching lists of highlightings, we annotate input code with resulting highlightings and diff it against the expected annotated input. In case of failures, this produces much nicer output in form of text-based diffs. Reviewers: hokein Reviewed By: hokein Subscribers: nridge, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67274 llvm-svn: 371373
* [clangd] Add highlighting for macro expansions.Johan Vikstrom2019-08-301-23/+25
| | | | | | | | | | | | | | Summary: https://github.com/clangd/clangd/issues/134 Reviewers: hokein, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66995 llvm-svn: 370482
* [clangd] Added highlighting for structured bindings.Johan Vikstrom2019-08-301-0/+15
| | | | | | | | | | | | | | Summary: Structured bindings are in a BindingDecl. The decl the declRefExpr points to are the BindingDecls. So this adds an additional if statement in the addToken function to highlight them. Reviewers: hokein, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66738 llvm-svn: 370473
* [clangd] Add distinct highlightings for static fields and methodsNathan Ridge2019-08-301-6/+10
| | | | | | | | | | | | | | Reviewers: hokein, ilya-biryukov, jvikstrom Reviewed By: hokein Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66828 llvm-svn: 370429
* [clangd] Add a distinct highlighting for local variablesNathan Ridge2019-08-271-57/+58
| | | | | | | | | | | | | | | | | | Summary: It's useful to be able to distinguish local variables from namespace scope variables. Reviewers: hokein, jvikstrom Reviewed By: hokein Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66723 llvm-svn: 370103
* [clangd] Send highlighting diff beyond the end of the file.Haojian Wu2019-08-261-16/+34
| | | | | | | | | | | | | | Summary: This would make the client life (tracking the changes) easier. Reviewers: jvikstrom Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66541 llvm-svn: 369884
* [clangd] Added highlighting for tokens that are macro arguments.Johan Vikstrom2019-08-191-4/+63
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: Adds semantic highlighting for tokens that are a macro argument. Example: ``` D_V(SomeVar); ``` The "SomeVar" inside the macro is highlighted as a variable now. Tokens that are in a macro body expansion are ignored in this patch for three reasons. * The spelling loc is inside the macro "definition" meaning it would highlight inside the macro definition (could probably easily be fixed by using getExpansionLoc instead of getSpellingLoc?) * If wanting to highlight the macro definition this could create duplicate tokens. And if the tokens are of different types there would be conflicts (tokens in the same range but with different types). Say a macro defines some name and both a variable declaration and a function use this, there would be two tokens in the macro definition but one with Kind "Variable" and the other with Kind "Function". * Thirdly, macro body expansions could come from a file that is not the main file (easily fixed, just check that the Loc is in the main file and not even a problem if we wanted to highlight the actual macro "invocation") Reviewers: hokein, sammccall, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64741 llvm-svn: 369275
* [clangd] Added special HighlightingKind for function parameters.Johan Vikstrom2019-08-191-11/+16
| | | | | | | | | | | | | | Summary: This means that function parameters are no longer highlighted as variable.other.cpp but instead as variable.parameter.cpp which is the more "correct" TextMate scope for them. Reviewers: hokein, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66335 llvm-svn: 369238
* [clangd] Added highlighting for non type templates.Johan Vikstrom2019-08-161-0/+53
| | | | | | | | | | | | | | | Summary: Non type templates were not being highlighted. This highlights them as TemplateParameters. Reviewers: hokein, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66221 llvm-svn: 369090
* [clangd] Remove highlightings coming from non topLevelDecls from included files.Johan Vikstrom2019-08-121-2/+19
| | | | | | | | | | | | | | Summary: It is possible to write include code from other files so that the decls from there do not become topLevelDecls (For example by including methods for a class). These Decls are not filtered by topLevelDecls and therefore SemanticHighlighting must manually check that every SLoc belongs in the main file. Otherwise there can be highlightings appearing in places where they should not. Reviewers: hokein, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66083 llvm-svn: 368563
* [clangd] Highlighting auto variables as the deduced type.Johan Vikstrom2019-08-121-2/+16
| | | | | | | | | | | | | | | | | | Summary: Done in VisitDeclaratorDecl as the AutoTypeLoc is not deduced. Scoped to only work for variables. auto function return values need to be handled in a special way (separate patch for that). auto's that are in lambdas ar enot highlighted as we don't highlight their underlying type (it's a RecordDecl, but the name is not an identifier so it returns in addToken). Reviewers: hokein, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65996 llvm-svn: 368546
* [clangd] Added highlighting for constructor initializers.Johan Vikstrom2019-08-091-0/+18
| | | | | | | | | | | | | | Summary: Constructor initializers were not being highlighted. This adds highlighting for them by using TraverseConstructorInitializer. Uses the Traverse* because there is no visit for CXXCtorInitializer. Reviewers: hokein, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66001 llvm-svn: 368434
* [AST] No longer visiting CXXMethodDecl bodies created by compiler when ↵Johan Vikstrom2019-08-091-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | method was default created. Summary: Clang generates function bodies and puts them in the AST for default methods if it is defaulted outside the class definition. ` struct A { A &operator=(A &&O); }; A &A::operator=(A &&O) = default; ` This will generate a function body for the `A &A::operator=(A &&O)` and put it in the AST. This body should not be visited if implicit code is not visited as it is implicit. This was causing SemanticHighlighting in clangd to generate duplicate tokens and putting them in weird places. Reviewers: hokein, ilya-biryukov, gribozavr Subscribers: mgorny, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65938 llvm-svn: 368402
* [clangd] Added semantic highlighting support for primitives.Johan Vikstrom2019-08-081-28/+32
| | | | | | | | | | | | | | | | Summary: Adds a new HighlightingKind "Primitive". Adds a special case for TypeLocs that have an underlying TypePtr that is are builtin types, adding them as primitives. The primary reason for this change is because otherwise typedefs that typedef primitives `typedef int A` would not get highlighted (so in the example `A` would not get any highlightings.) Reviewers: hokein, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65943 llvm-svn: 368291
* [clangd] Added an early return from VisitMemberExpr in SemanticHighlighting ↵Johan Vikstrom2019-08-081-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | if underlying MemberDecl is a CXXConversionDecl. Summary: Conversion operators contain invalid MemberLocs which caused SemanticHighlighting to emit a lot of error logs in large files as they can occur fairly often (for example converting StringRef to std string). As the only thing happening was a lot of error logs being emited there doesn't really seem to be any way to test this (no erroneous tokens are added). But emiting as many logs as were being emited is not wanted. This also adds a test to guard against regressions for highlightings disapearing from places where the conversion operators are used as their behaviour differ from the other CXXMethodDecls. Reviewers: hokein, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65928 llvm-svn: 368287
* [clangd] Fix implicit template instatiations appearing as topLevelDecls.Johan Vikstrom2019-08-081-0/+6
| | | | | | | | | | | | | | Summary: The parser gives implicit template instantiations to the action's HandleTopLevelDecls callback. This makes semantic highlighting highlight these templated functions multiple times. Fixed by filtering on if a Decl is an implicit function/variable/class instantiation. Also added a testcase to semantic highlighting on this. Reviewers: hokein, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65510 llvm-svn: 368261
* [clangd] Duplicate lines of semantic highlightings sent removed.Johan Vikstrom2019-08-011-17/+156
| | | | | | | | | | | | | | Summary: Added a class for diffing highlightings and removing duplicate lines. Integrated into the highlighting generation flow. Only works correctly if all tokens are on a single line. Also returns empty lines if the IDE should remove previous highlightings on a line. Reviewers: hokein, sammccall, ilya-biryukov Subscribers: MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64475 llvm-svn: 367521
* [clangd] Log input code of failed highlighting tests. NFCIlya Biryukov2019-07-221-1/+2
| | | | llvm-svn: 366674
* [clangd] Added highlightings for template parameters and specializations.Johan Vikstrom2019-07-181-6/+33
| | | | | | | | | | | | | | Summary: Template parameters and specializations were not being highlighted before. This adds highlightings to those types of tokens by adding two Visit* methods. Reviewers: hokein, sammccall, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64855 llvm-svn: 366420
* [clangd] Added highlighting for the targets in typedefs and using.Johan Vikstrom2019-07-161-1/+14
| | | | | | | | | | | | | | | | | | Summary: In `typedef int A` the `A` was not highlighted previously. This patch gives `A` the same kind of highlighting that the underlying type has (class/enum) (which in this example is no special highlighting because builtins are not handled yet) Will add highlightings for built ins in another patch. Reviewers: hokein, sammccall, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64754 llvm-svn: 366207
* [clangd] Fix duplicate highlighting tokens appearing in initializer lists.Johan Vikstrom2019-07-151-0/+7
| | | | | | | | | | | | | | Summary: The RecursiveASTVisitor sometimes visits exprs in initializer lists twice. Added deduplication to prevent duplicate highlighting tokens from appearing. Done by sorting and a linear search. Reviewers: hokein, sammccall, ilya-biryukov Subscribers: MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64634 llvm-svn: 366070
* [clangd] Added highlighting for members and methods.Johan Vikstrom2019-07-151-9/+35
| | | | | | | | | | | | | | Summary: Added highlighting for members and methods. Reviewers: hokein, sammccall, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64617 llvm-svn: 366047
* [clangd] Added highlighting to enum constants.Johan Vikstrom2019-07-151-5/+13
| | | | | | | | | | | | | | Summary: VSCode does not have a scope for enum constants. So they were placed under "constant.other.enum" as that seems to be the most correct scope for enum constants. However, this makes theia color them blue (the same color it uses for keywords). Reviewers: hokein, sammccall, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64624 llvm-svn: 366045
* [clangd] Added highlightings for namespace specifiers.Johan Vikstrom2019-07-111-5/+29
| | | | | | | | | | | | | | Summary: Added highlightings for namespace specifiers. Reviewers: hokein, sammccall, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64492 llvm-svn: 365745
* [clangd] Added highlighting for class and enum types.Johan Vikstrom2019-07-101-11/+43
| | | | | | | | | | | | | | Summary: Added highlighting for non-builtin types using VisitTypeLoc. Ignoring namespace qualifiers as for now. Reviewers: hokein, sammccall, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64257 llvm-svn: 365602
* [clangd] Added highlighting for variable references (declrefs)Johan Vikstrom2019-07-051-14/+29
| | | | | | | | | | | | | | Summary: Added highlighting for variable references using VisitDeclRefExpr. Reviewers: hokein, sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64199 llvm-svn: 365205
* [clangd] Emit publishSemanticHighlighting in LSP if enabledJohan Vikstrom2019-07-041-1/+25
| | | | | | | | | | | | | | Summary: Emit publishSemanticHighlighting in LSP if enabled Reviewers: hokein, kadircet Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63919 llvm-svn: 365111
* [clangd] Emit semantic highlighting tokens when the main AST is built.Johan Vikstrom2019-06-271-0/+26
| | | | | | Differential Revision: https://reviews.llvm.org/D63821 llvm-svn: 364551
* [clangd] Added functionality for getting semantic highlights for variable ↵Johan Vikstrom2019-06-261-0/+69
and function declarations llvm-svn: 364421
OpenPOWER on IntegriCloud