Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
buf.build/go/standard v0.1.0
connectrpc.com/connect v1.19.1
connectrpc.com/otelconnect v0.9.0
github.com/bufbuild/protocompile v0.14.2-0.20260121154354-91940cd2bca3
github.com/bufbuild/protocompile v0.14.2-0.20260130195850-5c64bed4577e
github.com/bufbuild/protoplugin v0.0.0-20250218205857-750e09ce93e1
github.com/cli/browser v1.3.0
github.com/docker/docker v28.5.2+incompatible
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYW
github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw=
github.com/bmatcuk/doublestar/v4 v4.9.2 h1:b0mc6WyRSYLjzofB2v/0cuDUZ+MqoGyH3r0dVij35GI=
github.com/bmatcuk/doublestar/v4 v4.9.2/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
github.com/bmatcuk/doublestar/v4 v4.10.0 h1:zU9WiOla1YA122oLM6i4EXvGW62DvKZVxIe6TYWexEs=
github.com/brianvoe/gofakeit/v6 v6.28.0 h1:Xib46XXuQfmlLS2EXRuJpqcw8St6qSZz75OUo0tgAW4=
github.com/brianvoe/gofakeit/v6 v6.28.0/go.mod h1:Xj58BMSnFqcn/fAQeSK+/PLtC5kSb7FJIq4JyGa8vEs=
github.com/bufbuild/protocompile v0.14.2-0.20260121154354-91940cd2bca3 h1:7wRdWMBC4bFiS66NRJtMWRimxYik53CKtcU8KPP1EMg=
github.com/bufbuild/protocompile v0.14.2-0.20260121154354-91940cd2bca3/go.mod h1:H51HpPHpeLddOIg/OZAuZsPmlKvP8pyXKXAkOUin9ZM=
github.com/bufbuild/protocompile v0.14.2-0.20260130195850-5c64bed4577e h1:emH16Bf1w4C0cJ3ge4QtBAl4sIYJe23EfpWH0SpA9co=
github.com/bufbuild/protocompile v0.14.2-0.20260130195850-5c64bed4577e/go.mod h1:cxhE8h+14t0Yxq2H9MV/UggzQ1L0gh0t2tJobITWsBE=
github.com/bufbuild/protoplugin v0.0.0-20250218205857-750e09ce93e1 h1:V1xulAoqLqVg44rY97xOR+mQpD2N+GzhMHVwJ030WEU=
github.com/bufbuild/protoplugin v0.0.0-20250218205857-750e09ce93e1/go.mod h1:c5D8gWRIZ2HLWO3gXYTtUfw/hbJyD8xikv2ooPxnklQ=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
Expand Down
34 changes: 14 additions & 20 deletions private/buf/buflsp/buflsp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,26 +121,20 @@ func setupLSPServer(

stream := jsonrpc2.NewStream(serverConn)

go func() {
conn, err := buflsp.Serve(
ctx,
"test",
wktBucket,
appextContainer,
controller,
wasmRuntime,
stream,
queryExecutor,
)
if err != nil {
t.Errorf("Failed to start server: %v", err)
return
}
t.Cleanup(func() {
require.NoError(t, conn.Close())
})
<-ctx.Done()
}()
conn, err := buflsp.Serve(
ctx,
"test",
wktBucket,
appextContainer,
controller,
wasmRuntime,
stream,
queryExecutor,
)
require.NoError(t, err)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just simplified; Serve will start running in the background, so we don't need the extra goroutine.

t.Cleanup(func() {
require.NoError(t, conn.Close())
})

clientStream := jsonrpc2.NewStream(clientConn)
clientJSONConn := jsonrpc2.NewConn(clientStream)
Expand Down
35 changes: 10 additions & 25 deletions private/buf/buflsp/diagnostic.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
package buflsp

import (
"encoding/json"
"strings"

"github.com/bufbuild/protocompile/experimental/report"
"github.com/bufbuild/protocompile/experimental/report/tags"
"github.com/bufbuild/protocompile/experimental/source/length"
"go.lsp.dev/protocol"
)
Expand All @@ -30,14 +28,6 @@ import (
// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#position
const positionalEncoding = length.UTF16

// diagnosticData is a structure to hold the [report.Diagnostic] notes, help, and debug
// messages, to marshal into JSON for the [protocol.Diagnostic].Data field.
type diagnosticData struct {
Notes string `json:"notes,omitempty"`
Help string `json:"help,omitempty"`
Debug string `json:"debug,omitempty"`
}

// reportLevelToDiagnosticSeverity is a mapping of [report.Level] to [protocol.DiagnosticSeverity].
var reportLevelToDiagnosticSeverity = map[report.Level]protocol.DiagnosticSeverity{
report.ICE: protocol.DiagnosticSeverityError,
Expand Down Expand Up @@ -70,20 +60,15 @@ func reportDiagnosticToProtocolDiagnostic(
},
}
}
data := diagnosticData{
Notes: strings.Join(reportDiagnostic.Notes(), "\n"),
Help: strings.Join(reportDiagnostic.Help(), "\n"),
Debug: strings.Join(reportDiagnostic.Debug(), "\n"),
}
bytes, err := json.Marshal(data)
if err != nil {
return protocol.Diagnostic{}, err
}
if bytes != nil {
// We serialize the bytes into a string before providing the structure to diagnostic.Data
// because diagnostic.Data is an interface{}, which is treated as a JSON "any", which
// will not cleanly deserialize.
diagnostic.Data = string(bytes)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we aren't using this data; it's just included so it can be passed back to us in a subsequent codeAction (ref: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#diagnostic). I think we can leave it off, for now.

switch reportDiagnostic.Tag() {
case tags.UnusedImport:
diagnostic.Tags = []protocol.DiagnosticTag{
protocol.DiagnosticTagUnnecessary,
}
case tags.Deprecated:
diagnostic.Tags = []protocol.DiagnosticTag{
protocol.DiagnosticTagDeprecated,
}
}
return diagnostic, nil
}
Loading
Loading