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 folding markers to syntax configuration #202

Closed
wants to merge 1 commit into from
Closed

Add folding markers to syntax configuration #202

wants to merge 1 commit into from

Conversation

KevinGliewe
Copy link

This PR adds the region markers //#region and //#endregion to add custom folding regions in the Haxe Code.
The snipped for the marker definition comes from the TypeScript configuration file in the VSCode repo:

https://github.com/Microsoft/vscode/blob/master/extensions/typescript/language-configuration.json#L28

I hope you guys like this feature.

Example

Add the region markers `//#region` and `//#endregion` to add custom folding regions.
@KevinGliewe
Copy link
Author

Well, this is a strange build error... 🤔

@Gama11
Copy link
Member

Gama11 commented Feb 5, 2018

There was a discussion about this here: #179

@KevinGliewe
Copy link
Author

Oh, sorry for the useless PR then.

@RealyUniqueName
Copy link

RealyUniqueName commented Feb 6, 2018

This feature is going to be implemented in IDEA too: HaxeFoundation/intellij-haxe#744
Maybe it should be treated as a convention.

@EricBishton
Copy link

EricBishton commented Feb 6, 2018

IDEA is going to have two flavors available, at first:

  • An FD style: // { region MyRegionTitle and // } endregion (with spaces optional between the comment signifier and the bracket, between the brackets and the region marker -- because they aren't actually required for FD -- and and between "end" and "region").
  • An AS3 style: // region MyRegionTitle and // end region (again, the spaces are optional).

Eventually, the user will be allowed to specify starting and ending markers by providing regexes via a dialog.

Edit: Oh, yeah. It works with any comment type (single line, block, documentation), if the marker is on the top line of the block, and the two types don't styles don't match each other.

@KevinGliewe
Copy link
Author

KevinGliewe commented Feb 6, 2018

Maybe we could use a regex as default which matches all the styles at once?

The start:
^\s*\/[\/\*]\s*[#{]?\s*region\b
https://regex101.com/r/3vWgnm/1

The end:
^\s*\/[\/\*]\s*[#}]?\s*end ?region\b
https://regex101.com/r/MPOk8s/1

Afterwards the pattern could be swapped out by a command or something along this line to use a specific style.
The method vscode.setLanguageConfiguration(language: string, configuration: LanguageConfiguration): Disposable should hopefully provide a way to accomplish it without reloading vscode.

Note:
It looks like the documentation here is not up to date:
https://code.visualstudio.com/docs/extensionAPI/vscode-api#_a-namelanguageconfigurationaspan-classcodeitem-id962languageconfigurationspan

There is no folding property in the documentation, but there is one in the sourcecode:
https://github.com/Microsoft/vscode/blob/777fddd4f7c65b4b1b040328b045c30c3c08f7bc/src/vs/editor/common/modes/languageConfiguration.ts#L68

Edit:
It looks like the LanguageConfiguration definition from the vscode-extern library isn't up do date as well.

https://github.com/vshaxe/vscode-extern/blob/7073e5eee91ca8c2389e7a5c6b899aac36af4562/src/vscode/LanguageConfiguration.hx

It lacks the folding property to.

@EricBishton
Copy link

EricBishton commented Feb 6, 2018

Is the #region marker common in other languages/IDEs? It seems that some folks like/expect it for JS.

EDIT: C#, it would appear. Except that it doesn't appear in comments.

@KevinGliewe
Copy link
Author

I think the #region swapped over from C# to vscode. It looks like it is sort of convention now for vscode to fold using this marke. They even included it in Java.

https://github.com/Microsoft/vscode/blob/master/extensions/java/language-configuration.json#L27

@Gama11
Copy link
Member

Gama11 commented Mar 26, 2018

@nadako Any thoughts on this?

@nadako
Copy link
Member

nadako commented Mar 26, 2018

Not really, but this won't hurt I guess

@Gama11
Copy link
Member

Gama11 commented Mar 27, 2018

Since there's not really a convention, it would be strange to pick out one specific style to support. I'm going to use the @KevinGliewe's "match-all" regexes with support for:

  • // #region name - // #endregion
  • // region name - // end region
  • // { region name - // } endregion

@Gama11 Gama11 closed this in d4d2aee Mar 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants