From 470c5a28f5b84353f077c2d871db65cddd5f923a Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 26 Jan 2024 16:30:19 -0800 Subject: Fix LSP compatibility issues with Visual Studio. (#3520) * [LSP] compatibility logic for Visual Studio. * [LSP] Fix diagnostic rank parsing. * [LSP] Fix semantic highlighting of cbuffer types. * Fix. * Fix. --------- Co-authored-by: Yong He --- source/slang/slang-parser.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'source/slang/slang-parser.cpp') diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index 909a8eb72..f0c9e175f 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -114,7 +114,7 @@ namespace Slang DiagnosticSink* sink; SourceLoc lastErrorLoc; ParserOptions options; - + Modifiers* pendingModifiers = nullptr; int genericDepth = 0; // Is the parser in a "recovering" state? @@ -3095,7 +3095,7 @@ namespace Slang } static Decl* ParseHLSLBufferDecl( - Parser* parser, + Parser* parser, String bufferWrapperTypeName) { // An HLSL declaration of a constant buffer like this: @@ -3119,7 +3119,19 @@ namespace Slang // the second is a variable declaration that uses the buffer type. StructDecl* bufferDataTypeDecl = parser->astBuilder->create(); - addModifier(bufferDataTypeDecl, parser->astBuilder->create()); + if (parser->pendingModifiers) + { + // Clone visibility modifier from cbuffer decl to the internal struct type decl. + // For example, if cbuffer is public, we want the element buffer type to also be + // public. + if (auto visModifier = parser->pendingModifiers->findModifier()) + { + auto cloneVisModifier = (VisibilityModifier*)parser->astBuilder->createByNodeType(visModifier->astNodeType); + cloneVisModifier->keywordName = visModifier->keywordName; + cloneVisModifier->loc = visModifier->loc; + addModifier(bufferDataTypeDecl, cloneVisModifier); + } + } VarDecl* bufferVarDecl = parser->astBuilder->create(); @@ -4396,6 +4408,18 @@ namespace Slang Modifiers modifiers ) { DeclBase* decl = nullptr; + + struct RestorePendingModifiersRAII + { + Modifiers* oldValue; + Parser* parser; + ~RestorePendingModifiersRAII() + { + parser->pendingModifiers = oldValue; + } + }; + RestorePendingModifiersRAII restorePendingModifiersRAII{ parser->pendingModifiers, parser }; + parser->pendingModifiers = &modifiers; auto loc = parser->tokenReader.peekLoc(); -- cgit v1.2.3