IoannisNezis / sparql-language-server

A Sparql formatter and language server, written in Rust
MIT License
5 stars 0 forks source link

More consistent indentation for predicate/objects attached to the same subject #3

Open vemonet opened 6 days ago

vemonet commented 6 days ago

Hi, currently the formatting of SPARQL queries aligns predicates/objects based on the length of the subject, e.g.:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX up:   <http://purl.uniprot.org/core/>
SELECT DISTINCT ?diseaseLabel ?humanProtein ?hgncSymbol ?orthologRatProtein ?orthologRatGene WHERE {
  ?humanProtein a up:Protein ;
                up:organism/up:scientificName 'Homo sapiens' ;
                up:annotation ?diseaseAnnotation ;
                rdfs:seeAlso ?hgnc .
  ?hgnc up:database <http://purl.uniprot.org/database/HGNC> ;
        rdfs:comment ?hgncSymbol .
  ?diseaseAnnotation a up:Disease_Annotation ;
                     up:disease ?disease .
  ?disease a up:Disease ;
           skos:prefLabel ?diseaseLabel .
}

Would it be possible to consider just going to the line and adding a regular indent? e.g.

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX up: <http://purl.uniprot.org/core/>
SELECT DISTINCT ?diseaseLabel ?humanProtein ?hgncSymbol ?orthologRatProtein ?orthologRatGene
WHERE {
  ?humanProtein a up:Protein ;
    up:organism/up:scientificName 'Homo sapiens' ;
    up:annotation ?diseaseAnnotation ;
    rdfs:seeAlso ?hgnc .
  ?hgnc up:database <http://purl.uniprot.org/database/HGNC> ;
    rdfs:comment ?hgncSymbol .
  ?diseaseAnnotation a up:Disease_Annotation ;
    up:disease ?disease .
  ?disease a up:Disease ;
    skos:prefLabel ?diseaseLabel.
}

I know it might seems like "a personal preference" but I think their are a few objective arguments for going for the regular indent approach:

IoannisNezis commented 6 days ago

Hey @vemonet, fair point. To be perfectly honest with you, i mainly implemented this to test tree-sitter queries and thought it was "cool".

One of the next things i would like to do is create a user-configuration. I'll add "align predicates" as a configurable option. Then we can argue about what the default should be :) Are there already other things about the formatter that you would like to have customizable?

vemonet commented 6 days ago

Yes it is quite cool indeed :) I'll make my list to Santa Claus then!

I don't know if it is worth to go to configuration but WHERE { should go to a newline imo

For configuration I could see these maybe:

fyi I tried pipx install fichu (cool name!) and currently getting:

fichu format ./query.rq
thread 'main' panicked at src/main.rs:39:6:
called `Result::unwrap()` on an `Err` value: No such file or directory (os error 2)
IoannisNezis commented 5 days ago

Nice, thanks for the input!

Some of the suggestions, like the conversion of URIs (thanks for the CURIEs hint btw, looks awesome), sound more like Code Actions to me.

I think i want formatting only to "move" the tokens and not add, delete or reorder anything (but whitespace). More complex refactor operations would then be split into separate code actions.

fyi I tried pipx install fichu (cool name!) and currently getting:

fichu format ./query.rq
thread 'main' panicked at src/main.rs:39:6:
called `Result::unwrap()` on an `Err` value: No such file or directory (os error 2)

The bug should have been fixed in 0.1.7.