grafana / vscode-jsonnet

Full code support (formatting, highlighting, navigation, etc) for Jsonnet
Apache License 2.0
65 stars 7 forks source link

libjsonnet path resolution #30

Closed jeremyVignelles closed 10 months ago

jeremyVignelles commented 10 months ago

I have a software that uses jsonnet to configure docker-compose.yml ( https://github.com/inetum-orleans/docker-devbox-ddb ) and it provides a .libjsonnet file on my machine.

in my docker-compose.yml.jsonnet file, I use this line to import the file:

local ddb = import 'ddb.docker.libjsonnet';

How do I tell the vscode extension in which directory to look for this file? (it is installed globally on my machine).

I'm pretty new to jsonnet, but didn't find any ressource that could help me with this.

jeremyVignelles commented 10 months ago

I added the path to the lib folder, that contains the file to the jpath config:

/home/vagrant/.docker-devbox/ddb/ddb/feature/jsonnet/lib

now, ctrl+clicking the file name can correctly navigate to the libjsonnet file, but there is no completion for ddb.<ctrl+space>

The log:

time="2023-08-16T14:13:37+02:00" level=info msg="Starting the language server"
time="2023-08-16T14:13:37+02:00" level=info msg="Initializing jsonnet-language-server version 0.12.1"
time="2023-08-16T14:13:37+02:00" level=info msg="Reading stdlib"
time="2023-08-16T14:13:38+02:00" level=debug msg="Publishing diagnostics for file:///home/vagrant/.docker-devbox/ddb/ddb/feature/jsonnet/lib/ddb.docker.libjsonnet"
time="2023-08-16T14:13:38+02:00" level=debug msg="Publishing diagnostics for file:///home/vagrant/.docker-devbox/ddb/ddb/feature/jsonnet/lib/ddb.docker.libjsonnet"
time="2023-08-16T14:13:38+02:00" level=debug msg="Done publishing diagnostics for file:///home/vagrant/.docker-devbox/ddb/ddb/feature/jsonnet/lib/ddb.docker.libjsonnet"
time="2023-08-16T14:13:38+02:00" level=debug msg="Done publishing diagnostics for file:///home/vagrant/.docker-devbox/ddb/ddb/feature/jsonnet/lib/ddb.docker.libjsonnet"
time="2023-08-16T14:13:48+02:00" level=debug msg="Unable to resolve jpath for /home/vagrant/projects/THE-PROJECT/docker-compose.yml.jsonnet: unable to identify the project root.\nTried to find 'tkrc.yaml' or 'jsonnetfile.json' in the parent directories.\nPlease refer to https://tanka.dev/directory-structure for more information"
time="2023-08-16T14:13:48+02:00" level=debug msg="Unable to resolve jpath for /home/vagrant/projects/THE-PROJECT/docker-compose.yml.jsonnet: unable to identify the project root.\nTried to find 'tkrc.yaml' or 'jsonnetfile.json' in the parent directories.\nPlease refer to https://tanka.dev/directory-structure for more information"
time="2023-08-16T14:13:48+02:00" level=error msg="Completion: error finding ranges: field  was not found in ast.DesugaredObject"
time="2023-08-16T14:13:49+02:00" level=debug msg="Publishing diagnostics for file:///home/vagrant/projects/THE-PROJECT/docker-compose.yml.jsonnet"
time="2023-08-16T14:13:49+02:00" level=debug msg="Done publishing diagnostics for file:///home/vagrant/projects/THE-PROJECT/docker-compose.yml.jsonnet"

that message is making me wondering what's wrong:

time="2023-08-16T14:13:48+02:00" level=error msg="Completion: error finding ranges: field  was not found in ast.DesugaredObject"

while importing the file that way works:

local ddb = import '/home/vagrant/.docker-devbox/ddb/ddb/feature/jsonnet/lib/ddb.docker.libjsonnet';

The libjsonnet file : https://github.com/inetum-orleans/docker-devbox-ddb/blob/develop/ddb/feature/jsonnet/lib/ddb.docker.libjsonnet

julienduchesne commented 10 months ago

Can you try to disable the "Tanka Mode" setting?

jeremyVignelles commented 10 months ago

Same: (EDIT: it's even worse, the ctrl+click doesn't work anymore)

time="2023-08-16T14:56:31+02:00" level=info msg="Starting the language server"
time="2023-08-16T14:56:31+02:00" level=info msg="Initializing jsonnet-language-server version 0.12.1"
time="2023-08-16T14:56:31+02:00" level=info msg="Reading stdlib"
time="2023-08-16T14:56:32+02:00" level=debug msg="Publishing diagnostics for file:///home/vagrant/.docker-devbox/ddb/ddb/feature/jsonnet/lib/ddb.docker.libjsonnet"
time="2023-08-16T14:56:32+02:00" level=debug msg="Publishing diagnostics for file:///home/vagrant/.docker-devbox/ddb/ddb/feature/jsonnet/lib/ddb.docker.libjsonnet"
time="2023-08-16T14:56:32+02:00" level=debug msg="Done publishing diagnostics for file:///home/vagrant/.docker-devbox/ddb/ddb/feature/jsonnet/lib/ddb.docker.libjsonnet"
time="2023-08-16T14:56:32+02:00" level=debug msg="Done publishing diagnostics for file:///home/vagrant/.docker-devbox/ddb/ddb/feature/jsonnet/lib/ddb.docker.libjsonnet"
time="2023-08-16T14:56:34+02:00" level=error msg="Completion: error finding ranges: field  was not found in ast.DesugaredObject"
time="2023-08-16T14:56:34+02:00" level=debug msg="Publishing diagnostics for file:///home/vagrant/projects/THE-PROJECT/docker-compose.yml.jsonnet"
time="2023-08-16T14:56:34+02:00" level=debug msg="Done publishing diagnostics for file:///home/vagrant/projects/THE-PROJECT/docker-compose.yml.jsonnet"
time="2023-08-16T14:56:36+02:00" level=error msg="Completion: error finding ranges: field  was not found in ast.DesugaredObject"

Is there any way I can know what jpath is passed to the language server ?

NOTE: I'm using the extension in a remote SSH session, could it cause any issue ?

jeremyVignelles commented 10 months ago

It seems that the jpath variable here is never used. Am I right to assume that I should trigger a configuration change rather than restarting the server in order to apply the jpath config properly ? Which path syntax should I use on windows/on linux ?

julienduchesne commented 10 months ago

It seems that the jpath variable here is never used. Am I right to assume that I should trigger a configuration change rather than restarting the server in order to apply the jpath config properly ? Which path syntax should I use on windows/on linux ?

It's supposed to be passed in the DidChangeConfiguration hook: https://github.com/grafana/vscode-jsonnet/blob/5d9bbbdb63908f03ce611f26e890907cdbf49d0a/src/extension.ts#L169 which is sent on startup as well

jeremyVignelles commented 10 months ago

It is called on startup, but not on "jsonnet.restartLanguageServer"

Inside the startClient method, it does not seem to have any effect.

By restarting the vscode window, I got it to work, but even after a configuration change trigger, it seems a bit flaky with the error message in my second post.

jeremyVignelles commented 10 months ago

So, to sum up: When I was testing, I was just hitting "Jsonnet: Restart Language Server" instead of restarting VSCode. It seems to work better now, with a working configuration.

The configuration I have:

{
  "jsonnet.languageServer.jpath": [
    "/home/vagrant/.docker-devbox/ddb/ddb/feature/jsonnet/lib"
  ],
  "jsonnet.languageServer.tankaMode": false
}

After starting the window again, the import is properly resolved and completion works as expected.

I submitted #31 to fix the issue of the configuration being lost on server restart.

On windows, it doesn't work, but I don't know yet if that's my fault or not. I'll keep you posted.