Skip to content

Commit

Permalink
Merge branch 'main' into ed/pluginPushCmd
Browse files Browse the repository at this point in the history
  • Loading branch information
emcfarlane committed Nov 27, 2024
2 parents 854095a + 9e94044 commit 1ef815c
Show file tree
Hide file tree
Showing 14 changed files with 1,793 additions and 709 deletions.
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ issues:
# G115 checks for use of truncating conversions.
path: private/buf/buflsp/file.go
text: "G115:"
- linters:
- gosec
# G115 checks for use of truncating conversions.
path: private/buf/buflsp/image.go
text: "G115:"
- linters:
- gosec
# G115 checks for use of truncating conversions.
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased]

- Add `buf registry plugin {create,delete,info,update}` commands to manage BSR plugins.
- Breaking analysis support for `buf beta lsp`.
- Add `buf plugin push` command to push a plugin to the Buf Schema Registry.
Only WebAssembly check plugins are supported at this time.

Expand Down
1 change: 1 addition & 0 deletions private/buf/bufcli/connectclient_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func newConnectClientConfigWithOptions(container appext.Container, opts ...conne
bufconnect.NewAugmentedConnectErrorInterceptor(),
bufconnect.NewSetCLIVersionInterceptor(Version),
bufconnect.NewCLIWarningInterceptor(container),
bufconnect.NewDebugLoggingInterceptor(container),
otelconnectInterceptor,
},
),
Expand Down
43 changes: 32 additions & 11 deletions private/buf/buflsp/buflsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func Serve(
&connWrapper{Conn: conn, logger: container.Logger()},
zap.NewNop(), // The logging from protocol itself isn't very good, we've replaced it with connAdapter here.
),
container: container,
logger: container.Logger(),
controller: controller,
checkClient: checkClient,
Expand All @@ -89,8 +90,9 @@ func Serve(
// Its handler methods are not defined in buflsp.go; they are defined in other files, grouped
// according to the groupings in
type lsp struct {
conn jsonrpc2.Conn
client protocol.Client
conn jsonrpc2.Conn
client protocol.Client
container appext.Container

logger *slog.Logger
controller bufctl.Controller
Expand Down Expand Up @@ -130,19 +132,38 @@ func (l *lsp) init(_ context.Context, params *protocol.InitializeParams) error {
// to inject debug logging, tracing, and timeouts to requests.
func (l *lsp) newHandler() jsonrpc2.Handler {
actual := protocol.ServerHandler(newServer(l), nil)
return func(ctx context.Context, reply jsonrpc2.Replier, req jsonrpc2.Request) (retErr error) {
defer slogext.DebugProfile(l.logger, slog.String("method", req.Method()), slog.Any("params", req.Params()))()
return jsonrpc2.AsyncHandler(func(ctx context.Context, reply jsonrpc2.Replier, req jsonrpc2.Request) error {
l.logger.Debug(
"handling request",
slog.String("method", req.Method()),
slog.Any("params", req.Params()),
)
defer slogext.DebugProfile(
l.logger,
slog.String("method", req.Method()),
slog.Any("params", req.Params()),
)()

replier := l.wrapReplier(reply, req)

// Verify that the server has been initialized if this isn't the initialization
// request.
var err error
if req.Method() != protocol.MethodInitialize && l.initParams.Load() == nil {
return replier(ctx, nil, fmt.Errorf("the first call to the server must be the %q method", protocol.MethodInitialize))
// Verify that the server has been initialized if this isn't the initialization
// request.
err = replier(ctx, nil, fmt.Errorf("the first call to the server must be the %q method", protocol.MethodInitialize))
} else {
l.lock.Lock()
err = actual(ctx, replier, req)
l.lock.Unlock()
}

l.lock.Lock()
defer l.lock.Unlock()
return actual(ctx, replier, req)
}
if err != nil {
l.logger.Error(
"error while replying to request",
slog.String("method", req.Method()),
slogext.ErrorAttr(err),
)
}
return nil
})
}
63 changes: 63 additions & 0 deletions private/buf/buflsp/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright 2020-2024 Buf Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package buflsp

// Configuration keys for the LSP.
//
// These are part of the public API of the LSP server, in that any user of
// the LSP can configure it using these keys. The server requests them over
// the LSP protocol as-needed.
//
// Keep in sync with bufbuild/vscode-buf package.json.
const (
// The strategy for how to calculate the --against input for a breaking
// check. This must be one of the following values:
//
// - "git". Use a particular Git revision to find the against file.
//
// - "disk". Use the last-saved value on disk as the against file.
ConfigBreakingStrategy = "buf.checks.breaking.againstStrategy"
// The Git revision to use for calculating the --against input for a
// breaking check when using the "git" strategy.
ConfigBreakingGitRef = "buf.checks.breaking.againstGitRef"
)

const (
// Compare against the configured git branch.
againstGit againstStrategy = iota + 1
// Against the last saved file on disk (i.e. saved vs unsaved changes).
againstDisk
)

// againstStrategy is a strategy for selecting which version of a file to use as
// --against for the purposes of breaking lints.
type againstStrategy int

// parseAgainstStrategy parses an againstKind from a config setting sent by
// the client.
//
// Returns againstTrunk, false if the value is not recognized.
func parseAgainstStrategy(s string) (againstStrategy, bool) {
switch s {
// These values are the same as those present in the package.json for the
// VSCode client.
case "git":
return againstGit, true
case "disk":
return againstDisk, true
default:
return againstGit, false
}
}
Loading

0 comments on commit 1ef815c

Please sign in to comment.