Skip to content

Commit

Permalink
Merge branch 'update_folding_sections_regex'
Browse files Browse the repository at this point in the history
  • Loading branch information
tamuratak committed Sep 9, 2023
2 parents 1c3d13f + 92491cf commit c2ad15c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/components/compilerloglib/biblogparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class BibLogParser {
const configuration = vscode.workspace.getConfiguration('latex-toybox')
let excludeRegexp: RegExp[]
try {
excludeRegexp = (configuration.get('message.bibtexlog.exclude') as string[]).map(regexp => RegExp(regexp))
excludeRegexp = (configuration.get('message.bibtexlog.exclude') as string[]).map(regexp => new RegExp(regexp))
} catch (e) {
if (e instanceof Error) {
this.extension.logger.info(`latex-toybox.message.bibtexlog.exclude is invalid: ${e.message}`)
Expand Down
2 changes: 1 addition & 1 deletion src/components/compilerloglib/latexlogparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class LatexLogParser {
const configuration = vscode.workspace.getConfiguration('latex-toybox')
let excludeRegexp: RegExp[]
try {
excludeRegexp = (configuration.get('message.latexlog.exclude') as string[]).map(regexp => RegExp(regexp))
excludeRegexp = (configuration.get('message.latexlog.exclude') as string[]).map(regexp => new RegExp(regexp))
} catch (e) {
if (e instanceof Error) {
this.extension.logger.info(`latex-toybox.message.latexlog.exclude is invalid: ${e.message}`)
Expand Down
20 changes: 16 additions & 4 deletions src/providers/folding.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import * as vscode from 'vscode'
import type { Manager } from '../components/manager'


export class FoldingProvider implements vscode.FoldingRangeProvider {
private readonly sectionRegex: RegExp[] = []
private sectionRegex: RegExp[]

constructor() {
const sections = vscode.workspace.getConfiguration('latex-toybox').get('view.outline.sections') as string[]
this.sectionRegex = sections.map(section => RegExp(`\\\\(?:${section})(?:\\*)?(?:\\[[^\\[\\]\\{\\}]*\\])?{(.*)}`, 'm'))
constructor(private readonly extension: {
readonly manager: Manager
}) {
this.sectionRegex = this.createSectionRegex()
vscode.workspace.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('latex-toybox.view.outline.sections', this.extension.manager.getWorkspaceFolderRootDir())) {
this.sectionRegex = this.createSectionRegex()
}
})
}

private createSectionRegex() {
const sections = vscode.workspace.getConfiguration('latex-toybox').get<string[]>('view.outline.sections', [])
return sections.map(section => new RegExp(`\\\\(?:${section})(?:\\*)?(?:\\[[^\\[\\]\\{\\}]*\\])?{(.*)}`, 'm'))
}

public provideFoldingRanges(document: vscode.TextDocument): vscode.FoldingRange[] {
Expand Down
2 changes: 1 addition & 1 deletion src/providersmanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class ProvidersManager {
)

context.subscriptions.push(
vscode.languages.registerFoldingRangeProvider(latexSelector, new FoldingProvider()),
vscode.languages.registerFoldingRangeProvider(latexSelector, new FoldingProvider(extension)),
)

context.subscriptions.push(
Expand Down
2 changes: 1 addition & 1 deletion src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function stripComments(text: string): string {
export function stripEnvironments(text: string, envs: string[]): string {
const envsAlt = envs.join('|')
const pattern = `\\\\begin{(${envsAlt})}.*?\\\\end{\\1}`
const reg = RegExp(pattern, 'gms')
const reg = new RegExp(pattern, 'gms')
return text.replace(reg, (match, ..._args) => {
const len = Math.max(match.split('\n').length, 1)
return '\n'.repeat(len - 1)
Expand Down

0 comments on commit c2ad15c

Please sign in to comment.