Skip to content

Commit

Permalink
Added builtin json treesitter language, added more language treesitte…
Browse files Browse the repository at this point in the history
…rr configs
  • Loading branch information
Nimaoth committed Jul 21, 2024
1 parent 6a82d90 commit a0705af
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 10 deletions.
9 changes: 8 additions & 1 deletion absytree.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ requires "https://github.com/Nimaoth/nimtreesitter-api >= 0.1.11"
requires "https://github.com/Nimaoth/nimwasmtime >= 0.1.5"

# Use this to include all treesitter languages (takes longer to download)
requires "https://github.com/Nimaoth/nimtreesitter >= 0.1.5"
requires "https://github.com/Nimaoth/nimtreesitter >= 0.1.6"

# Use these to only install specific treesitter languages. These don't work with the lock file
# requires "https://github.com/Nimaoth/nimtreesitter?subdir=treesitter_nim >= 0.1.3"
Expand Down Expand Up @@ -86,6 +86,13 @@ proc getCommandLineParams(): string =
return ""
return commandLineParams[3..^1].join(" ")

task setup2, "Setup":
exec "nimble setup"
when defined(windows):
cpFile "nimble.paths", "nimble-win.paths"
else:
cpFile "nimble.paths", "nimble-linux.paths"

task buildDesktop, "Build the desktop version":
selfExec fmt"c -o:ast{exe} -d:exposeScriptingApi -d:absytreeBuildWasmtime --passC:-std=gnu11 {getCommandLineParams()} ./src/absytree.nim"
# selfExec fmt"c --passL:advapi32.lib -o:ast{exe} -d:exposeScriptingApi -d:absytreeBuildWasmtime {getCommandLineParams()} ./src/absytree.nim"
Expand Down
6 changes: 1 addition & 5 deletions config.nims
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ switch("d", "wasm3VerboseErrorMessages")

# Configure which treesitter languages are compiled into the editor (ignored on js backend)
# switch("d", "treesitterBuiltins=cpp,nim,agda,bash,c,css,go,html,java,javascript,python,ruby,rust,scala,csharp,zig,haskell")
# switch("d", "treesitterBuiltins=cpp,nim,c,css,html,javascript,python,rust,csharp")
switch("d", "treesitterBuiltins=cpp,c,nim,csharp,rust,python,javascript")
switch("d", "treesitterBuiltins=cpp,c,nim,csharp,rust,python,javascript,json")

# Automatically build wasmtime when compiling the editor
const absytreeBuildWasmtime {.booldefine.} = false
Expand Down Expand Up @@ -91,9 +90,6 @@ when defined(musl):
# Disable system clipboard because it doesn't build with musl right now
switch("d", "enableSystemClipboard=false")

# Remove nim from treesitterBuiltins because it doesn't build with musl right now
switch("d", "treesitterBuiltins=cpp,c,nim,csharp,rust,python,javascript")

else:
switch("d", "ssl")

Expand Down
68 changes: 67 additions & 1 deletion config/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"\.zig$": "zig",
"\.md$": "markdown",
"\.scm$": "query",
"\.toml$": "toml",
"/(vector|string|thread|iostream)$": "cpp",
".+/MSVC/.+/include(/.+?)*/[a-z0-9_]+$": "cpp",
".+/include/c\\+\\+(/.+?)+/[a-z0-9_]+$": "cpp"
Expand Down Expand Up @@ -126,7 +127,24 @@
"ignoreContextLinePrefix": "{"
},
"typescript": {
"treesitter": "tree-sitter/tree-sitter-typescript",
"treesitter": "tree-sitter/tree-sitter-typescript/typescript",
"tabWidth": 4,
"indent": "tab",
"indentAfter": [
":",
"=",
"(",
"{",
"["
],
"lineComment": "//",
"blockComment": [
"/*",
"*/"
]
},
"tsx": {
"treesitter": "tree-sitter/tree-sitter-typescript/tsx",
"tabWidth": 4,
"indent": "tab",
"indentAfter": [
Expand Down Expand Up @@ -257,8 +275,56 @@
"indent": "spaces",
"blockComment": [ "<!--", "-->" ]
},
"scala": {
"treesitter": "tree-sitter/tree-sitter-scala"
},
"regex": {
"treesitter": "tree-sitter/tree-sitter-regex"
},
"ocaml": {
"treesitter": "tree-sitter/tree-sitter-ocaml/grammars/interface"
},
"ocaml": {
"treesitter": "tree-sitter/tree-sitter-ocaml/grammars/ocaml"
},
"ocaml": {
"treesitter": "tree-sitter/tree-sitter-ocaml/grammars/type"
},
"php": {
"treesitter": "tree-sitter/tree-sitter-php/php"
},
"php": {
"treesitter": "tree-sitter/tree-sitter-php/php_only"
},
"ruby": {
"treesitter": "tree-sitter/tree-sitter-ruby"
},
"jsdoc": {
"treesitter": "tree-sitter/tree-sitter-jsdoc"
},
"go": {
"treesitter": "tree-sitter/tree-sitter-go"
},
"ql": {
"treesitter": "tree-sitter/tree-sitter-ql"
},
"bash": {
"treesitter": "tree-sitter/tree-sitter-bash"
},
"css": {
"treesitter": "tree-sitter/tree-sitter-css"
},
"haskell": {
"treesitter": "tree-sitter/tree-sitter-haskell"
},
"agda": {
"treesitter": "tree-sitter/tree-sitter-agda"
},
"toml": {
"treesitter": "tree-sitter-grammars/tree-sitter-toml"
},
"swift": {
"treesitter": "alex-pinkus/tree-sitter-swift"
}
},

Expand Down
16 changes: 16 additions & 0 deletions languages/json/queries/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(pair
key: (_) @string.special.key)

(string) @string

(number) @number

[
(null)
(true)
(false)
] @constant.builtin

(escape_sequence) @escape

(comment) @comment
6 changes: 3 additions & 3 deletions nimble.lock
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,13 @@
}
},
"nimtreesitter": {
"version": "0.1.5",
"vcsRevision": "fb3cb90b534f464f93416813663a7734a0d8d313",
"version": "0.1.6",
"vcsRevision": "8e0af3c1efecfd624a169790d29a8b5e0b11edd6",
"url": "https://github.com/Nimaoth/nimtreesitter",
"downloadMethod": "git",
"dependencies": [],
"checksums": {
"sha1": "05ef2b4a9e16c0e1d20a290ca549dbac21be0012"
"sha1": "27ee351ba63063becf7b2739597dfc778634a4f0"
}
},
"nimwasmtime": {
Expand Down
3 changes: 3 additions & 0 deletions src/text/custom_treesitter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ else:
import treesitter_scala/treesitter_scala/scala
when useBuiltinTreesitterLanguage("typescript"):
import treesitter_typescript/treesitter_typescript/typescript
when useBuiltinTreesitterLanguage("json"):
import treesitter_json/treesitter_json/json

type TSQuery* = ref object
impl: ptr ts.TSQuery
Expand Down Expand Up @@ -611,6 +613,7 @@ proc loadLanguage(languageId: string, config: JsonNode): Future[Option[TSLanguag
of "typescript": tryGetLanguage(treeSitterTypecript)
of "nim": tryGetLanguage(treeSitterNim)
of "zig": tryGetLanguage(treeSitterZig)
of "json": tryGetLanguage(treeSitterJson)
else:
log(lvlWarn, fmt"Failed to init treesitter for language '{languageId}'")
TSLanguage.none
Expand Down

0 comments on commit a0705af

Please sign in to comment.