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 Sourcepawn language support #9304

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Sarrus1
Copy link

@Sarrus1 Sarrus1 commented Jan 10, 2024

This PR adds a tree-sitter parser and queries for the Sourcepawn programming language.


(array_indexed_access) @punctuation.bracket

(escape_sequence) @string.escape
Copy link
Member

Choose a reason for hiding this comment

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

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

the captures should line up with https://docs.helix-editor.com/master/themes.html#syntax-highlighting

name: (identifier) @type)

(enum_struct_field
name: (identifier) @variable.member)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
name: (identifier) @variable.member)
name: (identifier) @variable.other.member)

Comment on lines +249 to +253
(int_literal) @number

(char_literal) @character

(float_literal) @number.float
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
(int_literal) @number
(char_literal) @character
(float_literal) @number.float
(int_literal) @constant.numeric.integer
(char_literal) @constant.character
(float_literal) @constant.numeric.float


(concatenated_string) @punctuation.delimiter

(bool_literal) @boolean
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
(bool_literal) @boolean
(bool_literal) @constant.builtin.boolean

Comment on lines +269 to +283
"return" @keyword.return
[
"if"
"else"
"case"
"default"
"switch"
] @keyword.conditional
[
"do"
"while"
"for"
"continue"
"break"
] @keyword.repeat
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"return" @keyword.return
[
"if"
"else"
"case"
"default"
"switch"
] @keyword.conditional
[
"do"
"while"
"for"
"continue"
"break"
] @keyword.repeat
"return" @keyword.control.return
[
"if"
"else"
"case"
"default"
"switch"
] @keyword.control.conditional
[
"do"
"while"
"for"
"continue"
"break"
] @keyword.control.repeat

"static"
"stock"
"forward"
] @type.qualifier
Copy link
Member

Choose a reason for hiding this comment

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

The trailing newline is missing on a few files: highlights.scm, injections.scm and languages.toml

(identifier) @variable
; Assume all-caps names are constants
((identifier) @constant
(#lua-match? @constant "^[A-Z][A-Z0-9_]+$"))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
(#lua-match? @constant "^[A-Z][A-Z0-9_]+$"))
(#match? @constant "^[A-Z][A-Z0-9_]+$"))

#lua-match? is specific to neovim

Comment on lines +1 to +4
(identifier) @variable
; Assume all-caps names are constants
((identifier) @constant
(#lua-match? @constant "^[A-Z][A-Z0-9_]+$"))
Copy link
Member

Choose a reason for hiding this comment

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

These two matches on (identifier) should be at the bottom of the file rather than the top. In neovim the precedence of the queries is the opposite of what it is in Helix (and tree-sitter-cli): in Helix the higher patterns in the file take precedence over the lower ones. So as-written these (identifier) matches will match before any of the patterns below that also match (identifier) like on L7 or L10. You will also want to swap the order of these two matches since the one with the #match? is more specific (so it should be higher precedence) than the one on L1.

Comment on lines +47 to +49
(preproc_include) @keyword.import

(preproc_tryinclude) @keyword.import
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
(preproc_include) @keyword.import
(preproc_tryinclude) @keyword.import
(preproc_include) @keyword.control.import
(preproc_tryinclude) @keyword.control.import

@the-mikedavis the-mikedavis added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. A-language-support Area: Support for programming/text languages labels Jan 11, 2024
@Sarrus1
Copy link
Author

Sarrus1 commented Jan 20, 2024

Hello, thank you very much for the feedback.

I should have tested this PR before submitting it, I naively thought that helix queries were fully compatible with the new nvim-tree-sitter queries. Sorry about that.

I will convert it to draft while I fix it.

Is there a way to "easily" test queries?

@Sarrus1 Sarrus1 marked this pull request as draft January 20, 2024 09:15
@the-mikedavis
Copy link
Member

We don't have test cases but you can cargo run in the Helix directory on an example file to check your work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-language-support Area: Support for programming/text languages S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants