Giter VIP home page Giter VIP logo

vscode-jsonnet's Introduction

vscode-jsonnet

Full code support (formatting, highlighting, navigation, etc) for Jsonnet

Uses https://github.com/grafana/jsonnet-language-server as a language server. See that project's readme for information about its features

Additional Features (over the language server)

Auto-update

Installs the language server and keeps it up-to-date (prompting the user to install the new binary)

auto-update.mp4

Evaluate a file or an expression

evaluate.mp4

To use this

  1. Install the extension from the VSCode Marketplace or Open VSX
  2. Open a jsonnet file and follow the instructions on screen to download the language server
  3. Enjoy

vscode-jsonnet's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vscode-jsonnet's Issues

How does formatting works?

How can the formatting feature be triggered? It seems not working in my case. Linting and error indication are working. Thank you!

How to format jsonnet code?

The README mentions that it can format code; however it doesn't appear to format the code by default nor can I find a setting to turn on code formatting.

formatting options

Hi, I have installed vscode addon, and formatting worked on libsonnet files, but can it set "" instead '', to be more json like ?

Is there a way to provide TLAs when evaluating the file?

I want to evaluate the jsonnet file that requires some TLAs like this.

function(name)
  {
    value: std.format("Hello %s", name)、
  }

However, there seems to be no way to provide these information when evaluating the file.
And the evaluation fails due to RUNTIME ERROR: Missing argument: name Top-level function call.

Currently I need to put a dummy file that calls this function to evaluate this. Also, due to this specification, all jsonnet and libsonnet files containing such function declarations are marked with a warning.

Is there some mechanism to provide the TLAs at the time of evaluation?

autocomplete for imports

Environment

go-jsonnet: 0.18.0
jsonnet-language-server: 0.2.3

Current behaviour

When importing a jsonnet file and trying to use it, no autocompletion is provided for the import.

Expected behaviour

After importing a jsonnet file autocompletion is provided for the import, i.e. when pressing the dot key after "im" ident in the example.

Example

test.jsonnet

{
    name: "test"
}

main.jsonnet

local im = import "./test.jsonnet";

{
    asd: im.name
}

output

{
    "asd": "test"
}

Auto-Update does not work for darwin-arm64 (M1/M2 macs)

vscode auto updated the binary to 0.6.4, but the server no longer runs. and since it cant run, even with --version, it cant check the versions, so it asks to auto-update again, and the process repeats

vscode output:

Not using custom binary path. Using default path
Binary path is /Users/omar/Library/Application Support/Code/User/globalStorage/julienduchesne.vscode-jsonnet/bin/jsonnet-language-server (exists: true)
Auto-update is enabled. Fetching latest release from https://api.github.com/repos/grafana/jsonnet-language-server/releases/latest
Latest release is 0.6.4
Failed to get current version from /Users/omar/Library/Application Support/Code/User/globalStorage/julienduchesne.vscode-jsonnet/bin/jsonnet-language-server
Error: Command failed: /Users/omar/Library/Application Support/Code/User/globalStorage/julienduchesne.vscode-jsonnet/bin/jsonnet-language-server --version

however the same binary works if its in ~/go/bin/

 ~/go/bin $ ./jsonnet-language-server --version 
jsonnet-language-server version 0.6.4
 ~/L/Application Su/Co/U/g/j/bin $ ./jsonnet-language-server --version
[1]    93390 killed     ./jsonnet-language-server

im using the darwin-arm64 binary. after auto-update failed, i downloaded it manually from github and moved it into my go/bin folder, then after confirming it worked via command line, copied it to the binary path given in the vscode output above

problems: No errors or warnings

When I open a file, e.g. qa.jsonnet, it adds a entry in the Problems panel saying "No Errors or warnings"

Is this expected? thx

Publish extension on Open VSX

Hi there,

Thanks for this useful extension. I would like to ask you to kindly consider publishing this extension to the Open VSX marketplace.
I mainly use Gitpod, and so could use the extension there as well. That would be great.

Context

Unfortunately, as Microsoft prohibits usages of the Microsoft marketplace by any other products or redistribution of .vsix files from it. I kindly ask that you publish this extension on Open VSX, to use VS Code extensions in non-Microsoft products.

What is Open VSX? Why does it exist?

Open VSX is a vendor neutral alternative at the Eclipse Foundation to the MS marketplace used by most other derivatives of VS Code like VSCodium, Gitpod, OpenVSCode, Theia-based IDEs, and so on.

How can you publish to Open VSX?

The docs to publish an extension can be found here. There's also a doc explaining the process with an example GitHub Action workflow.

Support multi-root workspaces

Problem

When you use multiple folders in a VSCode workspace, the jpath is constructed with first workspace folder.

I have many jsonnet folders that respect a general hierearchy, and they are all in a named workspace.

# foreach folder of the workspace

     vendor/ # as produced by jsonnet bundler
     lib/ # local libraries
     build/ # some generated json files for import 

I set my jpath to [vendor, lib, build], but my libsonnet files are still not found, if I am not in the first folder.

Browsing through the code, I see that only the first project is used to deduce an absolute jpath. Also, this seems to happen on start of client, and on config reload. This seems like a global setting sent to the language server...

Expectation

I would expect hat the configured jpath is relative to the current folder of the current workspace and that the extension use the current context to find my files.

Notes

Maybe we could use the asRelativePath function of the workspace API, or getWorkspaceFolder to deduce the correct jpaths.

add ability to evaluate file/expression as yaml

Pretty self explanatory. It would be nice if there was a way to eval to yaml rather than json, either through another action or some sort of setting/config. Obviously, not a major thing since they're pretty interchangeable, but it may help in reading complex objects.

Can't navigate to an import file on windows

Following my success in getting #30 to work on a remote linux, I'm trying to achieve the same by copying the libjsonnet I got from the server and working locally, on a windows 10 PC.

I got some kind of success by Using this configuration:

{
  "jsonnet.languageServer.jpath": [
    "C:/workspace/tools/libjsonnet"
  ],
  "jsonnet.languageServer.tankaMode": false
}

The autocompletion works, but unlike the linux version, I get a warning on the "local" keyword on my first line;

local ddb = import 'ddb.docker.libjsonnet';
RUNTIME ERROR: Undefined external variable: core.env.available
	C:\workspace\tools\libjsonnet\ddb.docker.libjsonnet:42:29-61	thunk <_core_env_available> from <$>
	C:\workspace\tools\libjsonnet\ddb.docker.libjsonnet:376:35-54	thunk from <thunk <indexes> from <function <envIndex>>>
	<std>:1636:21-24	thunk from <function <anonymous>>
	<std>:32:25-26	thunk from <function <anonymous>>
	<std>:32:16-27	function <anonymous>
	<std>:1636:9-25	function <anonymous>
	C:\workspace\tools\libjsonnet\ddb.docker.libjsonnet:376:21-55	thunk <indexes> from <function <envIndex>>
	C:\workspace\tools\libjsonnet\ddb.docker.libjsonnet:377:33-40	thunk from <thunk <index> from <function <envIndex>>>
	C:\workspace\tools\libjsonnet\ddb.docker.libjsonnet:377:22-41	thunk <index> from <function <envIndex>>
	C:\workspace\tools\libjsonnet\ddb.docker.libjsonnet:378:5-10	function <envIndex>
	...
	<std>:1545:21-22	thunk from <function <anonymous>>
	<std>:1545:5-33	function <anonymous>
	C:\workspace\tools\libjsonnet\ddb.docker.libjsonnet:165:9-43	function <apply_docker_compose_included_services>
	C:\workspace\tools\libjsonnet\ddb.docker.libjsonnet:272:62-148	thunk from <thunk from <function <Compose>>>
	C:\workspace\tools\libjsonnet\ddb.docker.libjsonnet:175:2-9	function <apply_resolve_ports_conflicts>
	C:\workspace\tools\libjsonnet\ddb.docker.libjsonnet:272:32-149	thunk from <function <Compose>>
	C:\workspace\tools\libjsonnet\ddb.docker.libjsonnet:177:44-50	function <apply_default_network_name>
	C:\workspace\tools\libjsonnet\ddb.docker.libjsonnet:272:5-150	function <Compose>
	C:\workspace\projects\THE-PROJECT\docker-compose.yml.jsonnet:(9:1)-(99:3)	$
	During evaluation	

OK, that might not be a real issue, and I should probably set every std.extVar value I plan to use in the extension configuration, that's no my main concern.

When I try to ctrl+click on the file name on that line, it opens an editor to my project root (C:\workspace\projects\THE-PROJECT), with that message:
image

I suspect there is something off with the path handling of windows, but I don't know what to debug. The only thing I get is this:

