88#include " CodeService/LuaCodeStyleOptions.h"
99#include " CodeService/LuaFormatter.h"
1010#include " CodeFormatServer/LanguageClient.h"
11+ #include " CodeFormatServer/Service/CodeActionService.h"
1112#include " CodeFormatServer/Service/CodeFormatService.h"
1213#include " CodeFormatServer/Service/CommandService.h"
1314#include " CodeFormatServer/Service/ModuleService.h"
@@ -42,6 +43,7 @@ bool LanguageService::Initialize()
4243 JsonProtocol (" workspace/executeCommand" , &LanguageService::OnExecuteCommand);
4344 JsonProtocol (" workspace/didChangeWatchedFiles" , &LanguageService::OnDidChangeWatchedFiles);
4445 JsonProtocol (" textDocument/completion" , &LanguageService::OnCompletion);
46+ JsonProtocol (" workspace/didChangeConfiguration" , &LanguageService::OnWorkspaceDidChangeConfiguration);
4547 return true ;
4648}
4749
@@ -140,7 +142,10 @@ std::shared_ptr<vscode::InitializeResult> LanguageService::OnInitialize(std::sha
140142 auto dictionaryPath = param->initializationOptions .dictionaryPath ;
141143 if (!dictionaryPath.empty ())
142144 {
143- LanguageClient::GetInstance ().GetService <CodeFormatService>()->LoadDictionary (dictionaryPath);
145+ for (auto & path : dictionaryPath)
146+ {
147+ LanguageClient::GetInstance ().GetService <CodeFormatService>()->LoadDictionary (path);
148+ }
144149 }
145150 return result;
146151}
@@ -344,58 +349,11 @@ std::shared_ptr<vscode::Serializable> LanguageService::OnTypeFormatting(
344349
345350std::shared_ptr<vscode::CodeActionResult> LanguageService::OnCodeAction (std::shared_ptr<vscode::CodeActionParams> param)
346351{
347- // TODO refactor move to CodeActionService
348- auto range = param->range ;
349- auto uri = param->textDocument .uri ;
350- auto filePath = url::UrlToFilePath (uri);
351352 auto codeActionResult = std::make_shared<vscode::CodeActionResult>();
352353
353354 for (auto & diagnostic : param->context .diagnostics )
354355 {
355- if (LanguageClient::GetInstance ().GetService <CodeFormatService>()->IsCodeFormatDiagnostic (diagnostic))
356- {
357- auto & action = codeActionResult->actions .emplace_back ();
358- std::string title = " reformat current line" ;
359- action.title = title;
360- action.command .title = title;
361- action.command .command = LanguageClient::GetInstance ().
362- GetService<CommandService>()->GetCommand (CommandService::Command::Reformat);
363- action.command .arguments .push_back (param->textDocument .uri );
364- action.command .arguments .push_back (param->range .Serialize ());
365-
366- action.kind = vscode::CodeActionKind::QuickFix;
367- }
368- else if (LanguageClient::GetInstance ().GetService <CodeFormatService>()->IsSpellDiagnostic (diagnostic))
369- {
370- LanguageClient::GetInstance ().GetService <CodeFormatService>()->MakeSpellActions (
371- codeActionResult, diagnostic, param->textDocument .uri );
372- }
373- else if (LanguageClient::GetInstance ().GetService <ModuleService>()->IsModuleDiagnostic (diagnostic))
374- {
375- auto modules = LanguageClient::GetInstance ().GetService <ModuleService>()->GetImportModules (filePath, range);
376- auto & action = codeActionResult->actions .emplace_back ();
377- std::string title = " import multi choice" ;
378- if (modules.size () == 1 )
379- {
380- title = Util::format (" import '{}'" , modules.front ().ModuleName );
381- }
382- action.title = title;
383- action.command .title = title;
384- action.command .command = LanguageClient::GetInstance ().
385- GetService<CommandService>()->GetCommand (CommandService::Command::Import);
386- action.command .arguments .push_back (param->textDocument .uri );
387- action.command .arguments .push_back (param->range .Serialize ());
388- for (auto & module : modules)
389- {
390- auto object = nlohmann::json::object ();
391- object[" moduleName" ] = module .ModuleName ;
392- object[" path" ] = module .FilePath ;
393- object[" name" ] = module .Name ;
394- action.command .arguments .push_back (object);
395- }
396-
397- action.kind = vscode::CodeActionKind::QuickFix;
398- }
356+ LanguageClient::GetInstance ().GetService <CodeActionService>()->Dispatch (diagnostic, param, codeActionResult);
399357 }
400358 return codeActionResult;
401359}
@@ -441,10 +399,10 @@ std::shared_ptr<vscode::CompletionList> LanguageService::OnCompletion(std::share
441399{
442400 auto list = std::make_shared<vscode::CompletionList>();
443401
444- if (!LanguageClient::GetInstance ().GetSettings ().autoImport )
445- {
446- return list;
447- }
402+ // if (!LanguageClient::GetInstance().GetSettings().autoImport)
403+ // {
404+ // return list;
405+ // }
448406
449407 auto uri = param->textDocument .uri ;
450408
@@ -458,3 +416,52 @@ std::shared_ptr<vscode::CompletionList> LanguageService::OnCompletion(std::share
458416
459417 return list;
460418}
419+
420+ std::shared_ptr<vscode::Serializable> LanguageService::OnWorkspaceDidChangeConfiguration (
421+ std::shared_ptr<vscode::DidChangeConfigurationParams> param)
422+ {
423+ vscode::VscodeSettings& setting = LanguageClient::GetInstance ().GetSettings ();
424+ // TODO more modern method
425+ if (param->settings [" emmylua" ].is_object ())
426+ {
427+ auto emmylua = param->settings [" emmylua" ];
428+ if (emmylua[" lint" ].is_object ())
429+ {
430+ auto lint = emmylua[" lint" ];
431+ if (lint[" moduleCheck" ].is_boolean ())
432+ {
433+ setting.lintModule = lint[" moduleCheck" ];
434+ }
435+ if (lint[" codeStyle" ].is_boolean ())
436+ {
437+ setting.lintCodeStyle = lint[" codeStyle" ];
438+ }
439+ }
440+
441+ if (emmylua[" spell" ].is_object ())
442+ {
443+ auto spell = emmylua[" spell" ];
444+ if (spell[" enable" ].is_boolean ())
445+ {
446+ setting.spellEnable = spell[" enable" ];
447+ }
448+
449+ if (spell[" dict" ].is_array ())
450+ {
451+ setting.spellDict .clear ();
452+ for (auto j : spell[" dict" ])
453+ {
454+ if (j.is_string ())
455+ {
456+ setting.spellDict .push_back (j);
457+ }
458+ }
459+ }
460+ }
461+ }
462+
463+
464+ LanguageClient::GetInstance ().SetVscodeSettings (setting);
465+
466+ return nullptr ;
467+ }
0 commit comments