Skip to content

Folding range provider API #3389

@rwols

Description

@rwols

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions