@@ -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.
268170func (f * file ) Refresh (ctx context.Context ) {
269171 var progress * progress
0 commit comments