9 releases

new 0.1.15 Dec 13, 2024
0.1.14 Dec 12, 2024
0.1.12 Nov 14, 2024
0.1.9 Sep 25, 2024

#957 in Database interfaces

Download history 290/week @ 2024-09-14 190/week @ 2024-09-21 25/week @ 2024-09-28 3/week @ 2024-10-05 6/week @ 2024-10-12 1/week @ 2024-10-19 203/week @ 2024-11-09 46/week @ 2024-11-16 7/week @ 2024-11-23 264/week @ 2024-12-07

370 downloads per month

MIT license

130KB
3.5K SLoC

Fichu

A blazingly fast formatter and language server for SPARQL, written in Rust 🦀.

Getting Started

Installation

Fichu is availible on PyPi:

pipx install fichu

Or on crate.io:

cargo install fichu

You can also build it from source:

git clone https://github.com/IoannisNezis/sparql-language-server.git
cd sparql-language-server
cargo build --release

Usage

To run Fichu as formatter run:

fichu format <PATH>

To run Fichu as lanugage server run:

fichu server

This will create a language server listening on stdio.

Connect to Neovim

After you installed the language server, add this to your init.lua:

vim.api.nvim_create_autocmd({ 'FileType' }, {
  desc = 'Connect to sparql-language-server',
  pattern = { 'sparql' },
  callback = function()
    vim.lsp.start {
      name = 'fichu',
      cmd = { 'fichu', 'server' },
      root_dir = vim.fn.getcwd(),
      on_attach = function(client, bufnr)
        vim.keymap.set('n', '<leader>f', vim.lsp.buf.format, { buffer = bufnr, desc = 'LSP: ' .. '[F]ormat' })
      end,
    }
  end,
})

Open a .rq file and check that the buffer is attached to th server:

:checkhealth lsp

Configure keymaps in on_attach function.

Capabilities

Formatting

Status: Full support

Formats SPARQL queries to ensure consistent and readable syntax. Customizable options to align with preferred query styles are also implemented.

Diagnostics

Status: Partial support

Currently provides a few basic diagnostics for syntax errors and simple issues in SPARQL queries. Further enhancements are planned to cover a broader range of semantic and logic-related diagnostics.

Currently provided diagnostics:

  • unused namespace (warning): A declared namespace is not used
  • undefined namespace (error): A used namespace is not declared

Planed diagnostics:

  • path compresion possible (info): A declared namespace is not used

Completion

Status: Rudimentary

Basic auto-completion for SPARQL keywords and variables. Currently not context aware.
Future improvements will expand suggestions to include functions, predicates, and custom completions based on query context.

Code Actions

Status: Planed

Future support for code actions, such as quick fixes and refactoring suggestions, to improve productivity and code quality in SPARQL development.

Planed code actions:

  • Consolidate property paths
  • Refactor iris into namespaces
  • Sort Prefixes

Configuration

Fichu can be configured through a fichu.toml or fichu.yml file.

Here is the full default configuration

[format]
align_predicates = false
align_prefixes = false
separate_prolouge = true
capitalize_keywords = true
insert_spaces = true
tab_size = 2
where_new_line = true

use in web

If you want to connect from a web-based-editor, you can use this package as well.
For this purpouse this can be compiled to wasm and is availible on npm:

npm i @ioannisnezis/sparql-language-server

You will have to wrap this in a Web Worker and provide a language server client. There will be more documentation on this in the future...

Demo

In the mean time, check out the demo.

Dependencies

~17–29MB
~452K SLoC