Skip to content

Commit

Permalink
fix: do not remove files that do not exist on disk from FileCache (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesFaucherre authored Oct 19, 2023
1 parent 5541d4a commit f2c6a82
Showing 1 changed file with 0 additions and 41 deletions.
41 changes: 0 additions & 41 deletions pkg/services/documentSymbols.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,14 @@ package languageservice

import (
"errors"
"fmt"
"os"

yamlparser "github.com/CircleCI-Public/circleci-yaml-language-server/pkg/parser"
"github.com/CircleCI-Public/circleci-yaml-language-server/pkg/services/documentSymbols"
"github.com/CircleCI-Public/circleci-yaml-language-server/pkg/utils"
"go.lsp.dev/protocol"
)

func uriPath(uri protocol.URI) (path string, err error) {
defer func() {
panicErr := recover()
if panicErr != nil {
path = ""

var ok bool
if err, ok = panicErr.(error); ok {
return
}

err = fmt.Errorf("%s", panicErr)
return
}
}()
path = uri.Filename()
return
}

func DocumentSymbols(params protocol.DocumentSymbolParams, cache *utils.Cache, context *utils.LsContext) ([]protocol.DocumentSymbol, error) {
path, err := uriPath(params.TextDocument.URI)
if err != nil {
return nil, err
}

exists := true
_, err = os.Stat(path)
if err != nil {
if !errors.Is(err, os.ErrNotExist) {
// Error is not "file does not exist", stop execution and return
return nil, err
}
exists = false
}

if !exists {
cache.FileCache.RemoveFile(params.TextDocument.URI)
return nil, fmt.Errorf("file does not exist: %w", err)
}

yamlDocument, err := yamlparser.ParseFromUriWithCache(params.TextDocument.URI, cache, context)

if errors.Is(err, yamlparser.CacheMissingError) {
Expand Down

0 comments on commit f2c6a82

Please sign in to comment.