Skip to content

Commit

Permalink
LanguageServer: fix highlighting of wrapper type. (#5968)
Browse files Browse the repository at this point in the history
  • Loading branch information
csyonghe authored Dec 31, 2024
1 parent 3f43d6c commit 1f98bd6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
1 change: 1 addition & 0 deletions source/slang/slang-check-decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2133,6 +2133,7 @@ void SemanticsDeclHeaderVisitor::visitStructDecl(StructDecl* structDecl)
member->nameAndLoc.name = getName("inner");
member->nameAndLoc.loc = structDecl->wrappedType.exp->loc;
member->loc = member->nameAndLoc.loc;
addModifier(member, m_astBuilder->create<SynthesizedModifier>());
structDecl->addMember(member);
}
checkVisibility(structDecl);
Expand Down
7 changes: 7 additions & 0 deletions source/slang/slang-language-server-ast-lookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,13 @@ bool _findAstNodeImpl(ASTLookupContext& context, SyntaxNode* node)
{
if (_isLocInRange(&context, decl->nameAndLoc.loc, _getDeclNameLength(decl->getName())))
{
for (auto modifier : decl->modifiers)
{
if (as<SynthesizedModifier>(modifier))
return false;
if (as<ImplicitParameterGroupElementTypeModifier>(modifier))
return false;
}
ASTLookupResult result;
result.path = context.nodePath;
context.results.add(_Move(result));
Expand Down
34 changes: 22 additions & 12 deletions source/slang/slang-language-server-semantic-tokens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ List<SemanticToken> getSemanticTokens(
.pathInfo.foundPath.getUnownedSlice()
.endsWithCaseInsensitive(fileName))
return;
if (decl->hasModifier<SynthesizedModifier>())
return;
SemanticToken token = _createSemanticToken(manager, loc, name);
auto target = decl;
if (as<AggTypeDecl>(target))
Expand Down Expand Up @@ -137,6 +139,17 @@ List<SemanticToken> getSemanticTokens(
module->getModuleDecl(),
[&](SyntaxNode* node)
{
if (auto decl = as<Decl>(node))
{
for (auto modifier : decl->modifiers)
{
if (as<SynthesizedModifier>(modifier))
return;
if (as<ImplicitParameterGroupElementTypeModifier>(modifier))
return;
}
}

if (auto declRefExpr = as<DeclRefExpr>(node))
{
handleDeclRef(
Expand Down Expand Up @@ -173,19 +186,16 @@ List<SemanticToken> getSemanticTokens(
maybeInsertToken(token);
}
}
else if (auto aggTypeDecl = as<AggTypeDeclBase>(node))
else if (auto aggTypeDeclBase = as<AggTypeDeclBase>(node))
{
if (aggTypeDecl->getName() &&
aggTypeDecl->findModifier<ImplicitParameterGroupElementTypeModifier>() ==
nullptr)
{
SemanticToken token = _createSemanticToken(
manager,
aggTypeDecl->getNameLoc(),
aggTypeDecl->getName());
token.type = SemanticTokenType::Type;
maybeInsertToken(token);
}
if (!aggTypeDeclBase->getName())
return;
SemanticToken token = _createSemanticToken(
manager,
aggTypeDeclBase->getNameLoc(),
aggTypeDeclBase->getName());
token.type = SemanticTokenType::Type;
maybeInsertToken(token);
}
else if (auto enumCase = as<EnumCaseDecl>(node))
{
Expand Down

0 comments on commit 1f98bd6

Please sign in to comment.