jsonnet-language-server icon indicating copy to clipboard operation
jsonnet-language-server copied to clipboard

Fallback to configurations.JPath paths even on tanka jpath.Resolve() hit

Open ebracho opened this issue 1 year ago • 2 comments

In some scenarios tanka's jpath.Resolve() method will return false-positive results. Example:

$ pwd
/home/eddie/jls-test
$ tree .
.
├── jsonnetfile.json
├── main.libsonnet
// ...
└── vendor
    ├── github.com
    │   ├── grafana
    │   │   ├── grafonnet
    │   │   │   ├── gen
    │   │   │   │   ├── grafonnet-latest
    │   │   │   │   │   ├── jsonnetfile.json
    │   │   │   │   │   └── main.libsonnet
// ...
$ cat main.libsonnet
import 'github.com/grafana/grafonnet/gen/grafonnet-latest/main.libsonnet'

From vscode:

Screen Shot 2023-06-28 at 5 28 11 PM
RUNTIME ERROR: couldn't open import "github.com/grafana/grafonnet/gen/grafonnet-latest/main.libsonnet": no match locally or in the Jsonnet library paths
	/home/eddie/jls-test/main.libsonnet:1:1-74	$
	During evaluation	

The problem is that the language server incorrectly identifies github.com/grafana/grafonnet/gen/grafonnet-latest/ as a root directory because of the jsonnsetfile.json there (code), then returns two guesses for import paths that don't exist: grafonnet-latest/{lib,vendor}/. In this scenario it doesn't include the configured jsonnet library paths as a fallback (presumably since it thinks it found a successful hit).

This change doesn't fix this resolve error, but it does append configuration.JPaths to the end of Opts.ImportPaths as a fallback for this false-positive scenario.

ebracho avatar Jun 29 '23 00:06 ebracho

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jun 29 '23 00:06 CLAassistant

Hi @ebracho,

Thanks for being patient with this PR.

I'm a little confused by the screenshot from VSCode. It looks like the correct two paths have been determined: /home/eddie/jls-test/lib and /home/eddie/jls-test/vendor.

Re-reading your post, it looks like you have manually configured those paths and would like them respected by the language server even if Tanka resolution determines different ones. Is that correct?

jdbaldry avatar Jul 10 '23 08:07 jdbaldry