Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ebracho
Copy link

@ebracho ebracho commented Jun 29, 2023

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.

…WithTanka=true

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-v9.5.0/main.libsonnet'
```

The problem is that the language server incorrectly identifies
`/home/eddie/jls-test/github.com/grafana/grafonnet/gen/grafonnet-v9.5.0/`
as a root directory because of the jsonnsetfile.json there, then returns
two guesses for import paths that don't exist: `grafonnet-v9.5.0/{lib,vendor}/`

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.

Signed-off-by: Eddie Bracho <eddie.bracho@mixpanel.com>
@CLAassistant
Copy link

CLAassistant commented Jun 29, 2023

CLA assistant check
All committers have signed the CLA.

@jdbaldry
Copy link
Member

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?

@julienduchesne julienduchesne removed their request for review September 25, 2023 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants