Skip to content

add custom folding strategy#54200

Closed
daiyam wants to merge 30 commits into
microsoft:mainfrom
daiyam:custom-folding-strategy
Closed

add custom folding strategy#54200
daiyam wants to merge 30 commits into
microsoft:mainfrom
daiyam:custom-folding-strategy

Conversation

@daiyam

@daiyam daiyam commented Jul 12, 2018

Copy link
Copy Markdown
Contributor

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

aeschli commented Jul 17, 2018

Copy link
Copy Markdown
Contributor

@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.

Comment thread src/vs/monaco.d.ts Outdated
Comment thread src/vs/editor/common/config/commonEditorConfig.ts Outdated
Comment thread src/vs/editor/common/modes.ts Outdated
Comment thread src/vs/editor/contrib/folding/folding.ts
@daiyam
daiyam changed the base branch from release/1.25 to master December 23, 2020 21:02
@aeschli

aeschli commented Jan 5, 2021

Copy link
Copy Markdown
Contributor

@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

daiyam commented Jan 5, 2021

Copy link
Copy Markdown
Contributor Author

@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

daiyam commented Jan 5, 2021

Copy link
Copy Markdown
Contributor Author

@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
Copy Markdown

hi @aeschli , pinging for updates 😇

@aeschli

aeschli commented Jun 17, 2022

Copy link
Copy Markdown
Contributor

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

daiyam commented Jun 17, 2022

Copy link
Copy Markdown
Contributor Author

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

aeschli commented Jun 17, 2022

Copy link
Copy Markdown
Contributor

@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

daiyam commented Jun 17, 2022

Copy link
Copy Markdown
Contributor Author

@daiyam

daiyam commented Jun 23, 2022

Copy link
Copy Markdown
Contributor Author

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

@aeschli

aeschli commented Jun 23, 2022

Copy link
Copy Markdown
Contributor

@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

daiyam commented Aug 7, 2022

Copy link
Copy Markdown
Contributor Author

@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.