Skip to content

Commit f9edabb

Browse files
committed
cmd/acme-lsp: add -hidediag flag and HideDiagnostics config
Fixes #27
1 parent e04d256 commit f9edabb

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

internal/lsp/acmelsp/client.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type DiagnosticsWriter interface {
2424
// clientHandler handles JSON-RPC requests and notifications.
2525
type clientHandler struct {
2626
cfg *ClientConfig
27+
hideDiag bool
2728
diagWriter DiagnosticsWriter
2829
diag map[protocol.DocumentURI][]protocol.Diagnostic
2930
mu sync.Mutex
@@ -50,6 +51,9 @@ func (h *clientHandler) Event(context.Context, *interface{}) error {
5051
}
5152

5253
func (h *clientHandler) PublishDiagnostics(ctx context.Context, params *protocol.PublishDiagnosticsParams) error {
54+
if h.hideDiag {
55+
return nil
56+
}
5357
h.mu.Lock()
5458
defer h.mu.Unlock()
5559

@@ -94,6 +98,7 @@ func (h *clientHandler) ApplyEdit(ctx context.Context, params *protocol.ApplyWor
9498
type ClientConfig struct {
9599
*config.Server
96100
RootDirectory string // used to compute RootURI in initialization
101+
HideDiag bool // don't write diagnostics to DiagWriter
97102
DiagWriter DiagnosticsWriter // notification handler writes diagnostics here
98103
Workspaces []protocol.WorkspaceFolder // initial workspace folders
99104
Logger *log.Logger
@@ -118,6 +123,7 @@ func (c *Client) init(conn net.Conn, cfg *ClientConfig) error {
118123
stream := jsonrpc2.NewHeaderStream(conn, conn)
119124
ctx, rpc, server := protocol.NewClient(ctx, stream, &clientHandler{
120125
cfg: cfg,
126+
hideDiag: cfg.HideDiag,
121127
diagWriter: cfg.DiagWriter,
122128
diag: make(map[protocol.DocumentURI][]protocol.Diagnostic),
123129
})

internal/lsp/acmelsp/config/config.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ type File struct {
4444
// Root directory used for LSP initialization.
4545
RootDirectory string
4646

47+
// Don't show diagnostics sent by the LSP server.
48+
HideDiagnostics bool
49+
4750
// Format file when Put is executed in a window.
4851
FormatOnPut bool
4952

@@ -242,7 +245,8 @@ func (cfg *Config) ParseFlags(flags Flags, f *flag.FlagSet, arguments []string)
242245
}
243246
if flags&LangServerFlags != 0 {
244247
f.BoolVar(&cfg.Verbose, "debug", cfg.Verbose, "turn on debugging prints (deprecated: use -v)")
245-
f.StringVar(&cfg.RootDirectory, "rootdir", cfg.RootDirectory, "root directory used for LSP initialization.")
248+
f.StringVar(&cfg.RootDirectory, "rootdir", cfg.RootDirectory, "root directory used for LSP initialization")
249+
f.BoolVar(&cfg.HideDiagnostics, "hidediag", false, "hide diagnostics sent by LSP server")
246250
f.StringVar(&workspaces, "workspaces", "", "colon-separated list of initial workspace directories")
247251
f.Var(&userServers, "server", `language server command for filename match (e.g. '\.go$:gopls')`)
248252
f.Var(&dialServers, "dial", `language server address for filename match (e.g. '\.go$:localhost:4389')`)

internal/lsp/acmelsp/exec.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ func (ss *ServerSet) ClientConfig(info *ServerInfo) *ClientConfig {
216216
return &ClientConfig{
217217
Server: info.Server,
218218
RootDirectory: ss.cfg.RootDirectory,
219+
HideDiag: ss.cfg.HideDiagnostics,
219220
DiagWriter: ss.diagWriter,
220221
Workspaces: ss.Workspaces(),
221222
Logger: info.Logger,

0 commit comments

Comments
 (0)