diff options
| author | Yong He <yonghe@outlook.com> | 2024-01-22 23:19:40 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-22 23:19:40 -0800 |
| commit | 5902acdabc4445a65741a7a6a3a95f223e301059 (patch) | |
| tree | 0c5418d7367725c8df81b3f591b6dd264355c5e3 | |
| parent | fec9c42d4c61d1bdd54d020d55a3155e0d54fce7 (diff) | |
[LSP] Fetch configs directly from didConfigurationChanged message. (#3478)
Co-authored-by: Yong He <yhe@nvidia.com>
| -rw-r--r-- | source/slang/slang-language-server.cpp | 83 | ||||
| -rw-r--r-- | source/slang/slang-language-server.h | 1 |
2 files changed, 77 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(); diff --git a/source/slang/slang-language-server.h b/source/slang/slang-language-server.h index b17991714..e244ad9f5 100644 --- a/source/slang/slang-language-server.h +++ b/source/slang/slang-language-server.h @@ -105,6 +105,7 @@ public: SlangResult init(const LanguageServerProtocol::InitializeParams& args); SlangResult execute(); void update(); + void updateConfigFromJSON(const JSONValue& jsonVal); SlangResult didOpenTextDocument(const LanguageServerProtocol::DidOpenTextDocumentParams& args); SlangResult didCloseTextDocument( const LanguageServerProtocol::DidCloseTextDocumentParams& args); |
