-
Notifications
You must be signed in to change notification settings - Fork 48
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
Using tree-sitter in csharp-mode? #201
Comments
There has been similar discussions for |
I'll look i to it 😄 |
I've started to look into this, and have created a branch - What I've done so far:
To try this you need to use my fork of I think the simplest transition would be to keep the indentation provided by CC Mode until we have some Yet another rework! 😄 |
I just tried running the branch, but it seems I'm doing something wrong. When trying to activate it, I'm not getting any highlighting at all, I just instead the following in my logs:
Probably an easy fix, or a quick one-liner I'm missing, but it's not currently runnable OOB. Edit: After reading some docs and some of your PRs against emacs-tree-sitter I found the following to work: ;;;###autoload
(add-to-list 'tree-sitter-major-mode-language-alist '(csharp-mode . c_sharp)) Should I add it to our branch for now, or should we just assume it will be merged upstream soon enough? |
After playing slightly with this code, I'm very much sold on this.
All we have to do is tell Emacs how we want that language to look inside our major-mode. And that's really all we should be focusing on. Perfect! For instance, I took note that attributes are rendered differently with and without arguments: I looked at the (to me!) completely alien major-mode definition, found this: Noticed and fixed an inconsistency: And voila! This really couldn't be easier. Compared to any other Emacs major-mode I have worked with, this was by far the simplest fix. I'm all in awe! So:
This almost has me rooting for a similar solution for typescript-mode! My only concern/regret about such an approach is the dependency on native executables, and what (few) platforms they currently exist for, compared to the wide array of platforms Emacs itself supports. But again, I guess that can be solved upstream, and if the use of tree-sitter-mode in major-modes start increasing, there will be a natural push, by more people than just me, for better platform support (*BSD, ARM64, etc). |
Great! I'm so glad to hear that!
Yeah, this is an issue, and we need to find a good solution for this. Right now I've just hurled everything into one spot, as you can see. I think we should factor this one out in separate variables and then just Yeah, tree sitter is amazing. I'm looking into tree-sitter-indent as we speak as well :) |
Just sent in 2 patches to your branch! Attributes and namespaces. This shit is simple! |
Just fire away! We can extract stuff later. Some things I've noted:
(parameter
type: (identifier) @type
name: (identifier) @variable)
(parameter (identifier) @variable) This is intentional. Also: |
I opened an issue here: I feel like I'm missing something here, but I have a proof of concept for indentation also 🎉 . I hope @FelipeLema can help us out here. If we can iron out some bugs (or teach me how to read) I think we can ditch CC Mode pretty soon(tm) |
Right now this code indents correctly when typing it out manually namespace Foo
{
public class Bar
{
public Baz Quux()
{
// ...
var test = new Generic();
var text = new Thing.Thang
{
a,
b,
c
};
yield return new InnerA.InnerB
{
Boo = "foo",
May = "Yay"
};
}
}
} Marking the whole thing and pressing However, note that the |
@josteink If you want, you can test the branch now both for indentation and coloring, and add things as you see fit. Most of the infrastructure should be usable, and we have the same "config-based" rules for indentation! One small tip: If something doesn't indent properly, try making it syntactically valid first I.E add a semi after a brace. See the issue over at codeberg for more details 👍 Most of the code in |
oOo! My guess is that this is pretty hard :P We have no logic for dealing with that, now at least. I'll look into this :) Side note: Lots of changes coming :) |
I added back your interface code. It was a hassle with the defcustoms, much easier to iterate on highlighting when everything is in one place. Sorry for the back and forth. We will factor it out when we are satisfied in the end. |
Good news! I think we have feature parity, both with indentation and highlighting! 🤞 Caveat: You need https://codeberg.org/theo/tree-sitter-indent.el/ (fork of FelipeLemas thing) for the latest changes. They haven't been merged yet. However, it should be a simple Now One thing to note, which is a little weird: Consider this code: namespace Foo
{
| // This is how things are opened - point is '|'
} If I start typing something, then we get the extra indentation. I'm thinking of ways to get Why don't you test it a little? I'm a little eager to get this merged into (I'm also thinking of stealing the indent part - it's only a couple hundred LOC and making it C# specific. However, I think the community could need some debugging on that thing to make it super robust 😄 ) |
I don't think this is solvable: https://github.com/tree-sitter/tree-sitter-c-sharp/blob/master/grammar.js#L1471 Roslyn doesn't seem to acknowledge scandinavia, I'm afraid |
Given how that is legal, compilable code (even though bad form), that seems a bit odd. Oh well. Good researching 🙂 |
Ok I stole the |
Question: does this require installing tree-sitter? |
I believe our dependency on Emacs-tree-sitter should ensure we get a bundled version of the actual tree-sitter binary for all "common" platforms. What OS are you using? |
You don’t need any external tree sitter related packages. Everything should be included with the tree sitter branch. However, we depend on ubolontons mode as well |
Closing after 3cff337 |
Sorry guys! I got this error with the latest version if I didn't install
|
Do you get the error if you manually install tree-sitter first? If not, I’ll update readme to be clearer about this behavior. For now I don’t want to introduce dependencies to csharp mode. |
@seagle0128 Are you sure you are installing
|
Thanks, @theothornhill @jcs090218 . Now I got this message while installing Cannot open load file: No such file or directory, tree-sitter |
@seagle0128 Notice that tree-sitter support is experimental and this isn't an official yet. You may have to manually install package By seeing |
Gocha, glad to know. Thanks, @jcs090218 . |
I have been following
emacs-tree-sitter
development for a while, and after watching https://emacsconf.org/2020/talks/23/, I feel we at least should talk about this feature being incorporated intocsharp-mode
after #200 and numerous other issues.What would be the benefits?
This would be yet another rewrite - yay! However,
csharp-mode
is in a kind of good place, in that what it provides is mostly indentation and highlighting, leaving most of the smarts tolsp-mode
. This is obviously a wishlist feature.CC @ubolonton (Just letting you know this issue exists)
The text was updated successfully, but these errors were encountered: