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

Support code folding for DocTeX #4426

Merged
merged 6 commits into from
Oct 16, 2024
Merged

Conversation

huangyxi
Copy link
Contributor

@huangyxi huangyxi commented Oct 6, 2024

This pull request enhances the LaTeX-Workshop extension by adding support for VSCode code folding for DocTeX files. The new functionality includes:

  1. Sections Folding: Adds support for folding LaTeX section commands in DocTeX, such as % \section{abc}.
  2. DocStrip Guards Folding: Adds support for folding DocStrip guard ranges with patterns like %<*abc> to %</abc>, where abc can be replaced with characters such as |, ',', &, !, -, _, (, ).
  3. [UPDATED] meta-comment: Adds support for folding DocTeX from % \iffalse meta-comment to % \fi.

Showcase for the l3doc class:
image

@James-Yu
Copy link
Owner

James-Yu commented Oct 6, 2024

Thanks for your contribution. Please extend a new doctex folding class for the implementation. It would be fine if you need to make envRegex a class instance variable.

@huangyxi
Copy link
Contributor Author

huangyxi commented Oct 7, 2024

Thank you for your response. I have updated the structure of the new DocTeX folding class, and added a new folding pattern that matches from % \iffalse meta-comment to % \fi.

@huangyxi
Copy link
Contributor Author

I think it is ready for another review.

Copy link
Owner

@James-Yu James-Yu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original FoldingProvider class should not contain codes related to DocTeX.

Comment on lines +117 to +122
} else if (match[9]) {
keyword = '%<' + match[9] + '>'
} else if (match[10]) {
keyword = '%<' + match[10] + '>'
} else if (match[11] || match[12]) {
keyword = '%\\iffalse meta-comment'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are only for DocTeX

@@ -2,10 +2,11 @@ import * as vscode from 'vscode'

export class FoldingProvider implements vscode.FoldingRangeProvider {
private readonly sectionRegex: RegExp[] = []
protected readonly envRegex = /\\(begin){(.*?)}|\\(begingroup)[%\s\\]|\\(end){(.*?)}|\\(endgroup)[%\s\\]|^%\s*#?([rR]egion)|^%\s*#?([eE]ndregion)|^%\s*<\*([|_()\-a-zA-Z0-9]+)>|^%\s*<\/([|_()\-a-zA-Z0-9]+)>|^%\s*\\iffalse\s*(meta-comment)|^%\s*\\(fi)/gm
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems you add new matches to this regexp. Are they only for DocTeX?

@@ -113,11 +128,12 @@ export class FoldingProvider implements vscode.FoldingRangeProvider {
}
const lastItem = opStack[opStack.length - 1]

if ((match[4] || match[6] || match[8]) && lastItem && lastItem.keyword === item.keyword) { // match 'end' with its 'begin'
if ((match[4] || match[6] || match[8] || match[10] || match[12]) && lastItem && lastItem.keyword === item.keyword) { // match 'end' with its 'begin'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

@huangyxi
Copy link
Contributor Author

The getEnvironmentFoldingRanges method has been separated into both classes.

@James-Yu James-Yu merged commit 42da174 into James-Yu:master Oct 16, 2024
7 checks passed
@huangyxi huangyxi deleted the doctex-fold branch October 17, 2024 08:42
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants