From df90dec7da0e9687356905a7347c52b564c759e2 Mon Sep 17 00:00:00 2001 From: Charlie Egan Date: Thu, 16 Jan 2025 16:28:36 +0000 Subject: [PATCH] lsp: ignore after rename if not Rego (#1340) There were two places where a file would be processed after a rename incorrectly: - inlay hints were still requests if the file wasn't rego - new files were still formatting if the file wasn't rego any more Fixes https://github.com/StyraInc/regal/issues/1092 Signed-off-by: Charlie Egan --- internal/lsp/server.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/lsp/server.go b/internal/lsp/server.go index f13c8ae7..1e968587 100644 --- a/internal/lsp/server.go +++ b/internal/lsp/server.go @@ -2355,6 +2355,10 @@ func (l *LanguageServer) handleWorkspaceDidRenameFiles( l.logf(log.LevelMessage, "failed to send diagnostic: %s", err) } + if l.ignoreURI(renameOp.NewURI) { + continue + } + l.cache.SetFileContents(renameOp.NewURI, content) job := lintFileJob{ @@ -2556,11 +2560,6 @@ func (l *LanguageServer) loadWorkspaceContents(ctx context.Context, newOnly bool changedOrNewURIs := make([]string, 0) if err := rio.WalkFiles(workspaceRootPath, func(path string) error { - // TODO(charlieegan3): make this configurable for things like .rq etc? - if !strings.HasSuffix(path, ".rego") { - return nil - } - fileURI := uri.FromPath(l.clientIdentifier, path) if l.ignoreURI(fileURI) { @@ -2726,6 +2725,11 @@ func (l *LanguageServer) getFilteredModules() (map[string]*ast.Module, error) { } func (l *LanguageServer) ignoreURI(fileURI string) bool { + // TODO(charlieegan3): make this configurable for things like .rq etc? + if !strings.HasSuffix(fileURI, ".rego") { + return true + } + cfg := l.getLoadedConfig() if cfg == nil { return false