Skip to content

Commit ac4e88f

Browse files
committed
lsp: deleting files, deletes its diagnostics
1 parent 553ec66 commit ac4e88f

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- lsp: fix jump to definition
66
- lsp: fix multiline block comments
77
- lsp: fix logging too many errors
8+
- lsp: deleting files, deletes its diagnostics
89
- fix: extern docs generation
910
- stdlib: new markup and markdown library
1011
- stdlib: better docs generation
File renamed without changes.

langsrv/handler-initialize.go

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import (
88

99
func initialize(context *glsp.Context, params *protocol.InitializeParams) (interface{}, error) {
1010
capabilities := handler.CreateServerCapabilities()
11+
capabilities.Workspace.FileOperations.DidDelete.Filters = []protocol.FileOperationFilter{
12+
{
13+
Pattern: protocol.FileOperationPattern{Glob: "**/*.lithia"},
14+
},
15+
}
1116
capabilities.CompletionProvider = &protocol.CompletionOptions{
1217
TriggerCharacters: []string{"."},
1318
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package langsrv
2+
3+
import (
4+
"github.com/tliron/glsp"
5+
protocol "github.com/tliron/glsp/protocol_3_16"
6+
)
7+
8+
func workspaceDidDeleteFiles(context *glsp.Context, params *protocol.DeleteFilesParams) error {
9+
for _, deleted := range params.Files {
10+
context.Notify(protocol.ServerTextDocumentPublishDiagnostics, protocol.PublishDiagnosticsParams{
11+
URI: deleted.URI,
12+
Version: nil,
13+
Diagnostics: []protocol.Diagnostic{},
14+
})
15+
delete(langserver.documentCache.documents, deleted.URI)
16+
}
17+
return nil
18+
}

langsrv/lang-server.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package langsrv
22

33
import (
4+
"github.com/tliron/glsp"
45
protocol "github.com/tliron/glsp/protocol_3_16"
56
"github.com/tliron/glsp/server"
67
"github.com/tliron/kutil/logging"
@@ -22,7 +23,7 @@ var langserver lithiaLangserver = lithiaLangserver{
2223
}
2324

2425
func init() {
25-
logging.Configure(1, nil)
26+
logging.Configure(2, nil)
2627

2728
handler = protocol.Handler{
2829
Initialize: initialize,
@@ -32,6 +33,9 @@ func init() {
3233

3334
TextDocumentDidOpen: textDocumentDidOpen,
3435
TextDocumentDidChange: textDocumentDidChange,
36+
TextDocumentDidClose: func(context *glsp.Context, params *protocol.DidCloseTextDocumentParams) error { return nil },
37+
38+
WorkspaceDidDeleteFiles: workspaceDidDeleteFiles,
3539

3640
TextDocumentHover: textDocumentHover,
3741
TextDocumentCompletion: textDocumentCompletion,

0 commit comments

Comments
 (0)