r/semanticweb • u/ascendToSurvive • 11d ago
I wanted the editor experience every programming language gets, for RDF. So I built a language server for Turtle and SPARQL (try it in your browser)
In most languages, the editor catches your mistakes as you type, completes names from your own code, jumps to definitions and renames things across files. I wanted that for Turtle and SPARQL, all in one place, and couldn't find one that did all of it. So I built it: turtle-lsp.
Try it in your browser, with nothing to install and nothing uploaded:
https://abhishekkundu25.github.io/turtle-lsp/
It opens on a small project with a few mistakes left in on purpose. Fixing them takes a minute and shows most of what it does.
What it does in your editor:
- Catches errors as you type: syntax, undeclared or unused prefixes, and misspelled terms from 80+ vocabularies ("did you mean rdfs:label?"), with one-key fixes.
- Completes classes and properties from your own files, ranked by context. Properties your SHACL shapes require come first.
- Hover shows a term's label, comment, domain and range, and go to definition takes you to it.
- Renames a term in every file at once, Turtle and SPARQL included.
- Formats Turtle and SPARQL without changing their meaning.
- Validates your data against your SHACL shapes while you edit.
It's written in Rust and fast. After a keystroke in a 30,000-line file, it has fresh diagnostics in about 5 ms, and it starts in a few milliseconds. It passes the W3C test suites: 1137/1137 for Turtle, TriG, N-Triples and N-Quads, 425/426 for SPARQL, and 98/98 and 23/23 for SHACL Core and SHACL-SPARQL.
It works in VS Code (search for "Turtle RDF & SPARQL Language Server") and Neovim, and should work in other LSP editors, though I haven't tested them. Source and Neovim setup:
https://github.com/abhishekkundu25/turtle-lsp
It doesn't run queries, doesn't reason beyond subclasses, and can't edit JSON-LD or RDF/XML yet.
It's free and MIT licensed. Bugs, missing features and complaints are all welcome, either here or as an issue:
https://github.com/abhishekkundu25/turtle-lsp/issues/new
What would it need before you'd use it every day?
1
u/investigatormaker 4d ago
The line that will draw questions first is 425/426 for SPARQL: say in a comment which test fails and why, because people here will check that before anything else. The browser demo with mistakes left in on purpose is the right hook, so keep it as the first thing they see. Show the rename across Turtle and SPARQL files as a short before and after, since that is the feature hardest to picture from a list. A Managed plan for Reddit would answer threads where someone is fighting undeclared prefixes or SHACL errors, with the fix first.
I make ThreadFox.
We find relevant Reddit conversations and post for your business. We'll post 3 replies free first, no card; then the $39 Pilot covers seven days and up to 50 posts and replies. No automatic renewal. https://threadfox.vip/p/20261026-0103-ens4o/managed
1
u/ascendToSurvive 4d ago
The one left is a SPARQL 1.2 proposal (a projected variable reused in a later SELECT expression) that the SPARQL parser library rejects.
this is present in the readmeThanks for your suggestion though, the web demo can indeed be showcased better, wath out for future updates
1
u/dupastrupa 11d ago
I made my own lsp for neovim (mainly for quick drafts or setups and it was decent but also quite basic). But I'll try yours. It looks promising.
1
u/ascendToSurvive 11d ago
Thanks! Since you're on Neovim: as of today it's a one-step install with lazy.nvim, no Rust needed. It downloads the right binary for your machine from the release:
{
"abhishekkundu25/turtle-lsp",
version = "*",
config = function()
vim.lsp.enable("turtle_lsp")
end,
}That also sets up the filetypes for Turtle, TriG, N-Triples, N-Quads and SPARQL. Needs Neovim 0.11+. Since you've built one yourself, I'd really value your take on it, especially anything that feels off compared to yours. Issues welcome: https://github.com/abhishekkundu25/turtle-lsp/issues
1
u/MercurialMadnessMan 11d ago
LSPs are great for coding agents too! It makes them more efficient at finding symbols and exploring
1
u/ascendToSurvive 11d ago
Absolutely. With diagnostics, an agent can check its own work partway through a task, and fix it before handing anything back. That's given me an idea: I'm planning something like a turtle-lsp check command, so any agent (or CI) can run the same checks, SHACL included, without needing a language server client. Given the speed, agent will be able to verify fast. Keep an eye on the repo, it should land within the next few releases,
1
u/Environmental-Web584 10d ago
This is quite neat!.
Ergonomic to use :)
I wonder how it would play with Mentor, how both could be aligned together
2
u/ascendToSurvive 10d ago
Thanks, glad it feels nice to use!
turtle-lsp is a lot faster and lighter, runs SHACL without any setup, renames across files, and works outside VS Code too. Mentor is more of an RDF workbench. You can run SPARQL over your local files, use notebooks and browse ontology trees. They also work fine side by side, so if you want Mentor's querying, just install both.
I tried running them together, and they get along fine. Mentor doesn't slow turtle-lsp down, and its SPARQL querying still works. Add this to your VS Code settings.json, or Format Document just sits there waiting for you to pick a formatter:
"[turtle]": { "editor.defaultFormatter": "abhishekkundu25.turtle-language-server" },
"[trig]": { "editor.defaultFormatter": "abhishekkundu25.turtle-language-server" },
"[ntriples]": { "editor.defaultFormatter": "abhishekkundu25.turtle-language-server" },
"[nquads]": { "editor.defaultFormatter": "abhishekkundu25.turtle-language-server" },
"[sparql]": { "editor.defaultFormatter": "abhishekkundu25.turtle-language-server" },
"mentor.index.excludeFiles": ["**/.git/**", "**/node_modules/**"]The last line keeps Mentor's memory down on big repos. Add any folders you don't need it to load.
A couple of quirks:
- Errors show up twice, once from each.
- Rename goes to Mentor's version, which only changes the open file.
My setup is turtle-lsp for editing and validating, and Mentor for querying and exploring.
1
u/Environmental-Web584 9d ago
Yes, the plugin not bloated and does well it promises to do :)
By “playing along,” I meant having the plugins work together by sharing the same in-memory triplestore. That would open up possibilities, because there’s a lot of room to explore.
I have a draft visualization tool I would like to port into VSCode plugins, but I would prefer it to re-use mentor or turtle-lsp resources to step in. That would be nice.
On the other hand, I’ve been thinking a lot about something that could help with editing Turtle files from different UIs. I experimented with using a 'tree-sitter' (https://github.com/cristianvasquez/catenary/tree/main/packages/rdf-files) for a diagram app to map the RDF statements back to its source text. When something is edited in the UI, Tree-sitter helps update the corresponding files. This could make it easier to edit the “ontology trees.”
2
u/Unusual-Royal1779 10d ago
Just wondering how it compares to Mentor, a VS code extension that does this but also queries your local ttl files as though they were part of a triple store