Skip to content

Commit

Permalink
Improve LSP diagnostic info (#3436)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanvanburen authored Nov 4, 2024
1 parent c26d758 commit b760d59
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion private/buf/buflsp/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ func (f *file) RunLints(ctx context.Context) bool {
},
Code: annotation.Type(),
Severity: protocol.DiagnosticSeverityError,
Source: "buf lint",
Source: serverName,
Message: annotation.Message(),
})
}
Expand Down
5 changes: 2 additions & 3 deletions private/buf/buflsp/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
package buflsp

import (
"fmt"

"github.com/bufbuild/protocompile/linker"
"github.com/bufbuild/protocompile/parser"
"github.com/bufbuild/protocompile/reporter"
Expand Down Expand Up @@ -79,7 +77,8 @@ func newDiagnostic(err reporter.ErrorWithPos, isWarning bool) protocol.Diagnosti
// essentially a bug that will result in worse diagnostics until fixed.
Range: protocol.Range{Start: pos, End: pos},
Severity: protocol.DiagnosticSeverityError,
Message: fmt.Sprintf("%s:%d:%d: %s", err.GetPosition().Filename, err.GetPosition().Line, err.GetPosition().Col, err.Unwrap().Error()),
Message: err.Unwrap().Error(),
Source: serverName,
}

if isWarning {
Expand Down
6 changes: 5 additions & 1 deletion private/buf/buflsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ import (
"go.lsp.dev/protocol"
)

const (
serverName = "buf-lsp"
)

const (
semanticTypeType = iota
semanticTypeStruct
Expand Down Expand Up @@ -82,7 +86,7 @@ func (s *server) Initialize(
return nil, err
}

info := &protocol.ServerInfo{Name: "buf-lsp"}
info := &protocol.ServerInfo{Name: serverName}
if buildInfo, ok := debug.ReadBuildInfo(); ok {
info.Version = buildInfo.Main.Version
}
Expand Down

0 comments on commit b760d59

Please sign in to comment.