Skip to content

Commit

Permalink
lsp: ignore after rename if not Rego
Browse files Browse the repository at this point in the history
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 StyraInc#1092

Signed-off-by: Charlie Egan <[email protected]>
  • Loading branch information
charlieegan3 committed Jan 16, 2025
1 parent 5986638 commit 4b02d1c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions internal/lsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4b02d1c

Please sign in to comment.