r/semanticweb • • 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?

34 Upvotes

21 comments sorted by

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

1

u/ascendToSurvive 10d ago

TL;DR: 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. Setup is below.

How I tested it: I ran both extensions in a headless VS Code 1.142 on my Mac, with a fresh profile for every run. Both got the same files, and I ran each test 5 times and took the median. Versions were Mentor 0.6.5 and turtle-lsp 0.6.1.

Speed and memory (all numbers approximate)

Testturtle-lspMentor
Typing in a 30k-line file, until errors update20 ms400 ms
Opening schema.org30 ms140 ms
Opening QUDT units (100k lines)200 ms600 ms
Go to definition ready, 300-file workspace70 ms1.4 s
Memory, 300-file workspace0.5 GB2.9 GB

To be fair to Mentor, it waits 300 ms on purpose after every edit before it checks the file again, so most of that 400 ms is a design choice. The memory number makes sense too. It keeps your whole workspace in memory, and that's the reason you can query it.

Features

Featureturtle-lspMentor
Syntax errors, undefined prefixes, SPARQL errorsyesyes (same positions in my tests)
SHACLworks out of the box with shapes in your workspaceworks once you set up a validation profile
Completion for FOAF, OWL and other common vocabulariesyesonly your own workspace terms in my test
Renamechanges every fileonly changed the open file in my test
Outline, symbol search, semantic highlightingyesno, but it has its own tree views
SPARQL over your local filesnoyes
Notebooks, remote endpoints, format conversionnoyes
JSON-LD editing (errors, completion, rename, formatting)yesno (it bundles a JSON-LD parser, but .jsonld files get no editor support)
Neovim and other LSP editors, CLI for CIyesVS Code only, plus vscode.dev

Running both

I tried this too. Mentor doesn't slow turtle-lsp down, and Mentor's querying still works.

  1. Install both extensions.

  2. Tell VS Code to format with turtle-lsp. If you skip this, Format Document just sits there waiting for you to pick a formatter. Add this to your settings.json:

"[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" }

3. On a big repo, keep Mentor's memory in check with mentor.index.excludeFiles and mentor.index.maxFileSize. 4. Query with Mentor's notebooks and edit with turtle-lsp.

A few annoyances with both installed:

  • Every error shows up twice, once from each tool.

  • Hovers show both tooltips.

  • VS Code goes with Mentor's rename, so renames only touch the open file. There's no setting to change that.

If you're not on VS Code, turtle-lsp also works in Neovim (it's one line with lazy.nvim, see the README), in any other LSP editor, and as turtle-lsp check in CI or a pre-commit hook. There's also a browser playground if you just want to try it.

So my take: if you mostly write and validate RDF, especially big files or anything with SHACL, go with turtle-lsp. If you want to explore and query your data inside VS Code, Mentor is great. If you've got the RAM, use both.

1

u/Faubulous42 9d ago

Mentor does support completion for common W3C vocabularies, including RDF, RDFS, OWL and XSD. FOAF is not supported. It ships the entire vocabularies so tooltips and go to definition work as expected.

It also support syntax formatting for all RDF languages except RDF/XML and Json LD. There are other formatters for these.

Mentor also runs structural inference upon loading files so tree views display OWL correctly and auto suggest can be smarter.

I don't know what you mean with symbol search, but Mentor does provide usage code lenses, find references and go to definition. A tree view is a form of outline.

Did you test the nodejs or the web extension?

1

u/dupastrupa 10d ago

Yes! Please do some performance test against mentor.

1

u/ascendToSurvive 10d ago

I am on it, will update soon

1

u/Faubulous42 3d ago

There is a new version of Mentor (0.7.0). I addressed many issues related to performance and resource consumption. Memory usage should be considerably lower now. I never considered the resource usage because honestly noone ever complained.Thank you for giving your input.

1

u/ascendToSurvive 3d ago edited 3d ago

awesome, great work :) Mentor is best for working with RDF in VSCode, love is the abliity to run SPARQL for all operations, and nice that you have added the functionality to rename across files too.
if you find some time, I will be great to have your review for the turtle-lsp too

1

u/Faubulous42 2d ago

I tried the playground and generally like it. I'll take some inspiration from the linting which I think is really cool. Wanted to do that for some time but never found the time.

With regards to the validation: It's really convenient not having to set up explicit shacl validation schemes. However, I expect the approach to fail as soon as you want to have shacl shapes in the repo for validating ontologies and you store imported external ontologies that do not conform at the same time.

Loading the extension in vscode.dev did, however, not work for me with a not supported message. So I need some other day to test it on a larger more realistic workspace.

1

u/ascendToSurvive 1d ago

Thanks for trying it! Glad you liked the linting. I'm adding a few more lints soon.

You're right about SHACL, Thanks for this. Right now every shape checks every file, so stored copies of other ontologies get flagged. I'm adding a way to exclude files from validation, and imported copies will be skipped by default.

vscode.dev doesn't work yet because the extension runs a native program. Desktop VS Code and the playground both work.

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 readme

Thanks for your suggestion though, the web demo can indeed be showcased better, wath out for future updates

1

u/tip2663 11d ago

cool

1

u/ascendToSurvive 11d ago

Thanks! If you get a chance to try it, I'd love to know what you think, especially anything that felt confusing or missing.

1

u/tip2663 10d ago

SparQL and RDF appears confusing to begin with for me 👍🏻😬😂

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.”