@@ -4,18 +4,19 @@ use log::info;
44use lsp_server:: { Connection , Message , Notification , Response } ;
55use lsp_types:: {
66 CodeDescription , Diagnostic , DiagnosticSeverity , DidChangeTextDocumentParams ,
7- DidOpenTextDocumentParams , GotoDefinitionParams , GotoDefinitionResponse , InitializeParams ,
8- Location , OneOf , Position , PublishDiagnosticsParams , Range , ServerCapabilities ,
9- TextDocumentSyncCapability , TextDocumentSyncKind , Url ,
7+ DidCloseTextDocumentParams , DidOpenTextDocumentParams , GotoDefinitionParams ,
8+ GotoDefinitionResponse , InitializeParams , Location , OneOf , Position , PublishDiagnosticsParams ,
9+ Range , ServerCapabilities , TextDocumentSyncCapability , TextDocumentSyncKind , Url ,
1010 notification:: {
11- DidChangeTextDocument , DidOpenTextDocument , Notification as _, PublishDiagnostics ,
11+ DidChangeTextDocument , DidCloseTextDocument , DidOpenTextDocument , Notification as _,
12+ PublishDiagnostics ,
1213 } ,
1314 request:: { GotoDefinition , Request } ,
1415} ;
1516use squawk_linter:: Linter ;
1617use squawk_syntax:: { Parse , SourceFile } ;
1718
18- pub fn run_server ( ) -> Result < ( ) > {
19+ pub fn run ( ) -> Result < ( ) > {
1920 info ! ( "Starting Squawk LSP server" ) ;
2021
2122 let ( connection, io_threads) = Connection :: stdio ( ) ;
@@ -74,6 +75,8 @@ fn main_loop(connection: Connection, params: serde_json::Value) -> Result<()> {
7475 handle_did_open ( & connection, notif) ?;
7576 } else if notif. method == DidChangeTextDocument :: METHOD {
7677 handle_did_change ( & connection, notif) ?;
78+ } else if notif. method == DidCloseTextDocument :: METHOD {
79+ handle_did_close ( & connection, notif) ?;
7780 }
7881 }
7982 }
@@ -126,6 +129,28 @@ fn handle_did_change(connection: &Connection, notif: lsp_server::Notification) -
126129 Ok ( ( ) )
127130}
128131
132+ fn handle_did_close ( connection : & Connection , notif : lsp_server:: Notification ) -> Result < ( ) > {
133+ let params: DidCloseTextDocumentParams = serde_json:: from_value ( notif. params ) ?;
134+ let uri = params. text_document . uri ;
135+
136+ let publish_params = PublishDiagnosticsParams {
137+ uri,
138+ diagnostics : vec ! [ ] ,
139+ version : None ,
140+ } ;
141+
142+ let notification = Notification {
143+ method : PublishDiagnostics :: METHOD . to_owned ( ) ,
144+ params : serde_json:: to_value ( publish_params) ?,
145+ } ;
146+
147+ connection
148+ . sender
149+ . send ( Message :: Notification ( notification) ) ?;
150+
151+ Ok ( ( ) )
152+ }
153+
129154fn lint ( connection : & Connection , uri : lsp_types:: Url , content : & str , version : i32 ) -> Result < ( ) > {
130155 let parse: Parse < SourceFile > = SourceFile :: parse ( content) ;
131156 let parse_errors = parse. errors ( ) ;
0 commit comments