Skip to content

Commit d0a7159

Browse files
authored
Fix range over workspace files for WKTs (#4100)
1 parent b35b03d commit d0a7159

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

private/buf/buflsp/file.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ import (
5151
)
5252

5353
const (
54-
descriptorPath = "google/protobuf/descriptor.proto"
5554
checkRefreshPeriod = 3 * time.Second
5655
)
5756

@@ -70,7 +69,7 @@ type file struct {
7069
version int32
7170
hasText bool // Whether this file has ever had text read into it.
7271

73-
workspace *workspace
72+
workspace *workspace // May be nil.
7473

7574
againstStrategy againstStrategy
7675
againstGitRef string
@@ -393,7 +392,7 @@ func (f *file) IndexImports(ctx context.Context) {
393392
func (f *file) getWorkspaceFileInfos(ctx context.Context) ([]storage.ObjectInfo, error) {
394393
seen := make(map[string]struct{})
395394
var fileInfos []storage.ObjectInfo
396-
for _, fileInfo := range f.workspace.fileNameToFileInfo {
395+
for fileInfo := range f.workspace.FileInfo() {
397396
fileInfos = append(fileInfos, fileInfo)
398397
seen[fileInfo.Path()] = struct{}{}
399398
}

private/buf/buflsp/workspace.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package buflsp
1717
import (
1818
"context"
1919
"fmt"
20+
"iter"
2021
"log/slog"
2122

2223
"buf.build/go/standard/xlog/xslog"
@@ -141,6 +142,9 @@ func (w *workspace) Release() int {
141142

142143
// Refresh rebuilds the workspace and required context.
143144
func (w *workspace) Refresh(ctx context.Context) error {
145+
if w == nil {
146+
return nil
147+
}
144148
fileName := w.workspaceURI.Filename()
145149
bufWorkspace, err := w.lsp.controller.GetWorkspace(ctx, fileName)
146150
if err != nil {
@@ -172,6 +176,20 @@ func (w *workspace) Refresh(ctx context.Context) error {
172176
return nil
173177
}
174178

179+
// FileInfo returns an iterator over the files in the workspace.
180+
func (w *workspace) FileInfo() iter.Seq[bufmodule.FileInfo] {
181+
return func(yield func(bufmodule.FileInfo) bool) {
182+
if w == nil {
183+
return
184+
}
185+
for _, fileInfo := range w.fileNameToFileInfo {
186+
if !yield(fileInfo) {
187+
return
188+
}
189+
}
190+
}
191+
}
192+
175193
// Workspace returns the buf Workspace.
176194
func (w *workspace) Workspace() bufworkspace.Workspace {
177195
if w == nil {

0 commit comments

Comments
 (0)