@@ -21,8 +21,9 @@ bool LanguageService::Initialize()
2121
2222 _handles[" initialize" ] = DynamicBind (OnInitialize, vscode::InitializeParams);
2323 _handles[" textDocument/didChange" ] = DynamicBind (OnDidChange, vscode::DidChangeTextDocumentParams);
24- _handles[" textDocument/didOpen" ] = DynamicBind (OnDidOpen, vscode::DidOpenTextDocumentParam );
24+ _handles[" textDocument/didOpen" ] = DynamicBind (OnDidOpen, vscode::DidOpenTextDocumentParams );
2525 _handles[" textDocument/formatting" ] = DynamicBind (OnFormatting, vscode::DocumentFormattingParams);
26+ _handles[" textDocument/didClose" ] = DynamicBind (OnClose, vscode::DidCloseTextDocumentParams);
2627 return true ;
2728}
2829
@@ -60,7 +61,7 @@ std::shared_ptr<vscode::Serializable> LanguageService::OnDidChange(
6061}
6162
6263std::shared_ptr<vscode::Serializable> LanguageService::OnDidOpen (
63- std::shared_ptr<vscode::DidOpenTextDocumentParam > param)
64+ std::shared_ptr<vscode::DidOpenTextDocumentParams > param)
6465{
6566 LanguageClient::GetInstance ().CacheFile (param->textDocument .uri , param->textDocument .text );
6667 LanguageClient::GetInstance ().DiagnosticFile (param->textDocument .uri );
@@ -88,6 +89,12 @@ std::shared_ptr<vscode::Serializable> LanguageService::OnFormatting(
8889 std::shared_ptr<LuaParser> parser = LuaParser::LoadFromBuffer (std::move (text));
8990 parser->BuildAstWithComment ();
9091
92+ if (parser->HasError ())
93+ {
94+ result->hasError = true ;
95+ return result;
96+ }
97+
9198 LuaFormatter formatter (parser, options);
9299 formatter.BuildFormattedElement ();
93100
@@ -99,3 +106,11 @@ std::shared_ptr<vscode::Serializable> LanguageService::OnFormatting(
99106 );
100107 return result;
101108}
109+
110+ std::shared_ptr<vscode::Serializable> LanguageService::OnClose (
111+ std::shared_ptr<vscode::DidCloseTextDocumentParams> param)
112+ {
113+ LanguageClient::GetInstance ().ReleaseFile (param->textDocument .uri );
114+
115+ return nullptr ;
116+ }
0 commit comments