berabue / vscode-region-viewer

This extension allows you to print a list of regions in a document and select a region to navigate to the document's location.
22 stars 9 forks source link

More languages #3

Closed swift502 closed 4 years ago

swift502 commented 4 years ago

Hi!

I really like your extension! At least until there's an official region outline support.

Here's my proposal for extending it to support all the region markers listed in https://code.visualstudio.com/updates/v1_17#_folding-regions

It should be fairly general. Instead of your text.includes("#region"), I opted for text.trim().startsWith("#region") to avoid any false positives. I tested it on my Typescript project and various libraries and found no false positives.

I also made some subjective changes. Tell me if you don't like some (or either) of these behaviors. No hard feelings. 😄

  1. If there's a region marker with nothing else, the displayed name is still region. I think this is more appealing than simply displaying a "#". image

  2. The region names are now trimmed. image

I'd love to get this merged. I'll be happy to tweak things based on your feedback. Thanks!

swift502 commented 4 years ago

I see the marker list is incomplete. I'll try to address this with a different approach to parsing, so that the performance doesn't get worse with every added language.

I'll make a PR combined with nesting, as it's built upon this branch anyways.

berabue commented 4 years ago

Hi @swift502

It's so nice that someone is interested in this project!!

Even if there is a space between the hashtag and region, it would be better if it was recognized.

swift502 commented 4 years ago

I keep finding more things since I started working on this.

VScode has all the functions for recognising regions and their nesting already implemented. I really don't understand why regions aren't displayed in the outline yet.

Every language has a regex for recognising it's region start and end. We can use exactly what VSCode uses to recognise regions for folding. https://github.com/microsoft/vscode/blob/ae245c9b1f06e79cec4829f8cd1555206b0ec8f2/extensions/csharp/language-configuration.json#L26-L31

swift502 commented 4 years ago

This might be a valid way to get to the regex expressions directly. I hope extensions can access that information. I'll check when I get home. https://github.com/microsoft/vscode/blob/f74e473238aca7b79c08be761d99a0232838ca4c/src/vs/editor/contrib/folding/indentRangeProvider.ts#L28-L30

https://github.com/microsoft/vscode/blob/f74e473238aca7b79c08be761d99a0232838ca4c/src/vs/editor/common/modes/languageConfiguration.ts#L135

swift502 commented 4 years ago

@berabue I wanted to make a better PR and abandon this one but ok 😃

I'll make a new PR with both region nesting and other improvements if you agree.

berabue commented 4 years ago

@swift502

Sorry, I am not yet familiar with open source.😭

Thanks to you, I am learning hard.