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

Guide for adding new languages #57

Closed
RomeoV opened this issue Sep 11, 2023 · 3 comments
Closed

Guide for adding new languages #57

RomeoV opened this issue Sep 11, 2023 · 3 comments
Labels
documentation Improvements or additions to documentation question Further information is requested

Comments

@RomeoV
Copy link

RomeoV commented Sep 11, 2023

Hello,
looks like an awesome package, and I would love to use it for structual navation in Julia and orgmode files.

Since the goal this project is to "relatively easy to add new languages" I gave it a shot, starting off with the combobulate-python.el file, and removing (for now) everything related to indentation.

However, I'm running into some confusions. Several times, the function combobulate-production-rules-get loads information from several json files (e.g. python.json, python-grammar.json, python-nodes.json), which have to be written and somehow processed with the build-relationships.py` script (?)

For now, I would just like to have a minimum viable version of combobulate that supports basic navigation like traversing the tree up/down/sidewards/etc. Since I understand elements like treesit-node-next-sibling etc are all implemented, I imagine I should be able to get a version of combobulate-julia.el going without touching any .json files at all. Is that correct?

Perhaps it would be helpful to provide a language-agnostic version combobulate-anylang.el that gets started with basic navigation functionality, and which can further be refined with custom rules etc etc.

Thanks!

@mickeynp mickeynp added documentation Improvements or additions to documentation question Further information is requested labels Sep 12, 2023
@mickeynp
Copy link
Owner

There's no such thing as an agnostic language. That materially cannot exist as each grammar is its own, with its own set of rules and idiosyncrasies. Therefore, Combobulate can't do it either. Sure, you can probably wing it, but it will not work well.

Finding siblings with treesit-node-next-sibling will not help you write sensible sibling navigation code (and by extension, make dragging work, though that uses another approach that I am likely going to replace with the same system used by sibling nav.) as sibling navigation is one of the hardest things -- outside of editing -- to get right.

You'll need to load and update the rules with support for Julia, yes. The build-relationships script should do all the work for you, though you do need to add an URL to its internal dict to support it.

The production rules are required (for some things) because tree-sitter cannot tell you what the parents or children of certain nodes or fields are valid.

@RomeoV
Copy link
Author

RomeoV commented Sep 12, 2023

I see, thanks for the reply. I used the helix editor for a short while, and have been missing the "select a increasingly growing region" quite a lot. I understand helix achieves this (somewhat "basic" behaviour) without specializing for every language, so I was hoping to get some basic similar functionality out of combobulate too. However, it seems combobulate is designed with more advanced functionality in mind.

I have found that the functionality I am looking for is mostly provided by plain treesit, and exposed e.g. through ts-movement, which seems to do the job for me with zero language specific customization. Still, probably combobulate can provide a much better interface if the language is supported.

@mickeynp
Copy link
Owner

mickeynp commented Sep 13, 2023

Expanding a region is a basic feature in Combobulate, and is easy to enable. Configure combobulate-navigation-default-nodes with the nodes you want it to expand to. You probably want most/all node types in there -- the rules file can help you get that list. See any number of example major modes.

Type M-h in Combobulate to engage expand region.

Sibling navigation has nothing to do with any of this, so if that's also something you need, it's distinct from expand region. Indeed, expand region (depending on how you choose to define it) is usually a case of picking nodes at point and expanding. It just so happens that Combobulate lets you configure which ones you want it to use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants