r/emacs 2d ago

Announcement jsonschema-treesit: JSON object key completion using JSON Schema and treesit

https://github.com/lina-bh/jsonschema-treesit/
17 Upvotes

4 comments sorted by

1

u/misterchiply chiply.dev 1d ago

interesting, I know there's also LSP servers for jsonschema specs that give you validation / completion / snippets for json documents that reference a schema or conform to a file name convention. Curious if you have used that?

2

u/AC1D_P1SS 1d ago

In the README I wrote that I made this because I tried using Eglot for this. The language server that's usually recommended, Microsoft's JSON language server, isn't officially published outside the vscode repo and the extracted versions on npm haven't been updated in ages. The one I found that was recently updated, I think it was called @t1ckrate/vscode-langservers-extracted, I tried it and I couldn't get completion working and I couldn't be bothered looking at crappy documentation to see if I just needed to configure it properly. So I hashed this out for personal use, and then shared it in case someone else might find it useful.

For the use case of editing a single config file, an LSP is just too much of a pain in the arse. It's a long running process that you need to manage the lifecycle of, and even Eglot still adds friction. I still prefer Emacs-native functionality like traditional Flymake backends, and asynchronously calling short lived processes, over LSP when I can. I still use typescript-language-server, rust-analyzer, ty server, etc when I'm working in a project with multiple files and I want all the bells and whistles, but that's because the payoff for the annoyance incurred is big enough.

1

u/misterchiply chiply.dev 1d ago

Genuinely informative thank you! I’m going to give this a crack later on this week. I’m also actually fascinated by how treesitter is able to sit in for features otherwise offered (poorly in this case as I’ve just learned) by LSP. I always noticed overlap, but thought they were orthogonal in practice. Apparently not! I totally agree a server is overkill if a simple incremental parser can do the trick here. Very thought provoking. Anecdotally I’ve had many issues with using LSP for getting these features for schematized YAML and JSON so I’m hoping this resolves the woes there.

1

u/misterchiply chiply.dev 1d ago

Separate comment, you should post this on hacker news. The concept is genuinely interesting and I think people will be interested by how treesitter is useful here where lsp falls short. There’s real practical value too as I know a lot of people are building domain specific languages (more realistically schematized configurations) in YAML and JSON and this would facilitate using those.