Skip to content

Conversation

@BABA983
Copy link
Contributor

@BABA983 BABA983 commented Aug 30, 2024

Close #130678

demo.mp4
@aeschli
Copy link
Contributor

aeschli commented Sep 2, 2024

The folding model already knows which ranges are import ranges: type === FoldingRangeKind.Imports

See here as an example:

setCollapseStateForType(foldingModel, FoldingRangeKind.Comment.value, true);

Of course this only works for languages that have a provider. Your PR also has the same problem.

@BABA983 BABA983 force-pushed the feature/fold-import-command branch from 563a18b to 740fa3e Compare September 2, 2024 15:22
@BABA983
Copy link
Contributor Author

BABA983 commented Sep 2, 2024

The folding model already knows which ranges are import ranges: type === FoldingRangeKind.Imports

See here as an example:

setCollapseStateForType(foldingModel, FoldingRangeKind.Comment.value, true);

Of course this only works for languages that have a provider. Your PR also has the same problem.

I have update the code get regions from folding model.

Of course this only works for languages that have a provider. Your PR also has the same problem.

That seems to make sense to have a provider figure out what range is import range in different language?

@aeschli
Copy link
Contributor

aeschli commented Sep 3, 2024

You can use the already existing function setCollapseStateForType:

export function setCollapseStateForType(foldingModel: FoldingModel, type: string, doCollapse: boolean): void {

Depending on what extensions are installed, some language have rich language support and a folding provider, some don't.
For the languages that do not have a folding provider, folding ranges are computed using the indentation.
That might match the import sections, but must not.

@BABA983
Copy link
Contributor Author

BABA983 commented Sep 3, 2024

You can use the already existing function setCollapseStateForType

If we reuse the function we might need to know if the import range is collapsed or expanded.
Maybe we need a new function name toggleCollapseStateForType?

That might match the import sections, but must not.

If I understand right we should toggle fold import when there are provider provided? Like getFoldingRangeProviders here?

@aeschli
Copy link
Contributor

aeschli commented Sep 4, 2024

If we reuse the function we might need to know if the import range is collapsed or expanded.
Maybe we need a new function name toggleCollapseStateForType?

Do you want to toggle or set? I assumed from the name of the command fold import it is about setting the state to folded.

The command will just be a no-op if there's folding provider that knows about imports. That's fine.

@BABA983
Copy link
Contributor Author

BABA983 commented Sep 4, 2024

If we reuse the function we might need to know if the import range is collapsed or expanded.
Maybe we need a new function name toggleCollapseStateForType?

Do you want to toggle or set? I assumed from the name of the command fold import it is about setting the state to folded.

The command will just be a no-op if there's fodling provider that knows about imports. That's fine.

Maybe toggle is better? Only fold import seems quite limited. Separating the two commands fold and unfold seems to give the user more flexibility. What do you think?

@aeschli
Copy link
Contributor

aeschli commented Sep 4, 2024

Toggle is probably more useful.

@BABA983 BABA983 force-pushed the feature/fold-import-command branch from 0e4d995 to 89b2b66 Compare September 8, 2024 15:00
@BABA983 BABA983 requested a review from aeschli September 9, 2024 14:39
@aeschli
Copy link
Contributor

aeschli commented Sep 10, 2024

Thanks @BABA983 !

@vs-code-engineering vs-code-engineering bot added this to the September 2024 milestone Sep 10, 2024
@aeschli aeschli merged commit 3f0e1da into microsoft:main Sep 10, 2024
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Oct 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

3 participants