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

add custom folding strategy #54200

Closed
wants to merge 30 commits into from
Closed

Conversation

daiyam
Copy link
Contributor

@daiyam daiyam commented Jul 12, 2018

Hello,

This PR has been discussed with @aeschli at #53910

  • allow folding range provider to have an id
interface FoldingRangeProvider {
     id?: string;
     providerFoldingRanges(...) ...
}
  • allow the user to enter that id as a strategy
 "editor.foldingStrategy": "explicit"

roblourens and others added 22 commits June 29, 2018 11:46
Needed to understand which type of refactorings are most used so we can decided which bugs to prioritize and which new refactoring areas to invest in
Let the base text editor model be readonly by default unless the model handle is of "untitled://".
@daiyam daiyam changed the title add custom folding strategy as discuss with @aeschli at #53910 add custom folding strategy Jul 12, 2018
@aeschli aeschli self-requested a review July 12, 2018 21:02
@aeschli
Copy link
Contributor

aeschli commented Jul 17, 2018

@daiyam Thanks a lot for the PR. Please give me some time to review, I'm buried in some other work, but will get to this right after.

@daiyam daiyam changed the base branch from release/1.25 to master December 23, 2020 21:02
@aeschli
Copy link
Contributor

aeschli commented Jan 5, 2021

@daiyam If you plan to work on the PR again, maybe it's better to start a new one. Something is off.

As mentioned, revert the changes to folding.ts, but add the code to select the provider in SyntaxRangeProvider.

@daiyam
Copy link
Contributor Author

daiyam commented Jan 5, 2021

@aeschli Ya, I can filter out the providers inside the SyntaxRangeProvider but I still would need to modifyfolding.ts to pass the option EditorOption.foldingStrategy. Is that ok?

@daiyam
Copy link
Contributor Author

daiyam commented Jan 5, 2021

@aeschli If the changes are ok, I will make another PR. Thx

@joaomoreno joaomoreno changed the base branch from master to main February 15, 2021 08:51
@goyalyashpal
Copy link

hi @aeschli , pinging for updates 😇

@aeschli
Copy link
Contributor

aeschli commented Jun 17, 2022

An alternative way would be to go the same way we went for formatting:
The setting editor.defaultFormatter allows to select the formatter to use. The name of the formatter is the name of the extension that provides the formatter.

  • the setting also supports language specific settings: "[html]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }
  • potentially an extension can provide multiple formatters, but this uncommon. We'd just call all of them.
  • this change doesn't require any changes to the contribution (no id needed)
  • for folding we would use editor.foldingStrategy with that approach. This means that an id of an extension is also a allowed value. Maybe it could also be an array of extension ids, but we'd need to understand if there are use cases for that.

Would that work for your use case? I`d prefer that solution give we already use the approach for formatting where it worked well.

@daiyam
Copy link
Contributor Author

daiyam commented Jun 17, 2022

My personal use case is:

  • disable the folding defined by the language provider
  • use the foldings defined like with Emacs with my extension Explicit Folding

The main issue is that VSCode the foldings defined by the language provider can't be disabled.

There is an additional issue where we can't define the priority of the folding providers.
So I've added delay when registering the folding provider of my extension so it can get a higher priority.
But by doing so, VSCode won't remember collapsed regions of a file because it won't know the provider due to the delay...

I have a newer version of the PR where the users can finely tune which folding providers to use (doc)

@aeschli
Copy link
Contributor

aeschli commented Jun 17, 2022

@daiyam Can you confirm that the proposal as described in #54200 (comment) will help you? Users could set your folding provider as the default. Your provider can offer additional options such as 'explicit and indentation' etc. It would mean that you reimplement the indentation strategy, but IMO that's acceptable.

@daiyam
Copy link
Contributor Author

daiyam commented Jun 17, 2022

@aeschli Yes, your proposal would work.

For explicit and indentation, I've already implemented it: https://github.com/zokugun/vscode-explicit-folding/blob/master/docs/rules/indentation.md

@daiyam
Copy link
Contributor Author

daiyam commented Jun 23, 2022

@aeschli Do you want me to make a new PR with your proposal?

@aeschli
Copy link
Contributor

aeschli commented Jun 23, 2022

@daiyam Yes that would be great!

@daiyam daiyam closed this Aug 7, 2022
@daiyam daiyam deleted the custom-folding-strategy branch August 7, 2022 12:57
@daiyam daiyam restored the custom-folding-strategy branch August 7, 2022 12:57
@daiyam daiyam deleted the custom-folding-strategy branch August 7, 2022 12:59
@daiyam
Copy link
Contributor Author

daiyam commented Aug 7, 2022

@aeschli I've made the PR #157434 following your proposal.

@github-actions github-actions bot locked and limited conversation to collaborators Sep 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
editor-folding Editor code folding issues feature-request Request for new features or functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.