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