helix-editor / helix

A post-modern modal text editor.
https://helix-editor.com
Mozilla Public License 2.0
33.13k stars 2.46k forks source link

Fennel language support #3846

Open gasacchi opened 2 years ago

gasacchi commented 2 years ago

Hi, how to add Fennel language support? at least syntax highlighting, i came across tree-sitter-fennel and basic fennel lsp fennel-ls lsp completion work fine but i cannot build tree-sitter-fennel

try to setup locally as adding language

my languages.toml:

# Fennel language support
[[language]]
name = "fennel"
scope = "source.fennel"
injection-regex = "fennel"
file-types = ["fnl"]
roots = []
comment-token = ";;"
language-server = { command = "fennel-ls" }
indent = { tab-width = 2, unit = "  " }

[language.auto-pairs]
'(' = ')'
'{' = '}'
'[' = ']'
'"' = '"'

[[grammar]]
name = "fennel"
source = { path = "/home/gasacchi/Dev/fork/tree-sitter-fennel" }

and try to helix -g build the output:

Building 108 grammars
107 grammars already built
1 grammars failed to build
        Failure 0/1: Parser compilation failed.
Stdout:
Stderr: In file included from /home/gasacchi/Dev/fork/tree-sitter-fennel/src/parser.c:1:
/home/gasacchi/Dev/fork/tree-sitter-fennel/src/parser.c: In function ‘ts_lex_keywords’:
/home/gasacchi/Dev/fork/tree-sitter-fennel/src/tree_sitter/parser.h:136:8: warning: variable ‘eof’ set but not used [-Wunused-but-set-variable]
  136 |   bool eof = false;             \
      |        ^~~
/home/gasacchi/Dev/fork/tree-sitter-fennel/src/parser.c:3069:3: note: in expansion of macro ‘START_LEXER’
 3069 |   START_LEXER();
      |   ^~~~~~~~~~~
/usr/bin/ld: cannot open output file /var/lib/helix/runtime/grammars/fennel.so: Permission denied
collect2: error: ld returned 1 exit status

even with sudo helix -g bulid

Building 107 grammars
107 grammars already built

it ignore fennel tree-sitter, is there any mistake on my end? Thanks

Ordoviz commented 2 years ago

Did you install Helix with a package manager? Try cp -r /var/lib/helix/runtime ~/.config/helix/ and launch Helix with RUNTIME=~/.config/helix/runtime. To make highlighting work, you will also have to write a ~/.config/helix/runtime/queries/fennel/highlights.scm file.

gasacchi commented 2 years ago

Did you install Helix with a package manager? Try cp -r /var/lib/helix/runtime ~/.config/helix/ and launch Helix with RUNTIME=~/.config/helix/runtime. To make highlighting work, you will also have to write a ~/.config/helix/runtime/queries/fennel/highlights.scm file.

it works thanks 😄

Ordoviz commented 2 years ago

There is a pull request for Fennel support: #3851

icefoxen commented 1 year ago

The PR is stalled 'cause we already have tree-sitter-scheme (which might be weirdly huge?) and people were wondering if it would be preferable to have a single "lisp mode" or "sexpr mode" that handles any Lisp. I don't think that's a good idea 'cause lisps don't actually all have the same syntax... But I was thinking we might be able to do a "clojureish mode" that is Good Enough for Clojure, Fennel and Janet, and then a "True Lisp Mode" for Scheme, CL, LFE, etc. I want to try this out and see how well this works, no idea how easy it would be or not be to add partially-overlapping languages like that.

If I don't have a proof of concept in two months though assume I've gotten distracted by shiny objects and wandered off.

Mehgugs commented 1 year ago

I dont think that is a good idea at all. Imagine we had a grammar for "c-like" languages, maybe you can develop an lsp that provides some basic autocomplete. You wouldn't want that to be used as your editor's grammar for typescript.

offsetcyan commented 3 months ago

