Skip to content

Commit

Permalink
lsp: deleting files, deletes its diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
vknabel committed Feb 11, 2022
1 parent 553ec66 commit ac4e88f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- lsp: fix jump to definition
- lsp: fix multiline block comments
- lsp: fix logging too many errors
- lsp: deleting files, deletes its diagnostics
- fix: extern docs generation
- stdlib: new markup and markdown library
- stdlib: better docs generation
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions langsrv/handler-initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import (

func initialize(context *glsp.Context, params *protocol.InitializeParams) (interface{}, error) {
capabilities := handler.CreateServerCapabilities()
capabilities.Workspace.FileOperations.DidDelete.Filters = []protocol.FileOperationFilter{
{
Pattern: protocol.FileOperationPattern{Glob: "**/*.lithia"},
},
}
capabilities.CompletionProvider = &protocol.CompletionOptions{
TriggerCharacters: []string{"."},
}
Expand Down
18 changes: 18 additions & 0 deletions langsrv/handler-workspace-did-delete-files.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package langsrv

import (
"github.com/tliron/glsp"
protocol "github.com/tliron/glsp/protocol_3_16"
)

func workspaceDidDeleteFiles(context *glsp.Context, params *protocol.DeleteFilesParams) error {
for _, deleted := range params.Files {
context.Notify(protocol.ServerTextDocumentPublishDiagnostics, protocol.PublishDiagnosticsParams{
URI: deleted.URI,
Version: nil,
Diagnostics: []protocol.Diagnostic{},
})
delete(langserver.documentCache.documents, deleted.URI)
}
return nil
}
6 changes: 5 additions & 1 deletion langsrv/lang-server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package langsrv

import (
"github.com/tliron/glsp"
protocol "github.com/tliron/glsp/protocol_3_16"
"github.com/tliron/glsp/server"
"github.com/tliron/kutil/logging"
Expand All @@ -22,7 +23,7 @@ var langserver lithiaLangserver = lithiaLangserver{
}

func init() {
logging.Configure(1, nil)
logging.Configure(2, nil)

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

TextDocumentDidOpen: textDocumentDidOpen,
TextDocumentDidChange: textDocumentDidChange,
TextDocumentDidClose: func(context *glsp.Context, params *protocol.DidCloseTextDocumentParams) error { return nil },

WorkspaceDidDeleteFiles: workspaceDidDeleteFiles,

TextDocumentHover: textDocumentHover,
TextDocumentCompletion: textDocumentCompletion,
Expand Down

0 comments on commit ac4e88f

Please sign in to comment.