summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-language-server.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-07-01 14:02:35 -0700
committerGitHub <noreply@github.com>2025-07-01 21:02:35 +0000
commiteb7f3357a1c316bad51cf0bfaea27d81a93f96ad (patch)
tree448a2a07d36ef11b66ef79522086765efc5e708b /source/slang/slang-language-server.cpp
parent5120c1cd072548654c9ce79fa85426a5e48736c4 (diff)
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.
Diffstat (limited to 'source/slang/slang-language-server.cpp')
-rw-r--r--source/slang/slang-language-server.cpp71
1 files changed, 61 insertions, 10 deletions
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<List<LanguageServerProtocol::TextEdit>> LanguageServerCore::rangeFormatting(
const LanguageServerProtocol::DocumentRangeFormattingParams& args)
{
+ if (!m_formatOptions.enableFormatOnType)
+ return std::nullopt;
+
String canonicalPath = uriToCanonicalPath(args.textDocument.uri);
RefPtr<DocumentVersion> doc;
if (!m_workspace->openedDocuments.tryGetValue(canonicalPath, doc))
@@ -1924,6 +1927,9 @@ SlangResult LanguageServer::onTypeFormatting(
LanguageServerResult<List<LanguageServerProtocol::TextEdit>> LanguageServerCore::onTypeFormatting(
const LanguageServerProtocol::DocumentOnTypeFormattingParams& args)
{
+ if (!m_formatOptions.enableFormatOnType)
+ return std::nullopt;
+
String canonicalPath = uriToCanonicalPath(args.textDocument.uri);
RefPtr<DocumentVersion> 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")
{