Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(languages): Lean experimental tree-sitter-lean #1422

Merged
merged 9 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@
path = helix-syntax/languages/tree-sitter-git-rebase
url = https://github.com/the-mikedavis/tree-sitter-git-rebase.git
shallow = true
[submodule "helix-syntax/languages/tree-sitter-lean"]
path = helix-syntax/languages/tree-sitter-lean
url = https://github.com/Julian/tree-sitter-lean
shallow = true
[submodule "helix-syntax/languages/tree-sitter-regex"]
path = helix-syntax/languages/tree-sitter-regex
url = https://github.com/tree-sitter/tree-sitter-regex.git
Expand Down
1 change: 1 addition & 0 deletions book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
| json | ✓ | | ✓ | |
| julia | ✓ | | | `julia` |
| latex | ✓ | | | |
| lean | ✓ | | | `lean` |
| ledger | ✓ | | | |
| llvm | ✓ | ✓ | ✓ | |
| llvm-mir | ✓ | ✓ | ✓ | |
Expand Down
1 change: 1 addition & 0 deletions helix-syntax/languages/tree-sitter-lean
Submodule tree-sitter-lean added at d98426
11 changes: 11 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,17 @@ comment-token = "%"

indent = { tab-width = 4, unit = "\t" }

[[language]]
name = "lean"
scope = "source.lean"
injection-regex = "lean"
file-types = ["lean"]
roots = [ "lakefile.lean" ]
comment-token = "--"
language-server = { command = "lean", args = [ "--server" ] }

indent = { tab-width = 2, unit = " " }

[[language]]
name = "julia"
scope = "source.julia"
Expand Down
15 changes: 15 additions & 0 deletions runtime/queries/lean/folds.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[
(namespace)
(section)

(instance)
(def)
(theorem)
(example)

(product)
(array)
(list)

(string)
] @fold
217 changes: 217 additions & 0 deletions runtime/queries/lean/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
(open
namespace: (identifier) @namespace)
(namespace
name: (identifier) @namespace)
(section
name: (identifier) @namespace)

; Variables
(identifier) @variable
Copy link
Member

@the-mikedavis the-mikedavis Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'll want to move this stanza down to the bottom of the file. The higher in the file, the higher the precedence with helix (it's reversed in neovim), so this stanza will match all identifiers and so the rules on L38-L67 will never match.


;; Identifier naming conventions
((identifier) @type
(#match? @type "^[A-Z]"))

(arrow) @type
(product) @type

;; Declarations

[
"abbrev"
"def"
"theorem"
"constant"
"instance"
"axiom"
"example"
"inductive"
"structure"
"class"

"deriving"

"section"
"namespace"
] @keyword

(attributes
(identifier) @function)

(abbrev
name: (identifier) @type)
(def
name: (identifier) @function)
(theorem
name: (identifier) @function)
(constant
name: (identifier) @type)
(instance
name: (identifier) @function)
(instance
type: (identifier) @type)
(axiom
name: (identifier) @function)
(structure
name: (identifier) @type)
(structure
extends: (identifier) @type)

(where_decl
type: (identifier) @type)

(proj
name: (identifier) @field)

(binders
type: (identifier) @type)

["if" "then" "else"] @keyword.control.conditional

["for" "in" "do"] @keyword.control.repeat

(import) @include

; Tokens

[
"!"
"$"
"%"
"&&"
"*"
"*>"
"+"
"++"
"-"
"/"
"::"
":="
"<"
"<$>"
"<*"
"<*>"
"<="
"<|"
"<|>"
"="
"=="
"=>"
">"
">"
">="
">>"
">>="
"@"
"^"
"|>"
"|>."
"||"
"←"
"→"
"↔"
"∘"
"∧"
"∨"
"≠"
"≤"
"≥"
] @operator

[
"@&"
] @operator

[
"attribute"
"by"
"end"
"export"
"extends"
"fun"
"let"
"have"
"match"
"open"
"return"
"universe"
"variable"
"where"
"with"
"λ"
(hash_command)
(prelude)
(sorry)
] @keyword

[
"prefix"
"infix"
"infixl"
"infixr"
"postfix"
"notation"
"macro_rules"
"syntax"
"elab"
"builtin_initialize"
] @keyword

[
"noncomputable"
"partial"
"private"
"protected"
"unsafe"
] @keyword

[
"apply"
"exact"
"rewrite"
"rw"
"simp"
(trivial)
] @keyword

[
"catch"
"finally"
"try"
] @exception

((apply
name: (identifier) @exception)
(#match? @exception "throw"))

[
"unless"
"mut"
] @keyword

[(true) (false)] @boolean

(number) @constant.numeric.integer
(float) @constant.numeric.float

(comment) @comment
(char) @character
(string) @string
(interpolated_string) @string
; (escape_sequence) @string.escape

; Reset highlighing in string interpolation
(interpolation) @none

(interpolation
"{" @punctuation.special
"}" @punctuation.special)

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

["|" "," "." ":" ";"] @punctuation.delimiter

(sorry) @error

;; Error
(ERROR) @error
2 changes: 2 additions & 0 deletions runtime/queries/lean/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
((comment) @markdown
(#offset! @markdown 0 3 0 -2))
3 changes: 3 additions & 0 deletions runtime/queries/lean/locals.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(module) @scope
(namespace) @scope
(section) @scope