Skip to content

Commit 5902acd

Browse files
authored
[LSP] Fetch configs directly from didConfigurationChanged message. (shader-slang#3478)
Co-authored-by: Yong He <yhe@nvidia.com>
1 parent fec9c42 commit 5902acd

File tree

2 files changed

+77
-7
lines changed

2 files changed

+77
-7
lines changed

source/slang/slang-language-server.cpp

+76-7
Original file line numberDiff line numberDiff line change
@@ -1719,11 +1719,16 @@ void LanguageServer::updateFormattingOptions(const JSONValue& clangFormatLoc, co
17191719
{
17201720
auto container = m_connection->getContainer();
17211721
JSONToNativeConverter converter(container, &m_typeMap, m_connection->getSink());
1722-
converter.convert(clangFormatLoc, &m_formatOptions.clangFormatLocation);
1723-
converter.convert(clangFormatStyle, &m_formatOptions.style);
1724-
converter.convert(clangFormatFallbackStyle, &m_formatOptions.fallbackStyle);
1725-
converter.convert(allowLineBreakOnType, &m_formatOptions.allowLineBreakInOnTypeFormatting);
1726-
converter.convert(allowLineBreakInRange, &m_formatOptions.allowLineBreakInRangeFormatting);
1722+
if (clangFormatLoc.isValid())
1723+
converter.convert(clangFormatLoc, &m_formatOptions.clangFormatLocation);
1724+
if (clangFormatStyle.isValid())
1725+
converter.convert(clangFormatStyle, &m_formatOptions.style);
1726+
if (clangFormatFallbackStyle.isValid())
1727+
converter.convert(clangFormatFallbackStyle, &m_formatOptions.fallbackStyle);
1728+
if (allowLineBreakOnType.isValid())
1729+
converter.convert(allowLineBreakOnType, &m_formatOptions.allowLineBreakInOnTypeFormatting);
1730+
if (allowLineBreakInRange.isValid())
1731+
converter.convert(allowLineBreakInRange, &m_formatOptions.allowLineBreakInRangeFormatting);
17271732
if (m_formatOptions.style.getLength() == 0)
17281733
m_formatOptions.style = Slang::FormatOptions().style;
17291734
}
@@ -2176,8 +2181,14 @@ SlangResult LanguageServer::didChangeTextDocument(const DidChangeTextDocumentPar
21762181
SlangResult LanguageServer::didChangeConfiguration(
21772182
const LanguageServerProtocol::DidChangeConfigurationParams& args)
21782183
{
2179-
SLANG_UNUSED(args);
2180-
sendConfigRequest();
2184+
if (args.settings.isValid())
2185+
{
2186+
updateConfigFromJSON(args.settings);
2187+
}
2188+
else
2189+
{
2190+
sendConfigRequest();
2191+
}
21812192
return SLANG_OK;
21822193
}
21832194

@@ -2188,6 +2199,64 @@ void LanguageServer::update()
21882199
publishDiagnostics();
21892200
}
21902201

2202+
void LanguageServer::updateConfigFromJSON(const JSONValue& jsonVal)
2203+
{
2204+
if (!jsonVal.isObjectLike())
2205+
return;
2206+
auto obj = m_connection->getContainer()->getObject(jsonVal);
2207+
if (obj.getCount() == 1 &&
2208+
(m_connection->getContainer()->getStringFromKey(obj[0].key) == "settings"
2209+
|| m_connection->getContainer()->getStringFromKey(obj[0].key) == "RootElement"))
2210+
{
2211+
updateConfigFromJSON(obj[0].value);
2212+
return;
2213+
}
2214+
for (auto kv : obj)
2215+
{
2216+
auto key = m_connection->getContainer()->getStringFromKey(kv.key);
2217+
if (key == "slang.predefinedMacros")
2218+
{
2219+
updatePredefinedMacros(kv.value);
2220+
}
2221+
else if (key == "slang.additionalSearchPaths")
2222+
{
2223+
updateSearchPaths(kv.value);
2224+
}
2225+
else if (key == "slang.enableCommitCharactersInAutoCompletion")
2226+
{
2227+
updateCommitCharacters(kv.value);
2228+
}
2229+
else if (key == "slang.format.clangFormatLocation")
2230+
{
2231+
updateFormattingOptions(kv.value, JSONValue(), JSONValue(), JSONValue(), JSONValue());
2232+
}
2233+
else if (key == "slang.format.clangFormatStyle")
2234+
{
2235+
updateFormattingOptions(JSONValue(), kv.value, JSONValue(), JSONValue(), JSONValue());
2236+
}
2237+
else if (key == "slang.format.clangFormatFallbackStyle")
2238+
{
2239+
updateFormattingOptions(JSONValue(), JSONValue(), kv.value, JSONValue(), JSONValue());
2240+
}
2241+
else if (key == "slang.format.allowLineBreakChangesInOnTypeFormatting")
2242+
{
2243+
updateFormattingOptions(JSONValue(), JSONValue(), JSONValue(), kv.value, JSONValue());
2244+
}
2245+
else if (key == "slang.format.allowLineBreakChangesInRangeFormatting")
2246+
{
2247+
updateFormattingOptions(JSONValue(), JSONValue(), JSONValue(), JSONValue(), kv.value);
2248+
}
2249+
else if (key == "slang.inlayHints.deducedTypes")
2250+
{
2251+
updateInlayHintOptions(kv.value, JSONValue());
2252+
}
2253+
else if (key == "slang.inlayHints.parameterNames")
2254+
{
2255+
updateInlayHintOptions(JSONValue(), kv.value);
2256+
}
2257+
}
2258+
}
2259+
21912260
SlangResult LanguageServer::execute()
21922261
{
21932262
m_connection = new JSONRPCConnection();

source/slang/slang-language-server.h

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class LanguageServer
105105
SlangResult init(const LanguageServerProtocol::InitializeParams& args);
106106
SlangResult execute();
107107
void update();
108+
void updateConfigFromJSON(const JSONValue& jsonVal);
108109
SlangResult didOpenTextDocument(const LanguageServerProtocol::DidOpenTextDocumentParams& args);
109110
SlangResult didCloseTextDocument(
110111
const LanguageServerProtocol::DidCloseTextDocumentParams& args);

0 commit comments

Comments
 (0)