From 5503266a4354e3bd2da4b661c192ce75faea83b9 Mon Sep 17 00:00:00 2001 From: Nathan Whitaker Date: Mon, 13 Oct 2025 10:37:59 -0700 Subject: [PATCH] allow passing file names to GetDiagnostics --- internal/api/api.go | 6 +++--- internal/api/proto.go | 3 ++- internal/ls/api.go | 12 ++++++++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/internal/api/api.go b/internal/api/api.go index 69522b11d2..f9d65d398c 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -107,7 +107,7 @@ func (api *API) HandleRequest(ctx context.Context, method string, payload []byte })) case MethodGetDiagnostics: params := params.(*GetDiagnosticsParams) - return encodeJSON((api.GetDiagnostics(ctx, params.Project))) + return encodeJSON((api.GetDiagnostics(ctx, params.Project, params.FileNames))) default: return nil, fmt.Errorf("unhandled API method %q", method) } @@ -265,7 +265,7 @@ func (api *API) GetSourceFile(projectId Handle[project.Project], fileName string return sourceFile, nil } -func (api *API) GetDiagnostics(ctx context.Context, projectId Handle[project.Project]) ([]*ls.Diagnostic, error) { +func (api *API) GetDiagnostics(ctx context.Context, projectId Handle[project.Project], fileNames []string) ([]*ls.Diagnostic, error) { projectPath, ok := api.projects[projectId] if !ok { return nil, errors.New("project ID not found") @@ -278,7 +278,7 @@ func (api *API) GetDiagnostics(ctx context.Context, projectId Handle[project.Pro } languageService := ls.NewLanguageService(project.GetProgram(), snapshot) - diagnostics := languageService.GetDiagnostics(ctx) + diagnostics := languageService.GetDiagnostics(ctx, fileNames) api.symbolsMu.Lock() defer api.symbolsMu.Unlock() diff --git a/internal/api/proto.go b/internal/api/proto.go index 47cd241da0..7401d7e394 100644 --- a/internal/api/proto.go +++ b/internal/api/proto.go @@ -177,7 +177,8 @@ func NewSymbolResponse(symbol *ast.Symbol) *SymbolResponse { } type GetDiagnosticsParams struct { - Project Handle[project.Project] `json:"project"` + Project Handle[project.Project] `json:"project"` + FileNames []string `json:"fileNames"` } type GetTypeOfSymbolParams struct { diff --git a/internal/ls/api.go b/internal/ls/api.go index 5990b996a6..67be3d1f0c 100644 --- a/internal/ls/api.go +++ b/internal/ls/api.go @@ -124,9 +124,17 @@ func (d *diagnosticList) getDiagnostics() []*Diagnostic { return d.diagnostics } -func (l *LanguageService) GetDiagnostics(ctx context.Context) []*Diagnostic { +func (l *LanguageService) GetDiagnostics(ctx context.Context, fileNames []string) []*Diagnostic { program := l.GetProgram() - sourceFiles := program.GetSourceFiles() + var sourceFiles []*ast.SourceFile + if len(fileNames) > 0 { + sourceFiles = make([]*ast.SourceFile, 0, len(fileNames)) + for _, fileName := range fileNames { + sourceFiles = append(sourceFiles, program.GetSourceFile(fileName)) + } + } else { + sourceFiles = program.GetSourceFiles() + } diagnosticList := &diagnosticList{ diagnostics: make([]*Diagnostic, 0), }