@@ -1719,11 +1719,16 @@ void LanguageServer::updateFormattingOptions(const JSONValue& clangFormatLoc, co
1719
1719
{
1720
1720
auto container = m_connection->getContainer ();
1721
1721
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 );
1727
1732
if (m_formatOptions.style .getLength () == 0 )
1728
1733
m_formatOptions.style = Slang::FormatOptions ().style ;
1729
1734
}
@@ -2176,8 +2181,14 @@ SlangResult LanguageServer::didChangeTextDocument(const DidChangeTextDocumentPar
2176
2181
SlangResult LanguageServer::didChangeConfiguration (
2177
2182
const LanguageServerProtocol::DidChangeConfigurationParams& args)
2178
2183
{
2179
- SLANG_UNUSED (args);
2180
- sendConfigRequest ();
2184
+ if (args.settings .isValid ())
2185
+ {
2186
+ updateConfigFromJSON (args.settings );
2187
+ }
2188
+ else
2189
+ {
2190
+ sendConfigRequest ();
2191
+ }
2181
2192
return SLANG_OK;
2182
2193
}
2183
2194
@@ -2188,6 +2199,64 @@ void LanguageServer::update()
2188
2199
publishDiagnostics ();
2189
2200
}
2190
2201
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
+
2191
2260
SlangResult LanguageServer::execute ()
2192
2261
{
2193
2262
m_connection = new JSONRPCConnection ();
0 commit comments