mirror of
https://github.com/James-Yu/LaTeX-Workshop.git
synced 2024-10-04 23:27:20 +03:00
support multi root workspace
This commit is contained in:
parent
d4745fcd16
commit
8851da05da
4082
package-lock.json
generated
Normal file
4082
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -12,7 +12,7 @@
|
||||
"url": "https://github.com/James-Yu/LaTeX-Workshop.git"
|
||||
},
|
||||
"engines": {
|
||||
"vscode": "^1.13.0"
|
||||
"vscode": "^1.17.2"
|
||||
},
|
||||
"categories": [
|
||||
"Languages",
|
||||
@ -453,7 +453,7 @@
|
||||
"@types/ws": "^0.0.39",
|
||||
"tslint": "^5.0.0",
|
||||
"typescript": "^2.0.3",
|
||||
"vscode": "^1.0.0",
|
||||
"vscode": "^1.1.6",
|
||||
"webpack": "^2.7.0"
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,8 @@ import {Extension} from '../main'
|
||||
|
||||
export class Manager {
|
||||
extension: Extension
|
||||
rootFile: string
|
||||
rootFiles: object
|
||||
workspace: string
|
||||
texFileTree: { [id: string]: Set<string> } = {}
|
||||
fileWatcher: chokidar.FSWatcher
|
||||
bibWatcher: chokidar.FSWatcher
|
||||
@ -15,13 +16,23 @@ export class Manager {
|
||||
|
||||
constructor(extension: Extension) {
|
||||
this.extension = extension
|
||||
this.watched = []
|
||||
this.watched = []
|
||||
this.rootFiles = {}
|
||||
this.workspace = ''
|
||||
}
|
||||
|
||||
get rootDir() {
|
||||
return path.dirname(this.rootFile)
|
||||
}
|
||||
|
||||
get rootFile() {
|
||||
return this.rootFiles[this.workspace]
|
||||
}
|
||||
|
||||
set rootFile(root: string) {
|
||||
this.rootFiles[this.workspace] = root
|
||||
}
|
||||
|
||||
tex2pdf(texPath: string) {
|
||||
const configuration = vscode.workspace.getConfiguration('latex-workshop')
|
||||
const outputDir = configuration.get('latex.outputDir') as string
|
||||
@ -32,7 +43,24 @@ export class Manager {
|
||||
return ['.tex', '.sty', '.cls', '.bbx', '.cbx'].indexOf(path.extname(filePath)) > -1
|
||||
}
|
||||
|
||||
updateWorkspace() {
|
||||
let wsroot = vscode.workspace.rootPath
|
||||
if (vscode.window.activeTextEditor && vscode.workspace.getWorkspaceFolder(vscode.window.activeTextEditor.document.uri)) {
|
||||
wsroot = vscode.workspace.getWorkspaceFolder(vscode.window.activeTextEditor.document.uri).uri.fsPath
|
||||
}
|
||||
if (wsroot) {
|
||||
if (wsroot !== this.workspace) {
|
||||
this.workspace = wsroot
|
||||
this.extension.nodeProvider.refresh()
|
||||
this.extension.nodeProvider.update()
|
||||
}
|
||||
} else {
|
||||
this.workspace = ''
|
||||
}
|
||||
}
|
||||
|
||||
findRoot() : string | undefined {
|
||||
this.updateWorkspace()
|
||||
const findMethods = [() => this.findRootMagic(), () => this.findRootSelf(), () => this.findRootSaved(), () => this.findRootDir()]
|
||||
for (const method of findMethods) {
|
||||
const rootFile = method()
|
||||
@ -88,22 +116,22 @@ export class Manager {
|
||||
findRootDir() : string | undefined {
|
||||
const regex = /\\begin{document}/m
|
||||
|
||||
if (!vscode.workspace.rootPath) {
|
||||
if (!this.workspace) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
try {
|
||||
const files = fs.readdirSync(vscode.workspace.rootPath)
|
||||
const files = fs.readdirSync(this.workspace)
|
||||
for (let file of files) {
|
||||
if (path.extname(file) !== '.tex') {
|
||||
continue
|
||||
}
|
||||
file = path.join(vscode.workspace.rootPath, file)
|
||||
file = path.join(this.workspace, file)
|
||||
const content = fs.readFileSync(file)
|
||||
|
||||
const result = content.toString().match(regex)
|
||||
if (result) {
|
||||
file = path.resolve(vscode.workspace.rootPath, file)
|
||||
file = path.resolve(this.workspace, file)
|
||||
this.extension.logger.addLogMessage(`Found root file in root directory: ${file}`)
|
||||
return file
|
||||
}
|
||||
|
@ -26,8 +26,12 @@ export class SectionNodeProvider implements vscode.TreeDataProvider<Section> {
|
||||
}
|
||||
|
||||
refresh() : Section[] {
|
||||
this.ds = this.buildModel(this.extension.manager.rootFile)
|
||||
return this.ds
|
||||
if (this.extension.manager.rootFile) {
|
||||
this.ds = this.buildModel(this.extension.manager.rootFile)
|
||||
return this.ds
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
update() {
|
||||
|
Loading…
Reference in New Issue
Block a user