-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Recognize .ispc
extension as CPP
#8678
base: master
Are you sure you want to change the base?
Conversation
ISPC has a language server and is pending a release https://togithub.com/ispc/ispc/issues/1605#issuecomment-1771833547 |
Let's focus this PR on using tree-sitter-ispc and the ispc language server. For those looking for some basic syntax highlighting for ispc in the mean time, the current change can be added to your custom language config: # ~/.config/helix/languages.toml
[[language]]
name = "cpp"
file-types = ["cc", "hh", "c++", "cpp", "hpp", "h", "ipp", "tpp", "cxx", "hxx", "ixx", "txx", "ino", "C", "H", "cu", "cuh", "cppm", "h++", "ii", "inl", "ispc", { suffix = ".hpp.in" }, { suffix = ".h.in" }] |
Imported the grammar from https://github.com/fab4100/tree-sitter-ispc. Somewhat strangely some of the queries were removed in tree-sitter-grammars/tree-sitter-ispc@0197076 and have been moved into https://github.com/nvim-treesitter/nvim-treesitter/tree/7da3cb6323d1e1fbfc4d7dc05cac74946458b8a0/queries/ispc. I have imported the latter and should probably update the commit hash to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The queries will need to be adjusted - neovim queries don't work out of the box for Helix. For example some captures need to be adjusted to match the ones we use (https://docs.helix-editor.com/master/themes.html#syntax-highlighting) like @repeat
should be @keyword.control.repeat
. #lua-match?
will need to be replaced with an equivalent #match?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two sets of queries exist because neovim has its own query engine with some extensions as mentioned above. Unfortunately there is no common ground for query syntax at the moment. The queries in the ISPC parser repo are very basic and minimal (based off the C language parser). As mentioned, you will need to adjust and modify for your needs. If you have additions that will work for general queries (without custom engine syntax) I am happy to add them in the ISPC parser repo. Both query sets (in the ISPC parser repo and nvim-treesitter) are currently maintained (the one in nvim-treesitter more actively however).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll unfortunately be unavailable for the next month but hope to pick this back up after that and finalize this PR!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For indents see https://docs.helix-editor.com/master/guides/indent.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For locals we follow tree-sitter: https://tree-sitter.github.io/tree-sitter/syntax-highlighting#local-variables
So these should be changed to only use the @local.definition
, @local.reference
and @local.scope
captures
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for these pointers! I've quickly cobbled some changes together that I was able to debug using :treesitter
commands and validate visually in the editor, and now understand a lot better how these are supposed to work.
There's still more to do, and I should likely also contribute the C changes separately, which enable parameter highlights for int x[10]
and int **x
(only int *x
was supported).
Since there's no locals.scm
for C yet, and this PR adds a bunch of them that apply to C, should I move the base of it to c/locals.scm
and have an ; Inherits: c
in the ISPC file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep feel free to add some locals for C and re-use them if possible, that should be a nice improvement to C highlighting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Factored out to a separate file 👍
031156c
to
7871b57
Compare
Intel's Implicit SIMD Program Compiler (https://ispc.github.io/) files are "a variant of the C programming language" with support for templates and references.
…sitter/tree/7da3cb6323d1e1fbfc4d7dc05cac74946458b8a0/queries/ispc instead These seem to have been removed from the main repo in: tree-sitter-grammars/tree-sitter-ispc@0197076
Intel's Implicit SIMD Program Compiler (https://ispc.github.io/) files are "a variant of the C programming language" with support for templates and references.
Unfortunately they also use some custom keywords and constructs that make this language unsuitable for
clangd
, but the CPP grammar works well enough for most highlighting. There is supposedly a user-made tree-sitter grammar: https://github.com/tree-sitter/tree-sitter/pull 2282Creating this as draft as we should probably not use
clangd
as LSP here, and perhaps switch to https://github.com/fab4100/tree-sitter-ispc for grammar.