Skip to content

Commit 5503266

Browse files
committed
allow passing file names to GetDiagnostics
1 parent d7b27f2 commit 5503266

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

internal/api/api.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (api *API) HandleRequest(ctx context.Context, method string, payload []byte
107107
}))
108108
case MethodGetDiagnostics:
109109
params := params.(*GetDiagnosticsParams)
110-
return encodeJSON((api.GetDiagnostics(ctx, params.Project)))
110+
return encodeJSON((api.GetDiagnostics(ctx, params.Project, params.FileNames)))
111111
default:
112112
return nil, fmt.Errorf("unhandled API method %q", method)
113113
}
@@ -265,7 +265,7 @@ func (api *API) GetSourceFile(projectId Handle[project.Project], fileName string
265265
return sourceFile, nil
266266
}
267267

268-
func (api *API) GetDiagnostics(ctx context.Context, projectId Handle[project.Project]) ([]*ls.Diagnostic, error) {
268+
func (api *API) GetDiagnostics(ctx context.Context, projectId Handle[project.Project], fileNames []string) ([]*ls.Diagnostic, error) {
269269
projectPath, ok := api.projects[projectId]
270270
if !ok {
271271
return nil, errors.New("project ID not found")
@@ -278,7 +278,7 @@ func (api *API) GetDiagnostics(ctx context.Context, projectId Handle[project.Pro
278278
}
279279

280280
languageService := ls.NewLanguageService(project.GetProgram(), snapshot)
281-
diagnostics := languageService.GetDiagnostics(ctx)
281+
diagnostics := languageService.GetDiagnostics(ctx, fileNames)
282282

283283
api.symbolsMu.Lock()
284284
defer api.symbolsMu.Unlock()

internal/api/proto.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ func NewSymbolResponse(symbol *ast.Symbol) *SymbolResponse {
177177
}
178178

179179
type GetDiagnosticsParams struct {
180-
Project Handle[project.Project] `json:"project"`
180+
Project Handle[project.Project] `json:"project"`
181+
FileNames []string `json:"fileNames"`
181182
}
182183

183184
type GetTypeOfSymbolParams struct {

internal/ls/api.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,17 @@ func (d *diagnosticList) getDiagnostics() []*Diagnostic {
124124
return d.diagnostics
125125
}
126126

127-
func (l *LanguageService) GetDiagnostics(ctx context.Context) []*Diagnostic {
127+
func (l *LanguageService) GetDiagnostics(ctx context.Context, fileNames []string) []*Diagnostic {
128128
program := l.GetProgram()
129-
sourceFiles := program.GetSourceFiles()
129+
var sourceFiles []*ast.SourceFile
130+
if len(fileNames) > 0 {
131+
sourceFiles = make([]*ast.SourceFile, 0, len(fileNames))
132+
for _, fileName := range fileNames {
133+
sourceFiles = append(sourceFiles, program.GetSourceFile(fileName))
134+
}
135+
} else {
136+
sourceFiles = program.GetSourceFiles()
137+
}
130138
diagnosticList := &diagnosticList{
131139
diagnostics: make([]*Diagnostic, 0),
132140
}

0 commit comments

Comments
 (0)