Skip to content
Snippets Groups Projects
Commit b06e909e authored by Jerome Lelong's avatar Jerome Lelong
Browse files

Refactor latex.extraExts config to allow live changes

parent 5c821656
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ import { lw } from '../lw'
const logger = lw.log('File')
let extraTeXExts: string[]
export const file = {
tmpDirPath: '',
getOutDir,
......@@ -31,6 +32,12 @@ export function initialize() {
file.tmpDirPath = createTmpDir()
}
setExtraTeXExts()
lw.onConfigChange('latex.extraExts', setExtraTeXExts)
function setExtraTeXExts() {
extraTeXExts = vscode.workspace.getConfiguration('latex-workshop').get('latex.extraExts', []) as string[]
}
/**
* Creates a temporary directory and returns its path as a string.
*
......@@ -87,8 +94,9 @@ function handleTmpDirError(error: Error) {
* This function verifies whether a provided file extension string matches any
* of the TeX-related extensions defined in several constant arrays. It
* consolidates these arrays into a single collection and checks if the given
* extension exists within this collection. The arrays include TeX extensions, R
* Sweave extensions, Julia Weave extensions, and Python Weave extensions.
* extension exists within this collection. The arrays include TeX extensions
* (including those defined by the user ), R Sweave extensions, Julia Weave extensions,
* and Python Weave extensions.
*
* @param {string} extname - The file extension to be checked including the dot
* (e.g., '.tex').
......@@ -97,8 +105,8 @@ function handleTmpDirError(error: Error) {
*/
function hasTeXExt(extname: string): boolean {
return [
...extraTeXExts,
...lw.constant.TEX_EXT,
...lw.constant.EXTRA_TEX_EXT,
...lw.constant.RSWEAVE_EXT,
...lw.constant.JLWEAVE_EXT,
...lw.constant.PWEAVE_EXT
......@@ -112,9 +120,10 @@ function hasTeXExt(extname: string): boolean {
* This function evaluates the given file extension and checks it against a
* predefined list of TeX source extensions such as `.tex`, `.ltx`, `.sty`,
* `.cls`, `.fd`, `.aux`, `.bbl`, `.blg`, `.brf`, `.log`, `.out`, and R Sweave
* extensions, Julia Weave extensions, and Python Weave extensions. It returns
* `true` if the extension is not found in this list, and `false` otherwise.
* This is useful for filtering out non-TeX files from a collection of files.
* extensions, Julia Weave extensions, Python Weave extensions and user defined
* tex extensions. It returns `true` if the extension is not found in this list,
* and `false` otherwise. This is useful for filtering out non-TeX files from a
* collection of files.
*
* @param {string} extname - The file extension to be checked including the dot
* (e.g., '.tex').
......@@ -123,8 +132,8 @@ function hasTeXExt(extname: string): boolean {
*/
function hasBinaryExt(extname: string): boolean {
return ![
...extraTeXExts,
...lw.constant.TEX_EXT,
...lw.constant.EXTRA_TEX_EXT,
...lw.constant.TEX_NOCACHE_EXT,
...lw.constant.RSWEAVE_EXT,
...lw.constant.JLWEAVE_EXT,
......
......@@ -60,7 +60,6 @@ export const lw = {
const constant = {
TEX_EXT: ['.tex', '.bib'],
EXTRA_TEX_EXT: vscode.workspace.getConfiguration('latex-workshop').get('latex.extraExts', []) as string[],
TEX_NOCACHE_EXT: ['.cls', '.sty', '.bst', '.bbx', '.cbx', '.def', '.cfg'],
RSWEAVE_EXT: ['.rnw', '.Rnw', '.rtex', '.Rtex', '.snw', '.Snw'],
JLWEAVE_EXT: ['.jnw', '.jtexw'],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment