helix icon indicating copy to clipboard operation
helix copied to clipboard

Add support for janet language

Open KittyBorgX opened this issue 2 years ago • 1 comments

Resolves : #4574

KittyBorgX avatar Nov 06 '22 14:11 KittyBorgX

I'm sorry for the force pushes 😅 I forgot to add a few things and I didn't want to stack commits, so I rebased and pushed again.

KittyBorgX avatar Nov 06 '22 15:11 KittyBorgX

Since Janet is a lisp and looks a lot like clojure, I wonder if we can re-use the clojure or scheme parsers and only write new queries?

the-mikedavis avatar Nov 08 '22 01:11 the-mikedavis

Since Janet is a lisp and looks a lot like clojure, I wonder if we can re-use the clojure or scheme parsers and only write new queries?

Does "new queries" mean injections and highlights in runtime/queries ? I'm sorry, I'm kind of new to this repo and I'll take some time to absorb and understand stuff 😅

KittyBorgX avatar Nov 08 '22 03:11 KittyBorgX

Yep correct. To share the same parser you will need to change the languages.toml entry to remove the new [[grammar]] sub-table and add a grammar = "clojure" or grammar = "scheme" entry to the new [[language]] sub-table. Then it will need queries in runtime/queries/janet

the-mikedavis avatar Nov 08 '22 13:11 the-mikedavis

Gotcha. Although, I do have a concern. Looking further into the syntax of all the 3 languages [ janet, clojure and scheme ], there seems to be quite a bit of difference between the 3 of them with respect to keywords and the general mechanics of the languages. Janet does sort of represent scheme and clojure in a way but I feel that it is different enough to have its own grammar (since reusing grammar may raise questionable results and/or errors in the language later?)

Having said this, I could very well be wrong and I'm happy to correct myself if I am. If you feel that the grammar of clojure or scheme can be resused, then let me know, I'll make the necessary changes and add a new commit.

KittyBorgX avatar Nov 08 '22 14:11 KittyBorgX

@the-mikedavis [Sorry for the mention!] Any update on this PR?

KittyBorgX avatar Nov 10 '22 15:11 KittyBorgX

Hmm yeah, we might as well pull in a new grammar for this - when compiled, this parser is only 174KB. We can work on deduplicating grammars later, maybe we'll need to write a new grammar that's general enough to be used for any lisp.

the-mikedavis avatar Nov 11 '22 14:11 the-mikedavis

Hmm yeah, we might as well pull in a new grammar for this - when compiled, this parser is only 174KB. We can work on deduplicating grammars later, maybe we'll need to write a new grammar that's general enough to be used for any lisp.

Alright! Is there any pending work to be done on my end? (I'm really sorry for going back and forth over this PR) 😅

KittyBorgX avatar Nov 12 '22 13:11 KittyBorgX

Yep this still needs runtime/queries/janet/highlights.scm queries https://docs.helix-editor.com/master/guides/adding_languages.html#queries

the-mikedavis avatar Nov 12 '22 14:11 the-mikedavis

@the-mikedavis Is it alright if I reuse https://github.com/helix-editor/helix/blob/master/runtime/queries/clojure/highlights.scm with a bit of modification for janet atm? I know I'd told against it but I'm not finding enough time to roll out a new one for janet.

KittyBorgX avatar Nov 15 '22 15:11 KittyBorgX

Yep that would be fine as long as the syntax is close enough. You can set the grammar to use the clojure one and then inherit the highlights:

# /languages.toml

[[language]]
name = "janet"
# .. other stuff ..
grammar = "clojure"

then in runtime/queries/janet/highlights.scm:

; inherits: clojure

to use all of the clojure highlight patterns, or just use the patterns that are needed

the-mikedavis avatar Nov 16 '22 17:11 the-mikedavis

Thanks! Btw, How do i resolve the merge conflict? 😅 Do I just pull the latest upstream changes and commit everything again?

KittyBorgX avatar Nov 17 '22 01:11 KittyBorgX

You can pull down the master branch from this repo and git merge against that:

git remote add upstream https://github.com/helix-editor/helix
git fetch upstream
git merge upstream/master

(Or if you meant which side to take in the conflict: you can add both new entries so that you have

[[language]]
name = "janet"
# ...

[[grammar]]
name = "janet"
# ...

[[language]]
name = "bicep"
# ...

[[grammar]]
name = "bicep"

)

the-mikedavis avatar Nov 18 '22 03:11 the-mikedavis

(first off, im really sorry for the delay) @the-mikedavis I tried merging the conflicts but its only gotten worse. I want to complete the changes you suggested in this PR. I get "Your local changes to the following files would be overwritten by merge". I could squash and rebase to head and redo my changes which would erase my commits and I can just make a new one while still being part of this pr. Any advice?

KittyBorgX avatar Feb 07 '23 14:02 KittyBorgX

It sounds like you have uncommitted changes in your local branch. You should commit them first before running git merge upstream/master

howard36 avatar Feb 07 '23 15:02 howard36

Since there aren't a lot of lines changed, starting from scratch like you said might be the easiest option. You can also try committing the local changes before the merge as @Plasma-Vortex says or stashing: git stash before merging and then git stash pop afterwards.

the-mikedavis avatar Feb 07 '23 22:02 the-mikedavis