Skip to content

Commit

Permalink
cmd/acme-lsp: add -hidediag flag and HideDiagnostics config
Browse files Browse the repository at this point in the history
Fixes #27
  • Loading branch information
fhs committed Dec 13, 2019
1 parent e04d256 commit f9edabb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions internal/lsp/acmelsp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type DiagnosticsWriter interface {
// clientHandler handles JSON-RPC requests and notifications.
type clientHandler struct {
cfg *ClientConfig
hideDiag bool
diagWriter DiagnosticsWriter
diag map[protocol.DocumentURI][]protocol.Diagnostic
mu sync.Mutex
Expand All @@ -50,6 +51,9 @@ func (h *clientHandler) Event(context.Context, *interface{}) error {
}

func (h *clientHandler) PublishDiagnostics(ctx context.Context, params *protocol.PublishDiagnosticsParams) error {
if h.hideDiag {
return nil
}
h.mu.Lock()
defer h.mu.Unlock()

Expand Down Expand Up @@ -94,6 +98,7 @@ func (h *clientHandler) ApplyEdit(ctx context.Context, params *protocol.ApplyWor
type ClientConfig struct {
*config.Server
RootDirectory string // used to compute RootURI in initialization
HideDiag bool // don't write diagnostics to DiagWriter
DiagWriter DiagnosticsWriter // notification handler writes diagnostics here
Workspaces []protocol.WorkspaceFolder // initial workspace folders
Logger *log.Logger
Expand All @@ -118,6 +123,7 @@ func (c *Client) init(conn net.Conn, cfg *ClientConfig) error {
stream := jsonrpc2.NewHeaderStream(conn, conn)
ctx, rpc, server := protocol.NewClient(ctx, stream, &clientHandler{
cfg: cfg,
hideDiag: cfg.HideDiag,
diagWriter: cfg.DiagWriter,
diag: make(map[protocol.DocumentURI][]protocol.Diagnostic),
})
Expand Down
6 changes: 5 additions & 1 deletion internal/lsp/acmelsp/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ type File struct {
// Root directory used for LSP initialization.
RootDirectory string

// Don't show diagnostics sent by the LSP server.
HideDiagnostics bool

// Format file when Put is executed in a window.
FormatOnPut bool

Expand Down Expand Up @@ -242,7 +245,8 @@ func (cfg *Config) ParseFlags(flags Flags, f *flag.FlagSet, arguments []string)
}
if flags&LangServerFlags != 0 {
f.BoolVar(&cfg.Verbose, "debug", cfg.Verbose, "turn on debugging prints (deprecated: use -v)")
f.StringVar(&cfg.RootDirectory, "rootdir", cfg.RootDirectory, "root directory used for LSP initialization.")
f.StringVar(&cfg.RootDirectory, "rootdir", cfg.RootDirectory, "root directory used for LSP initialization")
f.BoolVar(&cfg.HideDiagnostics, "hidediag", false, "hide diagnostics sent by LSP server")
f.StringVar(&workspaces, "workspaces", "", "colon-separated list of initial workspace directories")
f.Var(&userServers, "server", `language server command for filename match (e.g. '\.go$:gopls')`)
f.Var(&dialServers, "dial", `language server address for filename match (e.g. '\.go$:localhost:4389')`)
Expand Down
1 change: 1 addition & 0 deletions internal/lsp/acmelsp/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func (ss *ServerSet) ClientConfig(info *ServerInfo) *ClientConfig {
return &ClientConfig{
Server: info.Server,
RootDirectory: ss.cfg.RootDirectory,
HideDiag: ss.cfg.HideDiagnostics,
DiagWriter: ss.diagWriter,
Workspaces: ss.Workspaces(),
Logger: info.Logger,
Expand Down

0 comments on commit f9edabb

Please sign in to comment.