Skip to content

Commit

Permalink
Merge branch 'stop_using_regex'
Browse files Browse the repository at this point in the history
  • Loading branch information
tamuratak committed Sep 2, 2023
2 parents 7de8ca1 + 0f35514 commit fb736f2
Show file tree
Hide file tree
Showing 19 changed files with 70 additions and 695 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ To streamline maintenance and enhance security measures, I removed some features
- Magic comment support
- Creating temporary directory to build
- Formatting LaTeX documents
- R Sweave and Weave.jl supports
- old-style Docker supports
- Counting words

## Feature requests
Expand Down
115 changes: 14 additions & 101 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
},
"categories": [
"Programming Languages",
"Snippets",
"Linters",
"Formatters"
"Linters"
],
"keywords": [
"latex",
Expand Down Expand Up @@ -108,32 +106,6 @@
"LaTeX-Expl3"
],
"configuration": "./syntax/latex3-language-configuration.json"
},
{
"id": "jlweave",
"aliases": [
"Weave.jl"
],
"extensions": [
".jnw",
".jtexw"
],
"configuration": "./syntax/latex-language-configuration.json"
},
{
"id": "rsweave",
"aliases": [
"R Sweave"
],
"extensions": [
".rnw",
".Rnw",
".Rtex",
".rtex",
".snw",
".Snw"
],
"configuration": "./syntax/latex-language-configuration.json"
}
],
"grammars": [
Expand Down Expand Up @@ -185,22 +157,6 @@
"language": "latex-expl3",
"scopeName": "text.tex.latex.expl3",
"path": "./syntax/LaTeX-Expl3.tmLanguage.json"
},
{
"language": "jlweave",
"scopeName": "text.tex.latex.jlweave",
"path": "./syntax/JLweave.tmLanguage.json",
"embeddedLanguages": {
"source.julia": "julia"
}
},
{
"language": "rsweave",
"scopeName": "text.tex.latex.rsweave",
"path": "./syntax/RSweave.tmLanguage.json",
"embeddedLanguages": {
"source.r": "r"
}
}
],
"commands": [
Expand Down Expand Up @@ -351,19 +307,19 @@
"key": "ctrl+l alt+m",
"mac": "cmd+l alt+m",
"command": "latex-toybox.toggleMathPreviewPanel",
"when": "editorLangId =~ /^latex$|^latex-expl3$|^rsweave$|^jlweave$/ && config.latex-toybox.bind.altKeymap.enabled"
"when": "editorLangId =~ /^latex$|^latex-expl3$/ && config.latex-toybox.bind.altKeymap.enabled"
},
{
"key": "ctrl+l alt+b",
"mac": "cmd+l alt+b",
"command": "latex-toybox.build",
"when": "editorLangId =~ /^latex$|^latex-expl3$|^rsweave$|^jlweave$/ && config.latex-toybox.bind.altKeymap.enabled && !virtualWorkspace"
"when": "editorLangId =~ /^latex$|^latex-expl3$/ && config.latex-toybox.bind.altKeymap.enabled && !virtualWorkspace"
},
{
"key": "ctrl+l alt+v",
"mac": "cmd+l alt+v",
"command": "latex-toybox.view",
"when": "editorLangId =~ /^latex$|^latex-expl3$|^rsweave$|^jlweave$/ && config.latex-toybox.bind.altKeymap.enabled && !virtualWorkspace"
"when": "editorLangId =~ /^latex$|^latex-expl3$/ && config.latex-toybox.bind.altKeymap.enabled && !virtualWorkspace"
},
{
"key": "ctrl+l alt+j",
Expand All @@ -375,19 +331,19 @@
"key": "ctrl+alt+m",
"mac": "cmd+alt+m",
"command": "latex-toybox.toggleMathPreviewPanel",
"when": "editorLangId =~ /^latex$|^latex-expl3$|^rsweave$|^jlweave$/ && !config.latex-toybox.bind.altKeymap.enabled"
"when": "editorLangId =~ /^latex$|^latex-expl3$/ && !config.latex-toybox.bind.altKeymap.enabled"
},
{
"key": "ctrl+alt+b",
"mac": "cmd+alt+b",
"command": "latex-toybox.build",
"when": "editorLangId =~ /^latex$|^latex-expl3$|^rsweave$|^jlweave$/ && !config.latex-toybox.bind.altKeymap.enabled && !virtualWorkspace"
"when": "editorLangId =~ /^latex$|^latex-expl3$/ && !config.latex-toybox.bind.altKeymap.enabled && !virtualWorkspace"
},
{
"key": "ctrl+alt+v",
"mac": "cmd+alt+v",
"command": "latex-toybox.view",
"when": "editorLangId =~ /^latex$|^latex-expl3$|^rsweave$|^jlweave$/ && !config.latex-toybox.bind.altKeymap.enabled && !virtualWorkspace"
"when": "editorLangId =~ /^latex$|^latex-expl3$/ && !config.latex-toybox.bind.altKeymap.enabled && !virtualWorkspace"
},
{
"key": "ctrl+alt+j",
Expand All @@ -398,12 +354,12 @@
{
"key": "enter",
"command": "latex-toybox.onEnterKey",
"when": "config.latex-toybox.bind.enter.key && editorTextFocus && (acceptSuggestionOnEnter && !suggestWidgetVisible || !acceptSuggestionOnEnter) && !editorReadonly && editorLangId =~ /^latex$|^latex-expl3$|^rsweave$|^jlweave$/ && (vim.active && vim.mode == 'Insert' || !vim.active)"
"when": "config.latex-toybox.bind.enter.key && editorTextFocus && (acceptSuggestionOnEnter && !suggestWidgetVisible || !acceptSuggestionOnEnter) && !editorReadonly && editorLangId =~ /^latex$|^latex-expl3$/ && (vim.active && vim.mode == 'Insert' || !vim.active)"
},
{
"key": "alt+enter",
"command": "latex-toybox.onAltEnterKey",
"when": "config.latex-toybox.bind.enter.key && editorTextFocus && (acceptSuggestionOnEnter && !suggestWidgetVisible || !acceptSuggestionOnEnter) && !editorReadonly && editorLangId =~ /^latex$|^latex-expl3$|^rsweave$|^jlweave$/"
"when": "config.latex-toybox.bind.enter.key && editorTextFocus && (acceptSuggestionOnEnter && !suggestWidgetVisible || !acceptSuggestionOnEnter) && !editorReadonly && editorLangId =~ /^latex$|^latex-expl3$/"
}
],
"configurationDefaults": {
Expand Down Expand Up @@ -472,20 +428,6 @@
"pdflatex"
]
},
{
"name": "Compile Rnw files",
"tools": [
"rnw2tex",
"latexmk"
]
},
{
"name": "Compile Jnw files",
"tools": [
"jnw2tex",
"latexmk"
]
},
{
"name": "tectonic",
"tools": [
Expand Down Expand Up @@ -596,33 +538,6 @@
],
"env": {}
},
{
"name": "rnw2tex",
"command": "Rscript",
"args": [
"-e",
"knitr::opts_knit$set(concordance = TRUE); knitr::knit('%DOCFILE_EXT%')"
],
"env": {}
},
{
"name": "jnw2tex",
"command": "julia",
"args": [
"-e",
"using Weave; weave(\"%DOC_EXT%\", doctype=\"tex\")"
],
"env": {}
},
{
"name": "jnw2texmintex",
"command": "julia",
"args": [
"-e",
"using Weave; weave(\"%DOC_EXT%\", doctype=\"texminted\")"
],
"env": {}
},
{
"name": "tectonic",
"command": "tectonic",
Expand Down Expand Up @@ -707,9 +622,7 @@
"type": "string"
},
"default": [
"**/*.tex",
"**/*.rnw",
"**/*.Rnw"
"**/*.tex"
],
"markdownDescription": "Patterns of files to consider for the root detection mechanism. Relative paths are computed from the workspace folder. To detect the root file and the tex file tree, we parse all the `.tex` listed here. If you want to specify all `.tex` files inside directory, say `foo`, and all its subdirectories recursively, you need to use `**/foo/**/*.tex`. If you only want to match `.tex` files at the top level of the workspace, use `*.tex`. For more details, see https://github.com/James-Yu/LaTeX-Workshop/wiki/Compile#multi-file-projects"
},
Expand Down Expand Up @@ -1713,24 +1626,24 @@
"menus": {
"editor/context": [
{
"when": "config.latex-toybox.showContextMenu && editorLangId =~ /^latex$|^latex-expl3$|^rsweave$|^jlweave$/ && !virtualWorkspace",
"when": "config.latex-toybox.showContextMenu && editorLangId =~ /^latex$|^latex-expl3$/ && !virtualWorkspace",
"command": "latex-toybox.build",
"group": "navigation@100"
},
{
"when": "config.latex-toybox.showContextMenu && editorLangId =~ /^latex$|^latex-expl3$|^rsweave$|^jlweave$/ && !virtualWorkspace",
"when": "config.latex-toybox.showContextMenu && editorLangId =~ /^latex$|^latex-expl3$/ && !virtualWorkspace",
"command": "latex-toybox.synctex",
"group": "navigation@101"
}
],
"editor/title": [
{
"when": "editorLangId =~ /^latex$|^latex-expl3$|^rsweave$|^jlweave$/ && !virtualWorkspace",
"when": "editorLangId =~ /^latex$|^latex-expl3$/ && !virtualWorkspace",
"command": "latex-toybox.view",
"group": "navigation@2"
},
{
"when": "editorLangId =~ /^latex$|^latex-expl3$|^rsweave$|^jlweave$/ && !virtualWorkspace",
"when": "editorLangId =~ /^latex$|^latex-expl3$/ && !virtualWorkspace",
"command": "latex-toybox.build",
"group": "navigation@1"
}
Expand Down
8 changes: 1 addition & 7 deletions src/components/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,7 @@ export class Builder {
} else if (defaultRecipeName === 'lastUsed' && this.previouslyUsedRecipe) {
recipe = this.previouslyUsedRecipe
} else if (defaultRecipeName === 'first' || defaultRecipeName === 'lastUsed' && !this.previouslyUsedRecipe) {
let candidates: Recipe[] = recipes
if (languageId === 'rsweave') {
candidates = recipes.filter(candidate => candidate.name.toLowerCase().match('rnw|rsweave'))
} else if (languageId === 'jlweave') {
candidates = recipes.filter(candidate => candidate.name.toLowerCase().match('jnw|jlweave|weave.jl'))
}
recipe = candidates[0]
recipe = recipes[0]
}
if (recipe === undefined) {
this.extension.logger.error(`Failed to resolve build recipe: ${[recipeName, defaultRecipeName]}`)
Expand Down
8 changes: 0 additions & 8 deletions src/components/completionupdater.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as utils from '../utils/utils'
import {latexParser} from 'latex-utensils'
import * as vscode from 'vscode'
import {CommandUpdater} from './completionupdaterlib/commandupdater'
Expand Down Expand Up @@ -66,13 +65,6 @@ export class CompletionUpdater {
this.commandUpdater.update(file, nodes)
} else {
this.extension.logger.info(`Cannot parse a TeX file: ${file}`)
this.extension.logger.info('Fall back to regex-based completion.')
// Do the update with old style.
const contentNoComment = utils.stripCommentsAndVerbatim(content)
this.referenceUpdater.update(file, undefined, undefined, contentNoComment)
this.glossaryUpdater.update(file, undefined, contentNoComment)
this.environmentUpdater.update(file, undefined, undefined, contentNoComment)
this.commandUpdater.update(file, undefined, contentNoComment)
}
if (cache) {
if (isContentOnDisk) {
Expand Down
45 changes: 3 additions & 42 deletions src/components/completionupdaterlib/commandupdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,12 @@ export class CommandUpdater {

/**
* Updates the Manager cache for commands used in `file` with `nodes`.
* If `nodes` is `undefined`, `content` is parsed with regular expressions,
* and the result is used to update the cache.
* @param file The path of a LaTeX file.
* @param nodes AST of a LaTeX file.
* @param content The content of a LaTeX file.
*/
update(file: string, nodes?: latexParser.Node[], content?: string) {
update(file: string, nodes: latexParser.Node[]) {
// First, we must update the package list
this.updatePkg(file, nodes, content)
this.updatePkgWithNodeArray(file, nodes)
// Remove newcommand cmds, because they will be re-insert in the next step
this.definedCmds.forEach((entry,cmd) => {
if (entry.file === file) {
Expand All @@ -41,43 +38,7 @@ export class CommandUpdater {
if (cache === undefined) {
return
}
if (nodes !== undefined) {
cache.element.command = this.commandFinder.getCmdFromNodeArray(file, nodes, new CommandNameDuplicationDetector())
} else if (content !== undefined) {
cache.element.command = this.commandFinder.getCmdFromContent(file, content)
}
}

/**
* Updates the Manager cache for packages used in `file` with `nodes`.
* If `nodes` is `undefined`, `content` is parsed with regular expressions,
* and the result is used to update the cache.
*
* @param file The path of a LaTeX file.
* @param nodes AST of a LaTeX file.
* @param content The content of a LaTeX file.
*/
private updatePkg(file: string, nodes?: latexParser.Node[], content?: string) {
if (nodes !== undefined) {
this.updatePkgWithNodeArray(file, nodes)
} else if (content !== undefined) {
const pkgReg = /\\usepackage(?:\[[^[\]{}]*\])?{(.*)}/g

while (true) {
const result = pkgReg.exec(content)
if (result === null) {
break
}
result[1].split(',').forEach(pkg => {
pkg = pkg.trim()
if (pkg === '') {
return
}
const cache = this.extension.manager.getCachedContent(file)
cache?.element.package.add(pkg)
})
}
}
cache.element.command = this.commandFinder.getCmdFromNodeArray(file, nodes, new CommandNameDuplicationDetector())
}

private updatePkgWithNodeArray(file: string, nodes: latexParser.Node[]) {
Expand Down
Loading

0 comments on commit fb736f2

Please sign in to comment.