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

Add support for webassembly text format #4040

Merged
merged 3 commits into from
Oct 1, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
| vala | ✓ | | | `vala-language-server` |
| verilog | ✓ | ✓ | | `svlangserver` |
| vue | ✓ | | | `vls` |
| wat | ✓ | | | |
| wgsl | ✓ | | | `wgsl_analyzer` |
| xit | ✓ | | | |
| yaml | ✓ | | ✓ | `yaml-language-server` |
Expand Down
22 changes: 22 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1781,3 +1781,25 @@ language-server = { command = "bass", args = ["--lsp"] }
[[grammar]]
name = "bass"
source = { git = "https://github.com/vito/tree-sitter-bass", rev = "501133e260d768ed4e1fd7374912ed5c86d6fd90" }

[[language]]
name = "wat"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it would make more sense to call this webassembly, but it seems that this name determines the symbol that will be imported from the grammer dynamic library, and that's fixed to tree_sitter_wat.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@the-mikedavis Do you think it'd be worth separating a human-readable name from the symbol name for tree sitter? I could do that in a subsequent PR.

Copy link
Member

Choose a reason for hiding this comment

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

There's an issue along those lines: #3164

It would only be a cosmetic improvement for the file-type statusline element though

scope = "source.webassembly"
comment-token = ";;"
file-types = ["wat"]
roots = []

[[grammar]]
name = "wat"
source = { git = "https://github.com/wasm-lsp/tree-sitter-wasm", rev = "2ca28a9f9d709847bf7a3de0942a84e912f59088", subpath = "wat" }

[[language]]
name = "wast"
scope = "source.webassembly"
Copy link
Member

Choose a reason for hiding this comment

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

The scopes are the same between these two. I think wat could be source.webassembly.text but I'm not sure what to use for wast

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tentatively set this to source.wat, which is the scope used by the main extensions in Sublime and VSCode. But not strong opinions here. If we were to follow your suggestion, we could set source.webassembly.script?

Copy link
Member

Choose a reason for hiding this comment

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

We could use source.webassembly.text & source.webassembly.script. Since Sublime and VSCode use these though, I would prefer to also use source.wat & source.wast.

comment-token = ";;"
file-types = ["wast"]
roots = []

[[grammar]]
name = "wast"
source = { git = "https://github.com/wasm-lsp/tree-sitter-wasm", rev = "2ca28a9f9d709847bf7a3de0942a84e912f59088", subpath = "wast" }
21 changes: 21 additions & 0 deletions runtime/queries/wast/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
; inherits: wat

[
"assert_return"
"assert_trap"
"assert_exhaustion"
"assert_malformed"
"assert_invalid"
"assert_unlinkable"
"assert_trap"

"invoke"
"get"

"script"
"input"
"output"

"binary"
"quote"
] @keyword
17 changes: 17 additions & 0 deletions runtime/queries/wat/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
["module" "func" "param" "result" "type" "memory" "elem" "data" "table" "global"] @keyword

["import" "export"] @keyword.control.import

["local"] @keyword.storage.type

[(name) (string)] @string

(identifier) @function

[(comment_block) (comment_line)] @comment

[(nat) (float) (align_offset_value)] @constant.numeric.integer

(value_type) @type
jrvidal marked this conversation as resolved.
Show resolved Hide resolved

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