summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/SemanticHighlighting.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [clangd] Highlighting dependent types in more contextsNathan Ridge2019-12-051-0/+19
| | | | | | | | | | | | | | 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] Inactive regions support as an extension to semantic highlightingNathan Ridge2019-11-211-5/+37
| | | | Differential Revision: https://reviews.llvm.org/D67536
* [clangd] Store xref for Macros in ParsedAST.Utkarsh Saxena2019-11-181-2/+7
| | | | | | | This patch adds the cross references for Macros in the MainFile. We add references for the main file to the ParsedAST. We query the references from it using the SymbolID. Xref outside main file will be added to the index in a separate patch.
* [clangd] Implement semantic highlightings via findExplicitReferencesIlya Biryukov2019-11-051-151/+97
| | | | | | | | | | | | | | | | | | | | | | | | | | 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-5/+14
| | | | | | | | | | 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-9/+11
| | | | | | | | | | | | | | | | | | 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-0/+51
| | | | | | | | | | | | Reviewers: hokein Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67901 llvm-svn: 374799
* [clangd] Remove an unrelated comment, NFC.Haojian Wu2019-09-271-1/+0
| | | | llvm-svn: 373079
* [clangd] Collect macros in the preamble region of the main fileHaojian Wu2019-09-241-2/+3
| | | | | | | | | | | | | | | | 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] Simplify semantic highlighting visitorIlya Biryukov2019-09-161-169/+111
| | | | | | | | | | | | | | | | | | | | | | | | Summary: - Functions to compute highlighting kinds for things are separated from the ones that add highlighting tokens. This keeps each of them more focused on what they're doing: getting locations and figuring out the kind of the entity, correspondingly. - Less special cases in visitor for various nodes. This change is an NFC. Reviewers: hokein Reviewed By: hokein Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67341 llvm-svn: 372008
* [clangd] Collect location of macro definition in the ParsedASTHaojian Wu2019-09-101-4/+2
| | | | | | | | | | | | 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-8/+30
| | | | | | | | | | | | | | | | | | | 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-5/+9
| | | | | | | | | | | | | | | | | | | | | | | 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] Replace HighlightingKind::NumKinds with LastKind. NFCIlya Biryukov2019-09-091-4/+1
| | | | | | | | | | | | | | | | | | Summary: The latter simplifies the client code by avoiding the need to handle it as a separate case statement. Reviewers: hokein Reviewed By: hokein Subscribers: nridge, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67277 llvm-svn: 371375
* [clangd] Improve output of semantic highlighting tests in case of failuresIlya Biryukov2019-09-091-0/+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] Rename ClangdUnit.h -> ParsedAST.h. NFCSam McCall2019-09-041-0/+1
| | | | | | | | | | This much better reflects what is (now) in this header. Maybe a rename to ParsedTU would be an improvement, but that's a much more invasive change and life is too short. ClangdUnit is dead, long live ClangdUnitTests! llvm-svn: 370862
* [clangd] Add highlighting for macro expansions.Johan Vikstrom2019-08-301-6/+13
| | | | | | | | | | | | | | 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/+4
| | | | | | | | | | | | | | 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-4/+11
| | | | | | | | | | | | | | 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-7/+10
| | | | | | | | | | | | | | | | | | 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-6/+6
| | | | | | | | | | | | | | 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/+29
| | | | | | | | | | | | | | | | | | | | | | | | | 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-0/+7
| | | | | | | | | | | | | | 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/+4
| | | | | | | | | | | | | | | 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-0/+6
| | | | | | | | | | | | | | 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-14/+24
| | | | | | | | | | | | | | | | | | 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/+8
| | | | | | | | | | | | | | 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
* [clangd] Added semantic highlighting support for primitives.Johan Vikstrom2019-08-081-1/+7
| | | | | | | | | | | | | | | | 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/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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 buildbot failure from ambigous ArrayRef ctorJohan Vikstrom2019-08-011-2/+2
| | | | llvm-svn: 367529
* [clangd] Duplicate lines of semantic highlightings sent removed.Johan Vikstrom2019-08-011-15/+73
| | | | | | | | | | | | | | 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] Added highlightings for template parameters and specializations.Johan Vikstrom2019-07-181-0/+27
| | | | | | | | | | | | | | 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-3/+13
| | | | | | | | | | | | | | | | | | 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/+8
| | | | | | | | | | | | | | 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-1/+23
| | | | | | | | | | | | | | 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-0/+6
| | | | | | | | | | | | | | 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/+38
| | | | | | | | | | | | | | 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-5/+47
| | | | | | | | | | | | | | 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-10/+30
| | | | | | | | | | | | | | 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] Some tweaks on semantic highlighting lookuptable.Haojian Wu2019-07-041-9/+10
| | | | | | | | | | | | | | | | Summary: - move toTextMateScope to SemanticHighlighting.h; - move the buildLookupTable to LSP layer (as LSP requires such form); Reviewers: sammccall, jvikstrom Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64202 llvm-svn: 365135
* [clangd] Emit publishSemanticHighlighting in LSP if enabledJohan Vikstrom2019-07-041-0/+88
| | | | | | | | | | | | | | 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] No need to setTraversalScope in SemanticHighlighting.Haojian Wu2019-06-271-2/+1
| | | | | | | | | | | | | | | | Summary: We have already set it when the AST is being built, and setting TraversalScope is not free (it will clear the cache, which is expensive to build). Reviewers: jvikstrom Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63874 llvm-svn: 364528
* [clangd] Added functionality for getting semantic highlights for variable ↵Johan Vikstrom2019-06-261-0/+78
and function declarations llvm-svn: 364421
OpenPOWER on IntegriCloud