From 7e7d9ce142c3ef077743496cbf8cdc8f669a66af Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 13 Dec 2023 16:39:46 -0800 Subject: Polish language server and documentation. (#3410) Co-authored-by: Yong He --- .../slang-language-server-semantic-tokens.cpp | 147 +++++++++++---------- 1 file changed, 78 insertions(+), 69 deletions(-) (limited to 'source/slang/slang-language-server-semantic-tokens.cpp') diff --git a/source/slang/slang-language-server-semantic-tokens.cpp b/source/slang/slang-language-server-semantic-tokens.cpp index 8fb4b1303..837aad06c 100644 --- a/source/slang/slang-language-server-semantic-tokens.cpp +++ b/source/slang/slang-language-server-semantic-tokens.cpp @@ -48,6 +48,78 @@ List getSemanticTokens(Linkage* linkage, Module* module, UnownedS token.type != SemanticTokenType::NormalText) result.add(token); }; + auto handleDeclRef = [&](DeclRef declRef, Expr* originalExpr, SourceLoc 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)) + { + 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(originalExpr) || + as(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)) + { + if (target->hasModifier()) + return; + } + maybeInsertToken(token); + }; iterateAST( fileName, manager, @@ -56,77 +128,14 @@ List getSemanticTokens(Linkage* linkage, Module* module, UnownedS { if (auto declRefExpr = as(node)) { - 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)) - { - 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(declRefExpr->originalExpr) || - as(declRefExpr->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)) + handleDeclRef(declRefExpr->declRef, declRefExpr->originalExpr, declRefExpr->loc); + } + else if (auto overloadedExpr = as(node)) + { + if (overloadedExpr->lookupResult2.items.getCount()) { - if (target->hasModifier()) - return; + handleDeclRef(overloadedExpr->lookupResult2.items[0].declRef, overloadedExpr->originalExpr, overloadedExpr->loc); } - maybeInsertToken(token); } else if (auto accessorDecl = as(node)) { -- cgit v1.2.3