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

Recognize .ispc extension as CPP #8678

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

MarijnS95
Copy link

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 2282


Creating 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.

@MarijnS95 MarijnS95 marked this pull request as draft October 31, 2023 11:14
@cloudhan
Copy link

cloudhan commented Oct 31, 2023

ISPC has a language server and is pending a release https://togithub.com/ispc/ispc/issues/1605#issuecomment-1771833547

@the-mikedavis
Copy link
Member

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" }]

@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 Oct 31, 2023
@MarijnS95
Copy link
Author

MarijnS95 commented Nov 21, 2023

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 0197076648b8f31aab85c447015f29dadb53a8b3~, or ask the author what source is supposed to be latest/source-of-truth. At least it provides indent queries.

Copy link
Member

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?

Copy link

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).

Copy link
Author

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!

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

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

Copy link
Author

@MarijnS95 MarijnS95 Feb 5, 2024

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?

Copy link
Member

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

Copy link
Author

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 👍

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

4 participants