Skip to content

Commit 82a0803

Browse files
authored
LSP remove refresh settings (#4114)
1 parent 10ca53e commit 82a0803

File tree

3 files changed

+1
-192
lines changed

3 files changed

+1
-192
lines changed

private/buf/buflsp/config.go

Lines changed: 0 additions & 62 deletions
This file was deleted.

private/buf/buflsp/file.go

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ import (
3434
"github.com/bufbuild/buf/private/bufpkg/bufanalysis"
3535
"github.com/bufbuild/buf/private/bufpkg/bufcheck"
3636
"github.com/bufbuild/buf/private/bufpkg/bufimage"
37-
"github.com/bufbuild/buf/private/pkg/git"
38-
"github.com/bufbuild/buf/private/pkg/normalpath"
3937
"github.com/bufbuild/buf/private/pkg/storage"
4038
"github.com/bufbuild/protocompile/experimental/ast/predeclared"
4139
"github.com/bufbuild/protocompile/experimental/incremental"
@@ -64,9 +62,6 @@ type file struct {
6462

6563
workspace *workspace // May be nil.
6664

67-
againstStrategy againstStrategy
68-
againstGitRef string
69-
7065
objectInfo storage.ObjectInfo
7166
importToFile map[string]*file
7267

@@ -171,99 +166,6 @@ func (f *file) Update(ctx context.Context, version int32, text string) {
171166
f.hasText = true
172167
}
173168

174-
// RefreshSettings refreshes configuration settings for this file.
175-
//
176-
// This only needs to happen when the file is open or when the client signals
177-
// that configuration settings have changed.
178-
func (f *file) RefreshSettings(ctx context.Context) {
179-
settings, err := f.lsp.client.Configuration(ctx, &protocol.ConfigurationParams{
180-
Items: []protocol.ConfigurationItem{
181-
{ScopeURI: f.uri, Section: ConfigBreakingStrategy},
182-
{ScopeURI: f.uri, Section: ConfigBreakingGitRef},
183-
},
184-
})
185-
if err != nil {
186-
// We can throw the error away, since the handler logs it for us.
187-
return
188-
}
189-
190-
// NOTE: indices here are those from the array in the call to Configuration above.
191-
f.againstStrategy = getSetting(f, settings, ConfigBreakingStrategy, 0, parseAgainstStrategy)
192-
f.againstGitRef = getSetting(f, settings, ConfigBreakingGitRef, 1, func(s string) (string, bool) { return s, true })
193-
194-
switch f.againstStrategy {
195-
case againstDisk:
196-
f.againstGitRef = ""
197-
case againstGit:
198-
// Check to see if the user setting is a valid Git ref.
199-
err := git.IsValidRef(
200-
ctx,
201-
f.lsp.container,
202-
normalpath.Dir(f.uri.Filename()),
203-
f.againstGitRef,
204-
)
205-
if err != nil {
206-
f.lsp.logger.Warn(
207-
"failed to validate buf.againstGit",
208-
slog.String("uri", string(f.uri)),
209-
xslog.ErrorAttr(err),
210-
)
211-
f.againstGitRef = ""
212-
} else {
213-
f.lsp.logger.Debug(
214-
"found remote branch",
215-
slog.String("uri", string(f.uri)),
216-
slog.String("ref", f.againstGitRef),
217-
)
218-
}
219-
}
220-
}
221-
222-
// getSetting is a helper that extracts a configuration setting from the return
223-
// value of [protocol.Client.Configuration].
224-
//
225-
// The parse function should convert the JSON value we get from the protocol
226-
// (such as a string), potentially performing validation, and returning a default
227-
// value on validation failure.
228-
func getSetting[T, U any](f *file, settings []any, name string, index int, parse func(T) (U, bool)) (value U) {
229-
if len(settings) <= index {
230-
f.lsp.logger.Warn(
231-
"missing config setting",
232-
slog.String("setting", name),
233-
slog.String("uri", string(f.uri)),
234-
)
235-
}
236-
237-
if raw, ok := settings[index].(T); ok {
238-
// For invalid settings, this will default to againstTrunk for us!
239-
value, ok = parse(raw)
240-
if !ok {
241-
f.lsp.logger.Warn(
242-
"invalid config setting",
243-
slog.String("setting", name),
244-
slog.String("uri", string(f.uri)),
245-
slog.Any("raw", raw),
246-
)
247-
}
248-
} else {
249-
f.lsp.logger.Warn(
250-
"invalid config setting",
251-
slog.String("setting", name),
252-
slog.String("uri", string(f.uri)),
253-
slog.Any("raw", raw),
254-
)
255-
}
256-
257-
f.lsp.logger.Debug(
258-
"parsed config setting",
259-
slog.String("setting", name),
260-
slog.String("uri", string(f.uri)),
261-
slog.Any("value", value),
262-
)
263-
264-
return value
265-
}
266-
267169
// Refresh rebuilds all of a file's internal book-keeping.
268170
func (f *file) Refresh(ctx context.Context) {
269171
var progress *progress

private/buf/buflsp/server.go

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -158,20 +158,7 @@ func (s *server) Initialized(
158158
ctx context.Context,
159159
params *protocol.InitializedParams,
160160
) error {
161-
workspaceCapabilities := s.initParams.Load().Capabilities.Workspace
162-
if workspaceCapabilities == nil {
163-
return nil
164-
}
165-
didChangeConfiguration := workspaceCapabilities.DidChangeConfiguration
166-
if didChangeConfiguration != nil && didChangeConfiguration.DynamicRegistration {
167-
// The error is logged for us by the client wrapper.
168-
_ = s.client.RegisterCapability(ctx, &protocol.RegistrationParams{
169-
Registrations: []protocol.Registration{
170-
{Method: protocol.MethodWorkspaceDidChangeConfiguration},
171-
},
172-
})
173-
}
174-
161+
// No initialization required.
175162
return nil
176163
}
177164

@@ -202,23 +189,6 @@ func (s *server) Exit(ctx context.Context) error {
202189
return s.lsp.conn.Close()
203190
}
204191

205-
// DidChangeConfiguration is sent whenever the client changes its config settings.
206-
func (s *server) DidChangeConfiguration(
207-
ctx context.Context,
208-
params *protocol.DidChangeConfigurationParams,
209-
) error {
210-
// We need to refresh every open file's settings, and refresh the file
211-
// itself.
212-
s.fileManager.uriToFile.Range(func(_ protocol.URI, file *file) bool {
213-
if file.IsOpenInEditor() {
214-
file.RefreshSettings(ctx)
215-
file.Refresh(ctx)
216-
}
217-
return true
218-
})
219-
return nil
220-
}
221-
222192
// -- File synchronization methods.
223193

224194
// DidOpen is called whenever the client opens a document. This is our signal to parse
@@ -228,7 +198,6 @@ func (s *server) DidOpen(
228198
params *protocol.DidOpenTextDocumentParams,
229199
) error {
230200
file := s.fileManager.Track(params.TextDocument.URI)
231-
file.RefreshSettings(ctx)
232201
file.Update(ctx, params.TextDocument.Version, params.TextDocument.Text)
233202
file.Refresh(ctx)
234203
return nil

0 commit comments

Comments
 (0)