diff --git a/internal/handler/hover_test.go b/internal/handler/hover_test.go index 31e999c7..aabaed3c 100644 --- a/internal/handler/hover_test.go +++ b/internal/handler/hover_test.go @@ -1,6 +1,7 @@ package handler import ( + "path/filepath" "testing" "github.com/mrjosh/helm-ls/internal/charts" @@ -125,7 +126,7 @@ nested: value want: `### values.yaml parentValue -### charts/subchart/values.yaml +### ` + filepath.Join("charts", "subchart", "values.yaml") + ` value `, @@ -159,7 +160,7 @@ value want: `### values.yaml parentValue -### charts/subchart/values.yaml +### ` + filepath.Join("charts", "subchart", "values.yaml") + ` value `, @@ -203,10 +204,10 @@ value want: `### values.yaml parentValue -### charts/subchart/values.yaml +### ` + filepath.Join("charts", "subchart", "values.yaml") + ` middleValue -### charts/subchart/charts/subsubchart/values.yaml +### ` + filepath.Join("charts", "subchart", "charts", "subsubchart", "values.yaml") + ` value `, diff --git a/internal/lsp/document.go b/internal/lsp/document.go index 0f68dd98..31640cba 100644 --- a/internal/lsp/document.go +++ b/internal/lsp/document.go @@ -2,10 +2,10 @@ package lsp import ( "bytes" + "fmt" "strings" "github.com/mrjosh/helm-ls/internal/util" - "github.com/pkg/errors" sitter "github.com/smacker/go-tree-sitter" lsp "go.lsp.dev/protocol" "go.lsp.dev/uri" @@ -33,16 +33,10 @@ func (s *DocumentStore) GetAllDocs() []*Document { } func (s *DocumentStore) DidOpen(params lsp.DidOpenTextDocumentParams,helmlsConfig util.HelmlsConfiguration) (*Document, error) { - //langID := params.TextDocument.LanguageID - //if langID != "markdown" && langID != "vimwiki" && langID != "pandoc" { - //return nil, nil - //} + logger.Debug(fmt.Sprintf("Opening document %s with langID %s", params.TextDocument.URI,params.TextDocument.LanguageID)) uri := params.TextDocument.URI - path, err := s.normalizePath(uri) - if err != nil { - return nil, err - } + path := uri.Filename() doc := &Document{ URI: uri, Path: path, @@ -59,23 +53,11 @@ func (s *DocumentStore) Close(uri lsp.DocumentURI) { } func (s *DocumentStore) Get(docuri uri.URI) (*Document, bool) { - path, err := s.normalizePath(docuri) - if err != nil { - logger.Debug(err) - return nil, false - } + path := docuri.Filename() d, ok := s.documents[path] return d, ok } -func (s *DocumentStore) normalizePath(docuri uri.URI) (string, error) { - path, err := util.URIToPath(docuri) - if err != nil { - return "", errors.Wrapf(err, "unable to parse URI: %s", docuri) - } - return s.fs.Canonical(path), nil -} - // Document represents an opened file. type Document struct { URI lsp.DocumentURI diff --git a/internal/util/strings.go b/internal/util/strings.go index 58d0c8c0..9c137ddc 100644 --- a/internal/util/strings.go +++ b/internal/util/strings.go @@ -1,14 +1,11 @@ package util import ( - "net/url" "regexp" - "runtime" "strings" "github.com/mrjosh/helm-ls/internal/log" "go.lsp.dev/protocol" - "go.lsp.dev/uri" ) var ( @@ -46,29 +43,6 @@ func AfterStrings(value string, a string) string { return value[adjustedPos:] } -func URIToPath(docuri uri.URI) (string, error) { - parsed, err := url.Parse(docuri.Filename()) - if err != nil { - return "", err - } - - logger.Printf("Go file uri %s, path: %s", parsed, parsed.Path) - if runtime.GOOS == "windows" { - - // In Windows "file:///c:/tmp/foo.md" is parsed to "/c:/tmp/foo.md". - // Strip the first character to get a valid path. - if strings.Contains(parsed.Path[1:], ":") { - // url.Parse() behaves differently with "file:///c:/..." and "file://c:/..." - return parsed.Path[1:], nil - } - - // if the windows drive is not included in Path it will be in Host - return parsed.Host + "/" + parsed.Path[1:], nil - } - - return parsed.Path, nil -} - // WordAt returns the word found at the given character position. // Credit https://github.com/aca/neuron-language-server/blob/450a7cff71c14e291ee85ff8a0614fa9d4dd5145/utils.go#L13 func WordAt(str string, index int) string {