Skip to content

Commit

Permalink
- Rename to findFileInDirs
Browse files Browse the repository at this point in the history
- Drop support for latex-toybox.intellisense.package.dirs
  • Loading branch information
tamuratak committed Sep 11, 2023
1 parent 322cd9f commit 7f8bed7
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 48 deletions.
9 changes: 0 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1211,15 +1211,6 @@
"default": true,
"markdownDescription": "If true, every environment provided by an included package is available by a snippet `\\envname`. Only applies when `#latex-toybox.intellisense.package.enabled#` is true. "
},
"latex-toybox.intellisense.package.dirs": {
"scope": "window",
"type": "array",
"items": {
"type": "string"
},
"default": [],
"markdownDescription": "List of extra directories to look for package completion files in addition to those provided by the extension. See https://github.com/James-Yu/LaTeX-Workshop/wiki/Intellisense#commands-starting-with- to learn how to generate these files. Files found in these directories have a higher priority over the default ones. This setting is only relevant when `#latex-toybox.intellisense.package.env.enabled#` is true."
},
"latex-toybox.intellisense.includegraphics.preview.enabled": {
"scope": "window",
"type": "boolean",
Expand Down
2 changes: 1 addition & 1 deletion src/components/managerlib/finderutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class FinderUtils {
const regex = /(?:\\documentclass\[(.*)\]{subfiles})/
const result = content.match(regex)
if (result) {
const file = await utils.resolveFile([path.dirname(vscode.window.activeTextEditor.document.fileName)], result[1])
const file = await utils.findFileInDirs([path.dirname(vscode.window.activeTextEditor.document.fileName)], result[1])
if (file) {
this.extension.logger.info(`Found root file of this subfile from active editor: ${file}`)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/components/managerlib/pathutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class PathUtils {
} else {
searchDirs = [baseDir, ...bibDirs]
}
const bibPath = await utils.resolveFile(searchDirs, bib, '.bib')
const bibPath = await utils.findFileInDirs(searchDirs, bib, '.bib')

if (!bibPath) {
this.extension.logger.info(`Cannot find .bib file: ${bib}`)
Expand Down
8 changes: 4 additions & 4 deletions src/components/structurelib/sectionnodeprovider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from 'vscode'
import * as path from 'path'
import { latexParser } from 'latex-utensils'
import { Section, SectionKind } from '../structure'
import { resolveFile } from '../../utils/utils'
import { findFileInDirs } from '../../utils/utils'
import { buildLaTeXHierarchy } from './sectionnodeproviderlib/structure'
import { setLastLineOfEachSection } from './sectionnodeproviderlib/utils'
import { captionify, findEnvCaption } from './sectionnodeproviderlib/caption'
Expand Down Expand Up @@ -289,7 +289,7 @@ export class SectionNodeProvider implements vscode.TreeDataProvider<Section> {
if (['input', 'InputIfFileExists', 'include', 'SweaveInput',
'subfile', 'loadglsentries'].includes(node.name.replace(/\*$/, ''))
&& cmdArgs.length > 0) {
candidate = await resolveFile(
candidate = await findFileInDirs(
[
path.dirname(file),
path.dirname(this.extension.manager.rootFile || ''),
Expand All @@ -301,7 +301,7 @@ export class SectionNodeProvider implements vscode.TreeDataProvider<Section> {
// \import{sections/}{section1.tex}
if (['import', 'inputfrom', 'includefrom'].includes(node.name.replace(/\*$/, ''))
&& cmdArgs.length > 1) {
candidate = await resolveFile(
candidate = await findFileInDirs(
[
cmdArgs[0],
path.join(path.dirname(this.extension.manager.rootFile || ''), cmdArgs[0])
Expand All @@ -312,7 +312,7 @@ export class SectionNodeProvider implements vscode.TreeDataProvider<Section> {
// \subimport{01-IntroDir/}{01-Intro.tex}
if (['subimport', 'subinputfrom', 'subincludefrom'].includes(node.name.replace(/\*$/, ''))
&& cmdArgs.length > 1) {
candidate = await resolveFile(
candidate = await findFileInDirs(
[path.dirname(file)],
path.join(cmdArgs[0], cmdArgs[1])
)
Expand Down
27 changes: 1 addition & 26 deletions src/providers/completionlib/commandlib/commandlib.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import * as vscode from 'vscode'
import { existsPath } from '../../../lib/lwfs/lwfs'
import {CmdEnvSuggestion} from '../command'
import { CmdEnvSuggestion } from '../command'


/**
Expand All @@ -14,29 +12,6 @@ export function isTriggerSuggestNeeded(name: string): boolean {
return reg.test(name)
}

export async function resolveCmdEnvFile(name: string, dataDir: string) {
const dirs = vscode.workspace.getConfiguration('latex-toybox').get('intellisense.package.dirs') as string[]
dirs.push(dataDir)
for (const dir of dirs) {
const f = `${dir}/${name}`
if (await existsPath(f)) {
return f
}
}
// Many package with names like toppackage-config.sty are just wrappers around
// the general package toppacke.sty and do not define commands on their own.
const suffix = name.substring(name.lastIndexOf('_'))
const indexDash = name.lastIndexOf('-')
if (indexDash > - 1) {
const generalPkg = name.substring(0, indexDash)
const f = `${dataDir}/${generalPkg}${suffix}`
if (await existsPath(f)) {
return f
}
}
return undefined
}

export class CommandSignatureDuplicationDetector {
private readonly cmdSignatureList: Set<string> = new Set<string>()

Expand Down
4 changes: 2 additions & 2 deletions src/providers/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class DefinitionProvider implements vscode.DefinitionProvider {
}

if (line.match(regexDocumentclass)) {
return utils.resolveFile([path.dirname(vscode.window.activeTextEditor.document.fileName)], token, '.cls')
return utils.findFileInDirs([path.dirname(vscode.window.activeTextEditor.document.fileName)], token, '.cls')
}

let dirs: string[] = []
Expand All @@ -43,7 +43,7 @@ export class DefinitionProvider implements vscode.DefinitionProvider {
}

if (dirs.length > 0) {
return utils.resolveFile(dirs, token, '.tex')
return utils.findFileInDirs(dirs, token, '.tex')
}
return undefined
}
Expand Down
8 changes: 4 additions & 4 deletions src/utils/inputfilepath.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as vscode from 'vscode'
import * as path from 'path'

import { resolveFile } from './utils'
import { findFileInDirs } from './utils'


interface MatchPath {
Expand Down Expand Up @@ -61,14 +61,14 @@ export class InputFileRegExp {

if (match.matchedString.startsWith('\\subimport') || match.matchedString.startsWith('\\subinputfrom') || match.matchedString.startsWith('\\subincludefrom')) {
if (match.directory) {
return resolveFile([path.dirname(currentFile)], path.join(match.directory, match.path))
return findFileInDirs([path.dirname(currentFile)], path.join(match.directory, match.path))
}
} else if (match.matchedString.startsWith('\\import') || match.matchedString.startsWith('\\inputfrom') || match.matchedString.startsWith('\\includefrom')) {
if (match.directory) {
return resolveFile([match.directory, path.join(path.dirname(rootFile), match.directory)], match.path)
return findFileInDirs([match.directory, path.join(path.dirname(rootFile), match.directory)], match.path)
}
} else {
return resolveFile([path.dirname(currentFile), path.dirname(rootFile), ...texDirs], match.path)
return findFileInDirs([path.dirname(currentFile), path.dirname(rootFile), ...texDirs], match.path)
}
return
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export type CommandArgument = {
* @param suffix The suffix of the input file
* @return an absolute path or undefined if the file does not exist
*/
export async function resolveFile(dirs: string[], inputFile: string, suffix: string = '.tex') {
export async function findFileInDirs(dirs: string[], inputFile: string, suffix: string = '.tex') {
if (inputFile.startsWith('/')) {
dirs.unshift('')
}
Expand Down

0 comments on commit 7f8bed7

Please sign in to comment.