File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed
Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -51,7 +51,6 @@ import (
5151)
5252
5353const (
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) {
393392func (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 }
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ package buflsp
1717import (
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.
143144func (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.
176194func (w * workspace ) Workspace () bufworkspace.Workspace {
177195 if w == nil {
You can’t perform that action at this time.
0 commit comments