summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-language-server.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-01-22 23:19:40 -0800
committerGitHub <noreply@github.com>2024-01-22 23:19:40 -0800
commit5902acdabc4445a65741a7a6a3a95f223e301059 (patch)
tree0c5418d7367725c8df81b3f591b6dd264355c5e3 /source/slang/slang-language-server.cpp
parentfec9c42d4c61d1bdd54d020d55a3155e0d54fce7 (diff)
[LSP] Fetch configs directly from didConfigurationChanged message. (#3478)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-language-server.cpp')
-rw-r--r--source/slang/slang-language-server.cpp83
1 files changed, 76 insertions, 7 deletions
diff --git a/source/slang/slang-language-server.cpp b/source/slang/slang-language-server.cpp
index 2c24ba6e5..f974dbb85 100644
--- a/source/slang/slang-language-server.cpp
+++ b/source/slang/slang-language-server.cpp
@@ -1719,11 +1719,16 @@ void LanguageServer::updateFormattingOptions(const JSONValue& clangFormatLoc, co
{
auto container = m_connection->getContainer();
JSONToNativeConverter converter(container, &m_typeMap, m_connection->getSink());
- converter.convert(clangFormatLoc, &m_formatOptions.clangFormatLocation);
- converter.convert(clangFormatStyle, &m_formatOptions.style);
- converter.convert(clangFormatFallbackStyle, &m_formatOptions.fallbackStyle);
- converter.convert(allowLineBreakOnType, &m_formatOptions.allowLineBreakInOnTypeFormatting);
- converter.convert(allowLineBreakInRange, &m_formatOptions.allowLineBreakInRangeFormatting);
+ if (clangFormatLoc.isValid())
+ converter.convert(clangFormatLoc, &m_formatOptions.clangFormatLocation);
+ if (clangFormatStyle.isValid())
+ converter.convert(clangFormatStyle, &m_formatOptions.style);
+ if (clangFormatFallbackStyle.isValid())
+ converter.convert(clangFormatFallbackStyle, &m_formatOptions.fallbackStyle);
+ if (allowLineBreakOnType.isValid())
+ converter.convert(allowLineBreakOnType, &m_formatOptions.allowLineBreakInOnTypeFormatting);
+ if (allowLineBreakInRange.isValid())
+ converter.convert(allowLineBreakInRange, &m_formatOptions.allowLineBreakInRangeFormatting);
if (m_formatOptions.style.getLength() == 0)
m_formatOptions.style = Slang::FormatOptions().style;
}
@@ -2176,8 +2181,14 @@ SlangResult LanguageServer::didChangeTextDocument(const DidChangeTextDocumentPar
SlangResult LanguageServer::didChangeConfiguration(
const LanguageServerProtocol::DidChangeConfigurationParams& args)
{
- SLANG_UNUSED(args);
- sendConfigRequest();
+ if (args.settings.isValid())
+ {
+ updateConfigFromJSON(args.settings);
+ }
+ else
+ {
+ sendConfigRequest();
+ }
return SLANG_OK;
}
@@ -2188,6 +2199,64 @@ void LanguageServer::update()
publishDiagnostics();
}
+void LanguageServer::updateConfigFromJSON(const JSONValue& jsonVal)
+{
+ if (!jsonVal.isObjectLike())
+ return;
+ auto obj = m_connection->getContainer()->getObject(jsonVal);
+ if (obj.getCount() == 1 &&
+ (m_connection->getContainer()->getStringFromKey(obj[0].key) == "settings"
+ || m_connection->getContainer()->getStringFromKey(obj[0].key) == "RootElement"))
+ {
+ updateConfigFromJSON(obj[0].value);
+ return;
+ }
+ for (auto kv : obj)
+ {
+ auto key = m_connection->getContainer()->getStringFromKey(kv.key);
+ if (key == "slang.predefinedMacros")
+ {
+ updatePredefinedMacros(kv.value);
+ }
+ else if (key == "slang.additionalSearchPaths")
+ {
+ updateSearchPaths(kv.value);
+ }
+ else if (key == "slang.enableCommitCharactersInAutoCompletion")
+ {
+ updateCommitCharacters(kv.value);
+ }
+ else if (key == "slang.format.clangFormatLocation")
+ {
+ updateFormattingOptions(kv.value, JSONValue(), JSONValue(), JSONValue(), JSONValue());
+ }
+ else if (key == "slang.format.clangFormatStyle")
+ {
+ updateFormattingOptions(JSONValue(), kv.value, JSONValue(), JSONValue(), JSONValue());
+ }
+ else if (key == "slang.format.clangFormatFallbackStyle")
+ {
+ updateFormattingOptions(JSONValue(), JSONValue(), kv.value, JSONValue(), JSONValue());
+ }
+ else if (key == "slang.format.allowLineBreakChangesInOnTypeFormatting")
+ {
+ updateFormattingOptions(JSONValue(), JSONValue(), JSONValue(), kv.value, JSONValue());
+ }
+ else if (key == "slang.format.allowLineBreakChangesInRangeFormatting")
+ {
+ updateFormattingOptions(JSONValue(), JSONValue(), JSONValue(), JSONValue(), kv.value);
+ }
+ else if (key == "slang.inlayHints.deducedTypes")
+ {
+ updateInlayHintOptions(kv.value, JSONValue());
+ }
+ else if (key == "slang.inlayHints.parameterNames")
+ {
+ updateInlayHintOptions(JSONValue(), kv.value);
+ }
+ }
+}
+
SlangResult LanguageServer::execute()
{
m_connection = new JSONRPCConnection();