From 0c64995ea28febcc7d38e1519da8d93391ce2e7d Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 7 Jun 2022 14:10:49 -0700 Subject: Major language server features. (#2264) * Major language server features. * Include slangd in binary release. * Fix compiler issues. * Fix compiler error. * Completion resolve. * Various improvements. * Update diagnostic test expected output. * Bug fix for source locations. * Adjust diagnostic update frequency. * Update github actions to store artifacts. * Fix infinite parser loop. * Fix parser recovery. * Fix parser recovery. * Update test. * Fix test. * Disable IR gen for language server. * Allow commit characters in auto completion. * Fix lookup for invoke exprs. * More parser robustness fixes. * update solution file Co-authored-by: Yong He --- source/slang/slang-ast-print.cpp | 128 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 126 insertions(+), 2 deletions(-) (limited to 'source/slang/slang-ast-print.cpp') diff --git a/source/slang/slang-ast-print.cpp b/source/slang/slang-ast-print.cpp index 3ffb481c6..3608e44f1 100644 --- a/source/slang/slang-ast-print.cpp +++ b/source/slang/slang-ast-print.cpp @@ -26,6 +26,40 @@ ASTPrinter::Part::Kind ASTPrinter::Part::getKind(ASTPrinter::Part::Type type) void ASTPrinter::addType(Type* type) { + if (!type) + { + m_builder << ""; + return; + } + if (m_optionFlags & OptionFlag::SimplifiedBuiltinType) + { + if (auto vectorType = as(type)) + { + if (as(vectorType->elementType)) + { + vectorType->elementType->toText(m_builder); + if (as(vectorType->elementCount)) + { + m_builder << vectorType->elementCount; + return; + } + } + } + else if (auto matrixType = as(type)) + { + auto elementType = matrixType->getElementType(); + if (as(elementType)) + { + matrixType->getElementType()->toText(m_builder); + if (as(matrixType->getRowCount()) && + as(matrixType->getColumnCount())) + { + m_builder << matrixType->getRowCount() << "x" << matrixType->getColumnCount(); + return; + } + } + } + } type->toText(m_builder); } @@ -223,7 +257,7 @@ void ASTPrinter::addGenericParams(const DeclRef& genericDeclRef) sb << ">"; } -void ASTPrinter::addDeclParams(const DeclRef& declRef) +void ASTPrinter::addDeclParams(const DeclRef& declRef, List>* outParamRange) { auto& sb = m_builder; @@ -237,6 +271,8 @@ void ASTPrinter::addDeclParams(const DeclRef& declRef) { if (!first) sb << ", "; + auto rangeStart = sb.getLength(); + ParamDecl* paramDecl = paramDeclRef; { @@ -278,6 +314,11 @@ void ASTPrinter::addDeclParams(const DeclRef& declRef) } } + auto rangeEnd = sb.getLength(); + + if (outParamRange) + outParamRange->add(makeArray(rangeStart, rangeEnd)); + first = false; } @@ -287,7 +328,7 @@ void ASTPrinter::addDeclParams(const DeclRef& declRef) { addGenericParams(genericDeclRef); - addDeclParams(DeclRef(getInner(genericDeclRef), genericDeclRef.substitutions)); + addDeclParams(DeclRef(getInner(genericDeclRef), genericDeclRef.substitutions), outParamRange); } else { @@ -300,10 +341,85 @@ void ASTPrinter::addDeclKindPrefix(Decl* decl) { decl = genericDecl->inner; } + for (auto modifier : decl->modifiers) + { + if (modifier->getKeywordName()) + { + if (m_optionFlags & OptionFlag::NoInternalKeywords) + { + if (as(modifier)) + continue; + if (as(modifier)) + continue; + if (as(modifier)) + continue; + if (as(modifier)) + continue; + if (as(modifier)) + continue; + if (as(modifier)) + continue; + } + m_builder << modifier->getKeywordName()->text << " "; + } + } if (as(decl)) { m_builder << "func "; } + else if (as(decl)) + { + m_builder << "struct "; + } + else if (as(decl)) + { + m_builder << "interface "; + } + else if (as(decl)) + { + m_builder << "class "; + } + else if (auto typedefDecl = as(decl)) + { + m_builder << "typedef "; + if (typedefDecl->type.type) + { + addType(typedefDecl->type.type); + m_builder << " "; + } + } + else if (auto propertyDecl = as(decl)) + { + m_builder << "property "; + } + else if (as(decl)) + { + m_builder << "namespace "; + } + else if (auto varDecl = as(decl)) + { + if (varDecl->getType()) + { + addType(varDecl->getType()); + m_builder << " "; + } + } + else if (as(decl)) + { + m_builder << "enum "; + } + else if (auto enumCase = as(decl)) + { + if (enumCase->getType()) + { + addType(enumCase->getType()); + m_builder << " "; + } + } + else if (auto assocType = as(decl)) + { + m_builder << "associatedtype "; + } } void ASTPrinter::addDeclResultType(const DeclRef& inDeclRef) @@ -326,6 +442,14 @@ void ASTPrinter::addDeclResultType(const DeclRef& inDeclRef) addType(getResultType(m_astBuilder, callableDeclRef)); } } + else if (auto propertyDecl = declRef.as()) + { + if (propertyDecl.getDecl()->type.type) + { + m_builder << " : "; + addType(declRef.substitute(m_astBuilder, propertyDecl.getDecl()->type.type)); + } + } } /* static */void ASTPrinter::addDeclSignature(const DeclRef& declRef) -- cgit v1.2.3