smart .chktexrc location
MODIFY
README.md
README.md
@@ -23,6 +23,7 @@ One million downloads! This project won't be successful without contributions fr
- LaTeX log parser, with errors and warnings in LaTeX build automatically reported in VS Code.
- Real-time linting of LaTeX with ChkTeX to pick up common LaTeX issues as you type.
- Code Actions (automatic fixes) are offered for many issues found by ChkTeX.
+ - Auto load `.chktexrc` configure in the following order: 1. manually configured `-l` setting in `chktex.args`; 2. `.chktexrc` file (if exists) in the same folder as the main LaTeX file; 3. `.chktexrc` file (if exists) at the project root folder.
- LaTeX file formatting.
- Auto close LaTeX environments: just call _LaTeX Workshop: Close current environment_ from the **Command Palette**. You can easily assign a shortcut to this action through the **Keyboard Shortcuts** menu, search for `latex-workshop.close-env`.
- Navigate from `\begin/\end` to the corresponding `\end/\begin`: while on the `begin` or `end` keyword, call _LaTeX Workshop: Navigate to matching begin/end_ from the **Command Palette**. To define a shortcut, search for `latex-workshop.navigate-envpair` in the **Keyboard Shortcuts** menu.

MODIFY
src/components/linter.ts
src/components/linter.ts
@@ -15,6 +15,28 @@ export class Linter {
this.extension = extension
}
+ get rcPath() {
+ let rcPath
+ // 0. root file folder
+ const root = this.extension.manager.documentRoot()
+ if (root) {
+ rcPath = path.join(path.dirname(root), '.chktexrc')
+ }
+ if (fs.existsSync(rcPath)) {
+ return rcPath
+ }
+
+ // 1. project root folder
+ const ws = vscode.workspace.workspaceFolders
+ if (ws && ws.length > 0) {
+ rcPath = path.join(ws[0].uri.fsPath, '.chktexrc')
+ }
+ if (fs.existsSync(rcPath)) {
+ return rcPath
+ }
+ return undefined
+ }
+
lintRootFileIfEnabled() {
const configuration = vscode.workspace.getConfiguration('latex-workshop')
const linter = configuration.get('chktex.enabled') as boolean
@@ -53,10 +75,10 @@ export class Linter {
const configuration = vscode.workspace.getConfiguration('latex-workshop')
const command = configuration.get('chktex.path') as string
- const args = configuration.get('chktex.args.active') as string[]
- if (this.extension.manager.rootDir) {
- const rcPath = path.join(this.extension.manager.rootDir, '.chktexrc')
- if (fs.existsSync(rcPath)) {
+ const args = [...(configuration.get('chktex.args.active') as string[])]
+ if (args.indexOf('-l') < 0) {
+ const rcPath = this.rcPath
+ if (rcPath) {
args.push('-l', rcPath)
}
}
@@ -83,10 +105,10 @@ export class Linter {
const configuration = vscode.workspace.getConfiguration('latex-workshop')
const command = configuration.get('chktex.path') as string
- const args = configuration.get('chktex.args.root') as string[]
- if (this.extension.manager.rootDir) {
- const rcPath = path.join(this.extension.manager.rootDir, '.chktexrc')
- if (fs.existsSync(rcPath)) {
+ const args = [...(configuration.get('chktex.args.active') as string[])]
+ if (args.indexOf('-l') < 0) {
+ const rcPath = this.rcPath
+ if (rcPath) {
args.push('-l', rcPath)
}
}

smart .chktexrc location