summaryrefslogtreecommitdiffstats
path: root/source/slang
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-12-13 16:39:46 -0800
committerGitHub <noreply@github.com>2023-12-13 16:39:46 -0800
commit7e7d9ce142c3ef077743496cbf8cdc8f669a66af (patch)
treecabcc19ab27e638877d5d12080377f50f01e6f1a /source/slang
parent3979660d4fe1fd6c1f1d9b8956e96817e17c3f4e (diff)
Polish language server and documentation. (#3410)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang')
-rw-r--r--source/slang/slang-ast-expr.h2
-rw-r--r--source/slang/slang-ast-iterator.h1
-rw-r--r--source/slang/slang-check-expr.cpp1
-rw-r--r--source/slang/slang-language-server-ast-lookup.cpp9
-rw-r--r--source/slang/slang-language-server-semantic-tokens.cpp147
-rw-r--r--source/slang/slang-parser.cpp1
6 files changed, 90 insertions, 71 deletions
diff --git a/source/slang/slang-ast-expr.h b/source/slang/slang-ast-expr.h
index 88293a812..23c721038 100644
--- a/source/slang/slang-ast-expr.h
+++ b/source/slang/slang-ast-expr.h
@@ -53,6 +53,8 @@ class OverloadedExpr : public Expr
// arose from a member-reference expression.
Expr* base = nullptr;
+ Expr* originalExpr = nullptr;
+
// The lookup result that was ambiguous
LookupResult lookupResult2;
};
diff --git a/source/slang/slang-ast-iterator.h b/source/slang/slang-ast-iterator.h
index 7dc358a8e..2e8f02697 100644
--- a/source/slang/slang-ast-iterator.h
+++ b/source/slang/slang-ast-iterator.h
@@ -150,6 +150,7 @@ struct ASTIterator
{
iterator->maybeDispatchCallback(expr);
dispatchIfNotNull(expr->base);
+ dispatchIfNotNull(expr->originalExpr);
}
void visitOverloadedExpr2(OverloadedExpr2* expr)
{
diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp
index 753f14768..59f7f2aa1 100644
--- a/source/slang/slang-check-expr.cpp
+++ b/source/slang/slang-check-expr.cpp
@@ -814,6 +814,7 @@ namespace Slang
m_astBuilder->getOverloadedType());
overloadedExpr->base = baseExpr;
overloadedExpr->lookupResult2 = lookupResult;
+ overloadedExpr->originalExpr = originalExpr;
return overloadedExpr;
}
else
diff --git a/source/slang/slang-language-server-ast-lookup.cpp b/source/slang/slang-language-server-ast-lookup.cpp
index 0e8520f3a..3da4f8554 100644
--- a/source/slang/slang-language-server-ast-lookup.cpp
+++ b/source/slang/slang-language-server-ast-lookup.cpp
@@ -187,7 +187,7 @@ public:
declLength = _getDeclNameLength(expr->name, expr->declRef.getDecl());
}
if (_isLocInRange(
- context, expr->loc, declLength))
+ context, expr->loc, declLength))
{
ASTLookupResult result;
result.path = context->nodePath;
@@ -196,7 +196,7 @@ public:
return true;
}
}
-
+
return dispatchIfNotNull(expr->originalExpr);
}
@@ -242,6 +242,11 @@ public:
if (dispatchIfNotNull(expr->base))
return true;
}
+ {
+ PushNode pushNode(context, expr);
+ if (dispatchIfNotNull(expr->originalExpr))
+ return true;
+ }
if (expr->lookupResult2.getName() &&
_isLocInRange(
context,
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<SemanticToken> getSemanticTokens(Linkage* linkage, Module* module, UnownedS
token.type != SemanticTokenType::NormalText)
result.add(token);
};
+ auto handleDeclRef = [&](DeclRef<Decl> declRef, Expr* originalExpr, SourceLoc 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))
+ {
+ 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>(originalExpr) ||
+ as<StaticMemberExpr>(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))
+ {
+ if (target->hasModifier<ImplicitConversionModifier>())
+ return;
+ }
+ maybeInsertToken(token);
+ };
iterateAST(
fileName,
manager,
@@ -56,77 +128,14 @@ List<SemanticToken> getSemanticTokens(Linkage* linkage, Module* module, UnownedS
{
if (auto declRefExpr = as<DeclRefExpr>(node))
{
- 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))
- {
- 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>(declRefExpr->originalExpr) ||
- as<StaticMemberExpr>(declRefExpr->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))
+ handleDeclRef(declRefExpr->declRef, declRefExpr->originalExpr, declRefExpr->loc);
+ }
+ else if (auto overloadedExpr = as<OverloadedExpr>(node))
+ {
+ if (overloadedExpr->lookupResult2.items.getCount())
{
- if (target->hasModifier<ImplicitConversionModifier>())
- return;
+ handleDeclRef(overloadedExpr->lookupResult2.items[0].declRef, overloadedExpr->originalExpr, overloadedExpr->loc);
}
- maybeInsertToken(token);
}
else if (auto accessorDecl = as<AccessorDecl>(node))
{
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp
index 361786b6f..1a7845a25 100644
--- a/source/slang/slang-parser.cpp
+++ b/source/slang/slang-parser.cpp
@@ -3374,6 +3374,7 @@ namespace Slang
{
namespaceDecl = parser->astBuilder->create<NamespaceDecl>();
namespaceDecl->nameAndLoc = nameAndLoc;
+ namespaceDecl->loc = nameAndLoc.loc;
}
}
if (!result)