diff options
| author | Yong He <yonghe@outlook.com> | 2023-09-18 11:46:53 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-18 11:46:53 -0700 |
| commit | e884b153f8c29438b818d9930b8342e5ac8f829f (patch) | |
| tree | c3677cec4ebb3d755aa029bc03b0ac51dd8158a1 /source | |
| parent | 8bcffcc085b996babedfeaee674c6ad09c9b08cf (diff) | |
Fix highlighting of generic types without argument. (#3208)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-check-overload.cpp | 1 | ||||
| -rw-r--r-- | source/slang/slang-language-server-semantic-tokens.cpp | 124 |
2 files changed, 66 insertions, 59 deletions
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<SemanticToken> getSemanticTokens(Linkage* linkage, Module* module, UnownedS module->getModuleDecl(), [&](SyntaxNode* node) { - if (auto declRef = as<DeclRefExpr>(node)) + if (auto declRefExpr = as<DeclRefExpr>(node)) { - if (declRef->name) + auto declRef = declRefExpr->declRef; + auto loc = declRefExpr->loc; + if (!declRef) + return; + auto decl = declRef.getDecl(); + if (auto genDecl = as<GenericDecl>(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<AggTypeDecl>(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<BuiltinTypeModifier>()) return; - SemanticToken token = - _createSemanticToken(manager, declRef->loc, declRef->name); - auto target = declRef->declRef.getDecl(); - if (as<AggTypeDecl>(target)) - { - if (target->hasModifier<BuiltinTypeModifier>()) - return; - token.type = SemanticTokenType::Type; - } - else if (as<ConstructorDecl>(target)) - { - token.type = SemanticTokenType::Type; - token.length = doc->getTokenLength(token.line, token.col); - } - else if (as<SimpleTypeDecl>(target)) - { - token.type = SemanticTokenType::Type; - } - else if (as<PropertyDecl>(target)) - { - token.type = SemanticTokenType::Property; - } - else if (as<ParamDecl>(target)) - { - token.type = SemanticTokenType::Parameter; - } - else if (as<VarDecl>(target)) - { - if (as<MemberExpr>(declRef->originalExpr) || - as<StaticMemberExpr>(declRef->originalExpr)) - { - return; - } - token.type = SemanticTokenType::Variable; - } - else if (as<FunctionDeclBase>(target)) - { - token.type = SemanticTokenType::Function; - } - else if (as<EnumCaseDecl>(target)) - { - token.type = SemanticTokenType::EnumMember; - } - else if (as<NamespaceDecl>(target)) - { - token.type = SemanticTokenType::Namespace; - } - - if (as<CallableDecl>(target)) + token.type = SemanticTokenType::Type; + } + else if (as<ConstructorDecl>(target)) + { + token.type = SemanticTokenType::Type; + token.length = doc->getTokenLength(token.line, token.col); + } + else if (as<SimpleTypeDecl>(target)) + { + token.type = SemanticTokenType::Type; + } + else if (as<PropertyDecl>(target)) + { + token.type = SemanticTokenType::Property; + } + else if (as<ParamDecl>(target)) + { + token.type = SemanticTokenType::Parameter; + } + else if (as<VarDecl>(target)) + { + if (as<MemberExpr>(declRefExpr->originalExpr) || + as<StaticMemberExpr>(declRefExpr->originalExpr)) { - if (target->hasModifier<ImplicitConversionModifier>()) - return; + return; } - maybeInsertToken(token); + token.type = SemanticTokenType::Variable; + } + else if (as<FunctionDeclBase>(target)) + { + token.type = SemanticTokenType::Function; + } + else if (as<EnumCaseDecl>(target)) + { + token.type = SemanticTokenType::EnumMember; + } + else if (as<NamespaceDecl>(target)) + { + token.type = SemanticTokenType::Namespace; } + if (as<CallableDecl>(target)) + { + if (target->hasModifier<ImplicitConversionModifier>()) + return; + } + maybeInsertToken(token); } else if (auto accessorDecl = as<AccessorDecl>(node)) { |
