11#include " CodeFormatServer/LanguageService.h"
22#include " CodeFormatServer/VSCode.h"
3- #include " CodeService/LuaFormatOptions .h"
3+ #include " CodeService/LuaCodeStyleOptions .h"
44#include " CodeService/LuaFormatter.h"
55#include " CodeFormatServer/LanguageClient.h"
66
@@ -24,6 +24,7 @@ bool LanguageService::Initialize()
2424 _handles[" textDocument/didOpen" ] = DynamicBind (OnDidOpen, vscode::DidOpenTextDocumentParams);
2525 _handles[" textDocument/formatting" ] = DynamicBind (OnFormatting, vscode::DocumentFormattingParams);
2626 _handles[" textDocument/didClose" ] = DynamicBind (OnClose, vscode::DidCloseTextDocumentParams);
27+ _handles[" updateEditorConfig" ] = DynamicBind (OnEditorConfigUpdate, vscode::EditorConfigUpdateParams);
2728 return true ;
2829}
2930
@@ -45,6 +46,13 @@ std::shared_ptr<vscode::InitializeResult> LanguageService::OnInitialize(std::sha
4546 result->capabilities .documentFormattingProvider = true ;
4647 result->capabilities .textDocumentSync .change = vscode::TextDocumentSyncKind::Full;
4748 result->capabilities .textDocumentSync .openClose = true ;
49+
50+ auto & configFiles = param->initializationOptions .configFiles ;
51+ for (auto & configFile : configFiles)
52+ {
53+ LanguageClient::GetInstance ().UpdateOptions (configFile.workspace , configFile.path );
54+ }
55+
4856 return result;
4957}
5058
@@ -84,18 +92,18 @@ std::shared_ptr<vscode::Serializable> LanguageService::OnFormatting(
8492 return result;
8593 }
8694
87- auto & options = LanguageClient::GetInstance ().GetOptions ();
95+ auto options = LanguageClient::GetInstance ().GetOptions (param-> textDocument . uri );
8896
8997 std::shared_ptr<LuaParser> parser = LuaParser::LoadFromBuffer (std::move (text));
9098 parser->BuildAstWithComment ();
9199
92- if (parser->HasError ())
100+ if (parser->HasError ())
93101 {
94102 result->hasError = true ;
95103 return result;
96104 }
97105
98- LuaFormatter formatter (parser, options);
106+ LuaFormatter formatter (parser, * options);
99107 formatter.BuildFormattedElement ();
100108
101109 auto & edit = result->edits .emplace_back ();
@@ -113,4 +121,25 @@ std::shared_ptr<vscode::Serializable> LanguageService::OnClose(
113121 LanguageClient::GetInstance ().ReleaseFile (param->textDocument .uri );
114122
115123 return nullptr ;
116- }
124+ }
125+
126+ std::shared_ptr<vscode::Serializable> LanguageService::OnEditorConfigUpdate (
127+ std::shared_ptr<vscode::EditorConfigUpdateParams> param)
128+ {
129+ switch (param->type )
130+ {
131+ case vscode::EditorConfigUpdateType::Created:
132+ case vscode::EditorConfigUpdateType::Changed:
133+ {
134+ LanguageClient::GetInstance ().UpdateOptions (param->source .workspace , param->source .path );
135+ break ;
136+ }
137+ case vscode::EditorConfigUpdateType::Delete:
138+ {
139+ LanguageClient::GetInstance ().RemoveOptions (param->source .workspace );
140+ break ;
141+ }
142+ }
143+
144+ return nullptr ;
145+ }
0 commit comments