From eb7f3357a1c316bad51cf0bfaea27d81a93f96ad Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 1 Jul 2025 14:02:35 -0700 Subject: Misc language server improvements. (#7569) * Misc language server improvements. * Fix. * Fix decl path printing for existential lookup. * More existential decl path fix. * Polish. * Fix test. --- source/slang/slang-language-server.cpp | 71 +++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 10 deletions(-) (limited to 'source/slang/slang-language-server.cpp') diff --git a/source/slang/slang-language-server.cpp b/source/slang/slang-language-server.cpp index 6daeb75ad..3cc093ad7 100644 --- a/source/slang/slang-language-server.cpp +++ b/source/slang/slang-language-server.cpp @@ -210,15 +210,15 @@ SlangResult LanguageServer::parseNextMessage() if (response.result.getKind() == JSONValue::Kind::Array) { auto arr = m_connection->getContainer()->getArray(response.result); - if (arr.getCount() == 12) + if (arr.getCount() == 13) { updatePredefinedMacros(arr[0]); updateSearchPaths(arr[1]); updateSearchInWorkspace(arr[2]); updateCommitCharacters(arr[3]); - updateFormattingOptions(arr[4], arr[5], arr[6], arr[7], arr[8]); - updateInlayHintOptions(arr[9], arr[10]); - updateTraceOptions(arr[11]); + updateFormattingOptions(arr[4], arr[5], arr[6], arr[7], arr[8], arr[9]); + updateInlayHintOptions(arr[10], arr[11]); + updateTraceOptions(arr[12]); } } break; @@ -1876,6 +1876,9 @@ SlangResult LanguageServer::rangeFormatting( LanguageServerResult> LanguageServerCore::rangeFormatting( const LanguageServerProtocol::DocumentRangeFormattingParams& args) { + if (!m_formatOptions.enableFormatOnType) + return std::nullopt; + String canonicalPath = uriToCanonicalPath(args.textDocument.uri); RefPtr doc; if (!m_workspace->openedDocuments.tryGetValue(canonicalPath, doc)) @@ -1924,6 +1927,9 @@ SlangResult LanguageServer::onTypeFormatting( LanguageServerResult> LanguageServerCore::onTypeFormatting( const LanguageServerProtocol::DocumentOnTypeFormattingParams& args) { + if (!m_formatOptions.enableFormatOnType) + return std::nullopt; + String canonicalPath = uriToCanonicalPath(args.textDocument.uri); RefPtr doc; if (!m_workspace->openedDocuments.tryGetValue(canonicalPath, doc)) @@ -2084,6 +2090,7 @@ void LanguageServer::updateCommitCharacters(const JSONValue& jsonValue) } void LanguageServer::updateFormattingOptions( + const JSONValue& enableFormatOnType, const JSONValue& clangFormatLoc, const JSONValue& clangFormatStyle, const JSONValue& clangFormatFallbackStyle, @@ -2092,6 +2099,8 @@ void LanguageServer::updateFormattingOptions( { auto container = m_connection->getContainer(); JSONToNativeConverter converter(container, &m_typeMap, m_connection->getSink()); + if (enableFormatOnType.isValid()) + converter.convert(enableFormatOnType, &m_core.m_formatOptions.enableFormatOnType); if (clangFormatLoc.isValid()) converter.convert(clangFormatLoc, &m_core.m_formatOptions.clangFormatLocation); if (clangFormatStyle.isValid()) @@ -2162,6 +2171,8 @@ void LanguageServer::sendConfigRequest() args.items.add(item); item.section = "slang.enableCommitCharactersInAutoCompletion"; args.items.add(item); + item.section = "slang.format.enableFormatOnType"; + args.items.add(item); item.section = "slang.format.clangFormatLocation"; args.items.add(item); item.section = "slang.format.clangFormatStyle"; @@ -2611,7 +2622,7 @@ SlangResult LanguageServerCore::didChangeTextDocument(const DidChangeTextDocumen SlangResult LanguageServer::didChangeConfiguration( const LanguageServerProtocol::DidChangeConfigurationParams& args) { - if (args.settings.isValid()) + if (args.settings.isValid() && args.settings.type != JSONValue::Type::Null) { updateConfigFromJSON(args.settings); } @@ -2657,25 +2668,65 @@ void LanguageServer::updateConfigFromJSON(const JSONValue& jsonVal) { updateCommitCharacters(kv.value); } + else if (key == "slang.format.enableFormatOnType") + { + updateFormattingOptions( + kv.value, + JSONValue(), + JSONValue(), + JSONValue(), + JSONValue(), + JSONValue()); + } else if (key == "slang.format.clangFormatLocation") { - updateFormattingOptions(kv.value, JSONValue(), JSONValue(), JSONValue(), JSONValue()); + updateFormattingOptions( + JSONValue(), + kv.value, + JSONValue(), + JSONValue(), + JSONValue(), + JSONValue()); } else if (key == "slang.format.clangFormatStyle") { - updateFormattingOptions(JSONValue(), kv.value, JSONValue(), JSONValue(), JSONValue()); + updateFormattingOptions( + JSONValue(), + JSONValue(), + kv.value, + JSONValue(), + JSONValue(), + JSONValue()); } else if (key == "slang.format.clangFormatFallbackStyle") { - updateFormattingOptions(JSONValue(), JSONValue(), kv.value, JSONValue(), JSONValue()); + updateFormattingOptions( + JSONValue(), + JSONValue(), + JSONValue(), + kv.value, + JSONValue(), + JSONValue()); } else if (key == "slang.format.allowLineBreakChangesInOnTypeFormatting") { - updateFormattingOptions(JSONValue(), JSONValue(), JSONValue(), kv.value, JSONValue()); + updateFormattingOptions( + JSONValue(), + JSONValue(), + JSONValue(), + JSONValue(), + kv.value, + JSONValue()); } else if (key == "slang.format.allowLineBreakChangesInRangeFormatting") { - updateFormattingOptions(JSONValue(), JSONValue(), JSONValue(), JSONValue(), kv.value); + updateFormattingOptions( + JSONValue(), + JSONValue(), + JSONValue(), + JSONValue(), + JSONValue(), + kv.value); } else if (key == "slang.inlayHints.deducedTypes") { -- cgit v1.2.3