summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorHarsh Aggarwal (NVIDIA) <haaggarwal@nvidia.com>2025-07-02 09:53:42 +0530
committerGitHub <noreply@github.com>2025-07-02 04:23:42 +0000
commit35f00363d03afad74874b330f623bcd4caf115be (patch)
treecc62b6708c8b8183f616be041a8196f31d224bc0 /source
parent7ffb9f53e41c409a51c41318442067cc6c7e4f48 (diff)
Fix diagnostics not appearing when semantic tokens are disabled (#7477) (#7532)
* Fix diagnostics not appearing when semantic tokens are disabled (#7477) Previously, the language server only triggered module loading and compilation through semantic token requests. When semantic tokens were disabled, didOpenTextDocument and didChangeTextDocument would only update the workspace without compiling modules, meaning no diagnostics were generated. This change: - Adds module loading to didOpenTextDocument for .slang/.hlsl files - Adds module loading to didChangeTextDocument for .slang/.hlsl files - Triggers diagnostic updates via resetDiagnosticUpdateTime for Slang files - Ensures diagnostics appear immediately when opening/editing files - Maintains backward compatibility with existing LSP features Additionally fixes JSON serialization to properly handle NullResponse types by serializing them as JSON null instead of empty objects, improving LSP protocol compliance. Now diagnostics work correctly regardless of semantic token settings. * Revert: Remove unrelated change - will pick up in seprate PR * Fix module state corruption when checkAllTranslationUnits throws Add try/catch in Linkage::loadParsedModule to properly clean up module maps when checkAllTranslationUnits() fails with an exception. This prevents incorrect state in WorkspaceVersion::getOrLoadModule where failed modules remained in the loaded modules map, causing subsequent calls to return stale/invalid module references. * Update to address review comments * update: remove explicit checking for .slang and .hlsl
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-language-server.cpp16
-rw-r--r--source/slang/slang.cpp14
2 files changed, 28 insertions, 2 deletions
diff --git a/source/slang/slang-language-server.cpp b/source/slang/slang-language-server.cpp
index 3cc093ad7..d52c5d855 100644
--- a/source/slang/slang-language-server.cpp
+++ b/source/slang/slang-language-server.cpp
@@ -247,6 +247,14 @@ SlangResult LanguageServerCore::didOpenTextDocument(const DidOpenTextDocumentPar
{
String canonicalPath = uriToCanonicalPath(args.textDocument.uri);
m_workspace->openDoc(canonicalPath, args.textDocument.text);
+
+ auto version = m_workspace->getCurrentVersion();
+ Module* parsedModule = version->getOrLoadModule(canonicalPath);
+ if (!parsedModule)
+ {
+ return SLANG_FAIL;
+ }
+
return SLANG_OK;
}
@@ -2616,6 +2624,14 @@ SlangResult LanguageServerCore::didChangeTextDocument(const DidChangeTextDocumen
String canonicalPath = uriToCanonicalPath(args.textDocument.uri);
for (auto change : args.contentChanges)
m_workspace->changeDoc(canonicalPath, change.range, change.text);
+
+ auto version = m_workspace->getCurrentVersion();
+ Module* parsedModule = version->getOrLoadModule(canonicalPath);
+ if (!parsedModule)
+ {
+ return SLANG_FAIL;
+ }
+
return SLANG_OK;
}
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index e149058b1..e98187c85 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -4131,8 +4131,18 @@ void Linkage::loadParsedModule(
auto sink = translationUnit->compileRequest->getSink();
int errorCountBefore = sink->getErrorCount();
- compileRequest->checkAllTranslationUnits();
- int errorCountAfter = sink->getErrorCount();
+ int errorCountAfter;
+ try
+ {
+ compileRequest->checkAllTranslationUnits();
+ }
+ catch (...)
+ {
+ mapPathToLoadedModule.remove(mostUniqueIdentity);
+ mapNameToLoadedModules.remove(name);
+ throw;
+ }
+ errorCountAfter = sink->getErrorCount();
if (isInLanguageServer())
{
// Don't generate IR as language server.