From e884b153f8c29438b818d9930b8342e5ac8f829f Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 18 Sep 2023 11:46:53 -0700 Subject: Fix highlighting of generic types without argument. (#3208) Co-authored-by: Yong He --- source/slang/slang-check-overload.cpp | 1 - .../slang-language-server-semantic-tokens.cpp | 124 +++++++++++---------- 2 files changed, 66 insertions(+), 59 deletions(-) (limited to 'source') diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp index ac93d6505..d7ed5975d 100644 --- a/source/slang/slang-check-overload.cpp +++ b/source/slang/slang-check-overload.cpp @@ -1510,7 +1510,6 @@ namespace Slang LookupResultItem innerItem; innerItem.breadcrumbs = genericItem.breadcrumbs; innerItem.declRef = innerRef; - AddDeclRefOverloadCandidates(innerItem, context); } else diff --git a/source/slang/slang-language-server-semantic-tokens.cpp b/source/slang/slang-language-server-semantic-tokens.cpp index e85da9824..159b91d01 100644 --- a/source/slang/slang-language-server-semantic-tokens.cpp +++ b/source/slang/slang-language-server-semantic-tokens.cpp @@ -51,71 +51,79 @@ List getSemanticTokens(Linkage* linkage, Module* module, UnownedS module->getModuleDecl(), [&](SyntaxNode* node) { - if (auto declRef = as(node)) + if (auto declRefExpr = as(node)) { - if (declRef->name) + auto declRef = declRefExpr->declRef; + auto loc = declRefExpr->loc; + if (!declRef) + return; + auto decl = declRef.getDecl(); + if (auto genDecl = as(decl)) + decl = genDecl->inner; + if (!decl) + return; + auto name = declRef.getDecl()->getName(); + if (!name) + return; + // Don't look at the expr if it is defined in a different file. + if (!manager->getHumaneLoc(loc, SourceLocType::Actual) + .pathInfo.foundPath.getUnownedSlice() + .endsWithCaseInsensitive(fileName)) + return; + SemanticToken token = + _createSemanticToken(manager, loc, name); + auto target = decl; + if (as(target)) { - // Don't look at the expr if it is defined in a different file. - if (!manager->getHumaneLoc(declRef->loc, SourceLocType::Actual) - .pathInfo.foundPath.getUnownedSlice() - .endsWithCaseInsensitive(fileName)) + if (target->hasModifier()) return; - SemanticToken token = - _createSemanticToken(manager, declRef->loc, declRef->name); - auto target = declRef->declRef.getDecl(); - if (as(target)) - { - if (target->hasModifier()) - return; - token.type = SemanticTokenType::Type; - } - else if (as(target)) - { - token.type = SemanticTokenType::Type; - token.length = doc->getTokenLength(token.line, token.col); - } - else if (as(target)) - { - token.type = SemanticTokenType::Type; - } - else if (as(target)) - { - token.type = SemanticTokenType::Property; - } - else if (as(target)) - { - token.type = SemanticTokenType::Parameter; - } - else if (as(target)) - { - if (as(declRef->originalExpr) || - as(declRef->originalExpr)) - { - return; - } - token.type = SemanticTokenType::Variable; - } - else if (as(target)) - { - token.type = SemanticTokenType::Function; - } - else if (as(target)) - { - token.type = SemanticTokenType::EnumMember; - } - else if (as(target)) - { - token.type = SemanticTokenType::Namespace; - } - - if (as(target)) + token.type = SemanticTokenType::Type; + } + else if (as(target)) + { + token.type = SemanticTokenType::Type; + token.length = doc->getTokenLength(token.line, token.col); + } + else if (as(target)) + { + token.type = SemanticTokenType::Type; + } + else if (as(target)) + { + token.type = SemanticTokenType::Property; + } + else if (as(target)) + { + token.type = SemanticTokenType::Parameter; + } + else if (as(target)) + { + if (as(declRefExpr->originalExpr) || + as(declRefExpr->originalExpr)) { - if (target->hasModifier()) - return; + return; } - maybeInsertToken(token); + token.type = SemanticTokenType::Variable; + } + else if (as(target)) + { + token.type = SemanticTokenType::Function; + } + else if (as(target)) + { + token.type = SemanticTokenType::EnumMember; + } + else if (as(target)) + { + token.type = SemanticTokenType::Namespace; } + if (as(target)) + { + if (target->hasModifier()) + return; + } + maybeInsertToken(token); } else if (auto accessorDecl = as(node)) { -- cgit v1.2.3