time="2023-08-16T17:16:59+02:00" level=info msg="configuration updated: {ResolvePathsWithTanka:false JPaths:[C:/workspace/tools/libjsonnet] ExtVars:map[] ExtCode:map[] FormattingOptions:{Indent:2 MaxBlankLines:2 StringStyle:1 CommentStyle:1 PrettyFieldNames:true PadArrays:false PadObjects:true SortImports:true UseImplicitPlus:true StripEverything:false StripComments:false StripAllButComments:false} EnableEvalDiagnostics:true EnableLintDiagnostics:false}"
time="2023-08-16T17:17:02+02:00" level=error msg="Hover: error parsing the document"

Any idea of what I need to do ?

EDIT: I tried with tanka enabled and disabled (with a full vs code restart in-between) and it behaves in the same way, except that I have a more verbose "unable to identify the project root" with tanka enabled.

Convert YAML to Jsonnet

Would love a function to convert YAML (with comments) to Jsonnet. Plugins to convert YAML to JSON already exist, but unfortunately, they drop comments (as they should, because JSON doesn't support them). Additionally, keys are usually quoted, which is unnecessary in Jsonnet.

Unable to start language server on windows

Unable to start language server after installing latest version prompt:
image

Output:

[Error - 下午4:07:08] Starting client failed
Launching server using command c:\Users\A35214\AppData\Roaming\Code\User\globalStorage\grafana.vscode-jsonnet\bin\jsonnet-language-server failed.

libjsonnet path resolution

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.

Tanka support

I was evaluating Tanka, following the tutorial, but jsonnet doesn't appear to work with tanka out of the box. In the environments/default/grafana.jsonnet file I see this error:

image

My main.jsonnet looks like so. As you can see, the _config field does exist.

// Think of `import` as copy-pasting the contents
// of ./grafana.jsonnet here
(import "grafana.jsonnet") +
(import "prometheus.jsonnet") +
{
  _config:: {
    grafana: {
      port: 3000,
      name: "grafana",
    },
    prometheus: {
      port: 9090,
      name: "prometheus"
    }
  }
}

This is a two-part issue:

  1. Feedback: it would be beneficial for this to work out-of-the-box
  2. Feature request / Question: How do I configure the extension to avoid the error above?

Republish as `grafana`

This is currently published under my personal account. We should republish this from a Grafana Azure account

Auto update possibly prevents language server from working

I guess due to different extensions I also have installed, a rate limit for the Github API was triggered. As a result, the extension couldn't be loaded. I didn't find a way to log into Github from VSCode (or in the vscode-jsonnet settings) to circumvent the limitation. After a while I restarted VSCode and the extension worked. I only then figured, that it was the auto-update that possibly prevented the extension from being usable. For now, I have disabled the auto-update.

Outline view

Is support for the outline view on the roadmap?

Thanks for the awesome extension

folder settings ignored

in my currently open folder I have a .vscode/settings.json file with:

{
  "jsonnet.languageServer.tankaMode": false,
  "jsonnet.languageServer.jpath": [
    "/test",
    "."
  ]
}

(the settings ui correctly shows these values)

But when I save it the content is ignored, here is the jsonnet language server output:

time="2024-02-26T11:30:32+01:00" level=info msg="configuration updated: {ResolvePathsWithTanka:false JPaths:[] ExtVars:map[] ExtCode:map[] FormattingOptions:{Indent:2 MaxBlankLines:2 StringStyle:1 CommentStyle:1 PrettyFieldNames:true PadArrays:false PadObjects:true SortImports:true UseImplicitPlus:true StripEverything:false StripComments:false StripAllButComments:false} EnableEvalDiagnostics:true EnableLintDiagnostics:false}"

I have the latest jsonnet language server (0.13.1) and the vscode extension is up to date too (v0.5.1)

if I move the settings in my workspace settings it works.

Odd auto formatting

If I create a jsonnet file with:

local asd(
  x=1
) = {
  hello: x,
};
asd(x=4)

It gets auto-formatted to:

local asd(
  x=1
      ) = {
  hello: x,
};
asd(x=4)

Which is really weird.

Version: 0.3.1

Getting "'opts.calledFrom' is unset or empty" even when doing new(std.thisFile)

I have the following lines in a jsonnet file

local tanka = import 'github.com/grafana/jsonnet-libs/tanka-util/main.libsonnet';
local helm = tanka.helm.new(std.thisFile);

And I'm seeing the 'opts.calledFrom' is unset or empty warning anyway.

image

I'm on the latest version (0.4.1), I'm running in Tanka mode, the chartfile.yaml file and the charts/ directory are there, and I have the dependency on https://github.com/grafana/jsonnet-libs.git pointing to master in jsonnetfile.json.

Also, running tk show ... on the command line works fine, both on the integrated terminal and on an external terminal.

Am I missing something? Is there a setting I can configure to make the warning go away?

v0.6.0 Seems to ignore configurations

Hi

I've updated the extensions to v0.6.0 and noticed that the PadArrays parameter doesn't work anymore.

Output with v0.6.0:

time="2024-03-06T10:18:41+01:00" level=info msg="Starting the language server"
time="2024-03-06T10:18:41+01:00" level=info msg="Initializing jsonnet-language-server version 0.13.1"
time="2024-03-06T10:18:41+01:00" level=info msg="Reading stdlib"

Output after downgrading to v0.5.1:


time="2024-03-06T10:19:04+01:00" level=info msg="Starting the language server"
time="2024-03-06T10:19:04+01:00" level=info msg="Initializing jsonnet-language-server version 0.13.1"
time="2024-03-06T10:19:04+01:00" level=info msg="Reading stdlib"
time="2024-03-06T10:19:04+01:00" level=info msg="configuration updated: {ResolvePathsWithTanka:false JPaths:[/Users/simonbeck/repos/appcat/component-appcat/lib/ /Users/simonbeck/Library/Python/3.10/lib/python/site-packages/commodore /Users/simonbeck/Library/Python/3.10/lib/python/site-packages/kapitan] ExtVars:map[] ExtCode:map[] FormattingOptions:{Indent:2 MaxBlankLines:2 StringStyle:1 CommentStyle:1 PrettyFieldNames:true PadArrays:true PadObjects:true SortImports:true UseImplicitPlus:true StripEverything:false StripComments:false StripAllButComments:false} EnableEvalDiagnostics:true EnableLintDiagnostics:true}"
time="2024-03-06T10:19:04+01:00" level=info msg="configuration updated: {ResolvePathsWithTanka:false JPaths:[/Users/simonbeck/repos/appcat/component-appcat/lib/ /Users/simonbeck/Library/Python/3.10/lib/python/site-packages/commodore /Users/simonbeck/Library/Python/3.10/lib/python/site-packages/kapitan] ExtVars:map[] ExtCode:map[] FormattingOptions:{Indent:2 MaxBlankLines:2 StringStyle:1 CommentStyle:1 PrettyFieldNames:true PadArrays:true PadObjects:true SortImports:true UseImplicitPlus:true StripEverything:false StripComments:false StripAllButComments:false} EnableEvalDiagnostics:true EnableLintDiagnostics:true}"
time="2024-03-06T10:19:05+01:00" level=info msg="configuration updated: {ResolvePathsWithTanka:false JPaths:[/Users/simonbeck/repos/appcat/component-appcat/lib/ /Users/simonbeck/Library/Python/3.10/lib/python/site-packages/commodore /Users/simonbeck/Library/Python/3.10/lib/python/site-packages/kapitan] ExtVars:map[] ExtCode:map[] FormattingOptions:{Indent:2 MaxBlankLines:2 StringStyle:1 CommentStyle:1 PrettyFieldNames:true PadArrays:true PadObjects:true SortImports:true UseImplicitPlus:true StripEverything:false StripComments:false StripAllButComments:false} EnableEvalDiagnostics:true EnableLintDiagnostics:true}"
time="2024-03-06T10:19:05+01:00" level=info msg="configuration updated: {ResolvePathsWithTanka:false JPaths:[/Users/simonbeck/repos/appcat/component-appcat/lib/ /Users/simonbeck/Library/Python/3.10/lib/python/site-packages/commodore /Users/simonbeck/Library/Python/3.10/lib/python/site-packages/kapitan] ExtVars:map[] ExtCode:map[] FormattingOptions:{Indent:2 MaxBlankLines:2 StringStyle:1 CommentStyle:1 PrettyFieldNames:true PadArrays:true PadObjects:true SortImports:true UseImplicitPlus:true StripEverything:false StripComments:false StripAllButComments:false} EnableEvalDiagnostics:true EnableLintDiagnostics:true}"

After downgrading the arrays are padded correctly again.

Pass jpath from file?

Hi,

it would be great if it were possible to pass in the jpath from the outside. I'm managing my build and thus also the jpath using the Gradle Build Tool. I think it would be nice if I could dump the jpath that my build inferred into a file that would then be taken into account by the extension.

Edit: thinking some more about this, it might make sense to also pass int extVars and tlas via a file. That way I could produce a completely runnable configuration from my build script.

Edit: Ok, this might already be possible by generating the workspace local settings.json file. I'll try that :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.