c3lang / editor-plugins

Editor plugins for C3
MIT License
39 stars 20 forks source link

Enhancements to the C3 VS Code extension #24

Closed carlosvneves closed 2 months ago

carlosvneves commented 2 months ago

This PR proposes enhancements to the C3 VS Code extension

The main adjustments include:

  1. Function and Method Calls:

    • Added distinct highlighting for function calls (e.g., malloc(), free()).
    • Improved method call highlighting (e.g., object.method()).
  2. Variable and Struct Member:

    • Enhanced differentiation between variables and struct members.
    • Ensured proper highlighting of variables in function declaration (e.g. &self and Object* ).
  3. Contract Comments:

    • Added special highlighting for contract comments (/** */).
    • Distinct colors for contract keywords (@require, @ensure, @param).
    • Highlighting for contract-specific constructs ([in], [out], $function).
  4. Code snippets:

    • Currently includes a limited number of code snippets.
  5. Support for LSP:

  6. Other minor changes:

    • Added README for the extension itself, explaining features and how to install the LSP, for example.
    • Added LICENSE file (MIT).
    • Added C3 icon for the extension, changed the display name to "C3 Language Support for VSCode", description to "C3 Language Support for VSCode - Syntax Highlighting and Code Snippets" and added publisher "C3 Language" (as discussed on Discord).
    • Added example to conform to the coding of other C3 examples (I used the one that is in the intellij plugin repo).
    • Added the .vsix file to the repo.

Testing:

IMPORTANT:

Feedback is welcome.

Note: This PR replaces the one that I made 2 days ago (by mistake). Thanks to Christoffer Lerno for pointing out what was wrong.

carlosvneves commented 2 months ago

I am sorry that I couldn't reply earlier. Thank you for the review!

I think the textmate grammar needs some work, but it's alright for now. I might continue to work on it myself since I know C3's grammar very well by now.

I am new to this and I wanted to help. I hope I really can learn from the more experienced.

I made the fixes, except in the example.c3 (as in the comment above).

Please, let me know when you think the code is ready. Then I will push the updated code.

cbuttner commented 2 months ago

No worries. Implementing good highlighting is tricky and takes a while, because it takes knowledge of the highlighting mechanism (TextMate in this case), regular expressions and the language grammar. The latter is where you need more experience with C3 to notice some issues. For example, block comments can be nested, macro parameters can start with #, there's no raw string literal, no attribute highlighting, some brace types are missing etc. Copying from C doesn't do the trick here, for instance there are more type suffixes other than *.

But don't worry about that stuff, I already went through the process twice with tree-sitter and Sublime Text syntax, so I'm gonna fix this one up too in the coming weeks. Plus I can copy a bunch of regular expressions from the Sublime syntax and make sure highlighting is kept relatively consistent between editors.

Another thing I noticed, can you please go through snippets.json and make sure these are valid constructs that actually compile? I noticed case and case-else are not valid. Thanks!

carlosvneves commented 2 months ago

Implementing good highlighting is tricky and takes a while, because it takes knowledge of the highlighting mechanism (TextMate in this case), regular expressions and the language grammar. The latter is where you need more experience with C3 to notice some issues. For example, block comments can be nested, macro parameters can start with #, there's no raw string literal, no attribute highlighting, some brace types are missing etc. Copying from C doesn't do the trick here, for instance there are more type suffixes other than *

Yeah, thanks for your patience. I think I was a "little bit ambitious" for my first PR. Was my first time on developing vscode extension and syntax-highlight. And I am very new to the C3 language. I became interested after TSoding's videos and I am very excited. It's a very nice concept and the community is awesome.

I tried to read the docs and understand all the snippets. But you are right about the lack of experience. I took zig, C and other extensions to see how I could implement some of the features I missed, and others that I saw people asking for.

But don't worry about that stuff, I already went through the process twice with tree-sitter and Sublime Text syntax, so I'm gonna fix this one up too in the coming weeks. Plus I can copy a bunch of regular expressions from the Sublime syntax and make sure highlighting is kept relatively consistent between editors.

Since you have all that experience, I am sure you can make great improvements. It is a great idea try to make it consistent between editors. Please, feel free to take what is worth from the code. I really hope it can helps :)

Another thing I noticed, can you please go through snippets.json and make sure these are valid constructs that actually compile? I noticed case and case-else are not valid. Thanks!

Sure, I can review the snippets. As I said earlier, I took some examples from other plugins. I thought that I changed the snippets accordingly, but I missed some. I will fix it and maybe add others that can be useful. I was thinking about the snippets as a way to help the beginners (like myself) to get some help with the C3 syntax. So, if you remember anything that it is worth to add, please let me know.

Finally, as you will make improvements, how would be the best way for me to work on the fixes? I mean, we let this PR opened and I make de the fixes you suggest in my fork, and then we merge with your improvements later before the merge in the main repo? I'm sorry if it is a silly question, but I think it was important to ask anyway.

Thanks again!

cbuttner commented 2 months ago

Development continues here, based off this PR and my syntax highlighting: https://github.com/c3lang/vscode-c3