-
Notifications
You must be signed in to change notification settings - Fork 349
/
workspace_did_change_watched_files.go
49 lines (41 loc) · 1.14 KB
/
workspace_did_change_watched_files.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package langserver
import (
"context"
"fmt"
"log"
lsp "github.com/sourcegraph/go-lsp"
"github.com/sourcegraph/jsonrpc2"
"github.com/spf13/afero"
"github.com/terraform-linters/tflint/tflint"
)
func (h *handler) workspaceDidChangeWatchedFiles(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
if h.rootDir == "" {
return nil, fmt.Errorf("root directory is undefined")
}
newConfig, err := tflint.LoadConfig(afero.Afero{Fs: afero.NewOsFs()}, h.configPath)
if err != nil {
return nil, err
}
newConfig.Merge(h.cliConfig)
h.config = newConfig
h.fs = afero.NewCopyOnWriteFs(afero.NewOsFs(), afero.NewMemMapFs())
diagnostics, err := h.inspect()
if err != nil {
return nil, err
}
log.Printf("Notify textDocument/publishDiagnostics with %#v", diagnostics)
for path, diags := range diagnostics {
err = conn.Notify(
ctx,
"textDocument/publishDiagnostics",
lsp.PublishDiagnosticsParams{
URI: pathToURI(path),
Diagnostics: diags,
},
)
if err != nil {
return nil, fmt.Errorf("Failed to notify textDocument/publishDiagnostics: %s", err)
}
}
return nil, nil
}