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

Folding range provider API #3389

Open
rwols opened this issue Jun 5, 2020 · 2 comments
Open

Folding range provider API #3389

rwols opened this issue Jun 5, 2020 · 2 comments

Comments

@rwols
Copy link

rwols commented Jun 5, 2020

Problem description

There's this capability in LSP where a server can be a foldingRangeProvider. An editor can ask the server to provide folding ranges.

It is at the moment not possible to bring those fold ranges to the gutter area.

Preferred solution

A new ST callback, much like on_query_completions, where a plugin must return a promise object to provide new fold regions. All fold regions from all plugins are merged in some way or another.

def FooListener(sublime_plugin.ViewEventListener):

    def on_fold_regions(self) -> sublime.FoldRegions:
        promise = sublime.FoldRegions()
        sublime.set_timeout_async(lambda: self.compute_fold_regions(promise))
        return promise

    def compute_fold_regions(self, promise: sublime.FoldRegions) -> None:
        promise.set_result([sublime.Region(0, 1), sublime.Region(10, 12)])

This way, ST can coordinate when to ask for new fold regions (perhaps after saving the view). And ST can also merge results.

Alternatives

None.

Additional Information (optional)

This is one possible solution for #101

@rchl
Copy link

rchl commented Mar 12, 2021

This way, ST can coordinate when to ask for new fold regions (perhaps after saving the view).

But the regions would easily get out of sync when editing the files?

@rwols
Copy link
Author

rwols commented Mar 12, 2021

If a region is replaced entirely inside of a fold region, then the fold region can just shrink/expand, no?
If a region is replaced entirely outside of a fold region, then the fold region can move.
If the replacement region intersects with the fold region endpoints, then yeah the fold region becomes invalid/stale.

In any case, requesting after a view is saved was just an idea. It's not a hard requirement for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants