github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/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/wata727/tflint/rules" 12 "github.com/wata727/tflint/tflint" 13 ) 14 15 func (h *handler) workspaceDidChangeWatchedFiles(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) { 16 if h.rootDir == "" { 17 return nil, fmt.Errorf("root directory is undefined") 18 } 19 20 newConfig, err := tflint.LoadConfig(h.configPath) 21 if err != nil { 22 return nil, err 23 } 24 h.config = newConfig.Merge(h.cliConfig) 25 h.rules = rules.NewRules(h.config) 26 27 h.fs = afero.NewCopyOnWriteFs(afero.NewOsFs(), afero.NewMemMapFs()) 28 29 diagnostics, err := h.inspect() 30 if err != nil { 31 return nil, err 32 } 33 34 log.Println(fmt.Sprintf("Notify `textDocument/publishDiagnostics` with `%#v`", diagnostics)) 35 for path, diags := range diagnostics { 36 err = conn.Notify( 37 ctx, 38 "textDocument/publishDiagnostics", 39 lsp.PublishDiagnosticsParams{ 40 URI: pathToURI(path), 41 Diagnostics: diags, 42 }, 43 ) 44 if err != nil { 45 return nil, fmt.Errorf("Failed to notify `textDocument/publishDiagnostics`: %s", err) 46 } 47 } 48 49 return nil, nil 50 }