summaryrefslogtreecommitdiff
path: root/source/slang/slang-check-modifier.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-06-22 19:58:34 -0700
committerGitHub <noreply@github.com>2022-06-22 19:58:34 -0700
commit07a380d72a13899a84cbdc35692be7a3d9246dcb (patch)
tree68e77f2e9682b3b7c3debd745604a494439e5b25 /source/slang/slang-check-modifier.cpp
parente5a75563a1ba2e378353af8b937b8b7bb0fe2c2b (diff)
More Language Server Improvements. (#2289)
Diffstat (limited to 'source/slang/slang-check-modifier.cpp')
-rw-r--r--source/slang/slang-check-modifier.cpp47
1 files changed, 46 insertions, 1 deletions
diff --git a/source/slang/slang-check-modifier.cpp b/source/slang/slang-check-modifier.cpp
index 429479a38..c6a33930b 100644
--- a/source/slang/slang-check-modifier.cpp
+++ b/source/slang/slang-check-modifier.cpp
@@ -78,6 +78,19 @@ namespace Slang
// Do nothing with modifiers for now
}
+ static bool _isDeclAllowedAsAttribute(DeclRef<Decl> declRef)
+ {
+ if (as<AttributeDecl>(declRef.getDecl()))
+ return true;
+ auto structDecl = as<StructDecl>(declRef.getDecl());
+ if (!structDecl)
+ return false;
+ auto attrUsageAttr = structDecl->findModifier<AttributeUsageAttribute>();
+ if (!attrUsageAttr)
+ return false;
+ return true;
+ }
+
AttributeDecl* SemanticsVisitor::lookUpAttributeDecl(Name* attributeName, Scope* scope)
{
if (!attributeName)
@@ -88,7 +101,29 @@ namespace Slang
{
// Look up the name and see what attributes we find.
//
- auto lookupResult = lookUp(m_astBuilder, this, attributeName, scope, LookupMask::Attribute);
+ LookupMask lookupMask = LookupMask::Attribute;
+ if (attributeName == getSession()->getCompletionRequestTokenName())
+ {
+ lookupMask =
+ LookupMask((uint32_t)LookupMask::Attribute | (uint32_t)LookupMask::type);
+ }
+
+ auto lookupResult = lookUp(m_astBuilder, this, attributeName, scope, lookupMask);
+
+ if (attributeName == getSession()->getCompletionRequestTokenName())
+ {
+ // If this is a completion request, add the lookup result to linkage.
+ auto& suggestions = getLinkage()->contentAssistInfo.completionSuggestions;
+ suggestions.clear();
+ suggestions.scopeKind = CompletionSuggestions::ScopeKind::Attribute;
+ for (auto& item : lookupResult)
+ {
+ if (_isDeclAllowedAsAttribute(item.declRef))
+ {
+ suggestions.candidateItems.add(item);
+ }
+ }
+ }
// If the result was overloaded, then that means there
// are multiple attributes matching the name, and we
@@ -709,6 +744,16 @@ namespace Slang
return checkAttribute(hlslUncheckedAttribute, syntaxNode);
}
+
+ if (auto hlslSemantic = as<HLSLSimpleSemantic>(m))
+ {
+ if (hlslSemantic->name.getName() == getSession()->getCompletionRequestTokenName())
+ {
+ getLinkage()->contentAssistInfo.completionSuggestions.scopeKind =
+ CompletionSuggestions::ScopeKind::HLSLSemantics;
+ }
+ }
+
// Default behavior is to leave things as they are,
// and assume that modifiers are mostly already checked.
//