Unifying the tree-sitter grammar among all Lisps is the kind of yak shaving I would expect from lispers but really a blocker on having adequate support for each of them. I here to +1 any kind of upstream support for Fennel.

atomicptr commented 3 months ago

I feel like this is silly as a blocker for adding Fennel esp. considering this was not a problem for janet https://github.com/helix-editor/helix/pull/9247. I'm not sure if merging all lisps into one grammar is a good idea because most of them do have some special quirks.

The sentiment might have changed around this though (considering the janet one was merged without discussions) and it might be worthwhile submitting a new PR for this.

I played around with the scheme and Clojure (which is much closer to Fennel than scheme) grammar but decided in the end to just use the fennel one since that works best.

For completions sake, this is my current config that works quite well:

xdg-config/helix/languages.toml

[language-server.fennel-ls]
command = "fennel-ls"

[[language]]
name = "fennel"
scope = "source.fnl"
injection-regex = "(fennel|fnl)"
file-types = ["fnl"]
shebangs = ["fennel"]
roots = []
comment-token = ";"
indent = { tab-width = 2, unit = "  " }
formatter = { command = "fnlfmt", args = ["-"] }
language-servers = [ "fennel-ls" ]
grammar = "fennel"

[[grammar]]
name = "fennel"
source = { git = "https://github.com/travonted/tree-sitter-fennel", rev = "15e4f8c417281768db17080c4447297f8ff5343a"}

xdg-config/helix/runtime/queries/fennel/highlights.scm (from: https://github.com/helix-editor/helix/pull/3851)

(comment) @comment

[ "(" ")" "{" "}" "[" "]" ] @punctuation.bracket

[ ":" ":until" "&" "&as" "?" ] @punctuation.special

(nil) @constant.builtin
(vararg) @punctuation.special

(boolean) @constant.builtin.boolean
(number) @constant.numeric

(string) @string
(escape_sequence) @constant.character.escape

((symbol) @variable.builtin
 (#match? @variable.builtin "^[$]"))

(binding) @symbol

[ "fn" "lambda" "hashfn" "#" ] @keyword.function

(fn name: [
  (symbol) @function
  (multi_symbol (symbol) @function .)
])

(lambda name: [
  (symbol) @function
  (multi_symbol (symbol) @function .)
])

(multi_symbol
  "." @punctuation.delimiter
  (symbol) @variable.other.member)

(multi_symbol_method
  ":" @punctuation.delimiter
  (symbol) @function.method .)

[ "for" "each" ] @keyword.control.repeat
((symbol) @keyword.control.repeat
 (#eq? @keyword.control.repeat
  "while"))

[ "match" ] @keyword.control.conditional
((symbol) @keyword.control.conditional
 (#match? @keyword.control.conditional "^(if|when)$"))

[ "global" "local" "let" "set" "var" "where" "or" ] @keyword
((symbol) @keyword
 (#match? @keyword
  "^(comment|do|doc|eval-compiler|lua|macros|quote|tset|values)$"))

((symbol) @keyword.control.import
 (#match? @keyword.control.import
  "^(require|require-macros|import-macros|include)$"))

[ "collect" "icollect" "accumulate" ] @function.macro
((symbol) @function.macro
 (#match? @function.macro
  "^(->|->>|-\\?>|-\\?>>|\\?\\.|doto|macro|macrodebug|partial|pick-args|pick-values|with-open)$"))

; Lua builtins
((symbol) @constant.builtin
 (#match? @constant.builtin
  "^(arg|_ENV|_G|_VERSION)$"))

((symbol) @function.builtin
 (#match? @function.builtin
  "^(assert|collectgarbage|dofile|error|getmetatable|ipairs|load|loadfile|loadstring|module|next|pairs|pcall|print|rawequal|rawget|rawlen|rawset|require|select|setfenv|setmetatable|tonumber|tostring|type|unpack|warn|xpcall)$"))

(list . (symbol) @function)
(list . (multi_symbol (symbol) @function .))
(symbol) @variable