add: configuration for compile and makeindex processes,
add: LaTeX root file configuration
This commit is contained in:
		
							parent
							
								
									eeea3268a0
								
							
						
					
					
						commit
						97c1c47e72
					
				
							
								
								
									
										29
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								package.json
									
									
									
									
									
								
							| @ -50,7 +50,34 @@ | ||||
| 					"latex.shell": { | ||||
| 						"type": "string", | ||||
| 						"default": "\\bin\\bash", | ||||
| 						"description": "The shell to be used for child processes like the compile commands pdflatex or cleanup commands." | ||||
| 						"description": "The shell to be used for child processes like the compile command." | ||||
| 					} | ||||
| 				} | ||||
| 			}, { | ||||
| 				"title": "LaTeX compile process", | ||||
| 				"properties": { | ||||
| 					"latex.pdflatex": { | ||||
| 						"type": "string", | ||||
| 						"default": "pdflatex -synctex=1 -interaction=nonstopmode -output-directory=\"${fileDirname}\" \"${file}\"", | ||||
| 						"description": "The compile command." | ||||
| 					} | ||||
| 				} | ||||
| 			}, { | ||||
| 				"title": "LaTeX make index process", | ||||
| 				"properties": { | ||||
| 					"latex.makeindex": { | ||||
| 						"type": "string", | ||||
| 						"default": "makeindex ${fileBasenameNoExtension}", | ||||
| 						"description": "The compile command." | ||||
| 					} | ||||
| 				} | ||||
| 			}, { | ||||
| 				"title": "LaTeX root file", | ||||
| 				"properties": { | ||||
| 					"latex.rootFile": { | ||||
| 						"type": "string", | ||||
| 						"default": null, | ||||
| 						"description": "The root file for the compile process, if not set the current file will be used for the compile process. If there is a root file for the cimpilation this property must be specified or you allways have to compile with the root file as current opened file." | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
							
								
								
									
										117
									
								
								src/commands.ts
									
									
									
									
									
								
							
							
						
						
									
										117
									
								
								src/commands.ts
									
									
									
									
									
								
							| @ -3,44 +3,44 @@ import * as child_process from 'child_process'; | ||||
| import documentclass_symbols from '../dictionary/documentclass_symbols'; | ||||
| import { window, Range } from 'vscode'; | ||||
| 
 | ||||
| // /**
 | ||||
| // 	${workspaceFolder} - the path of the workspace folder that contains the tasks.json file
 | ||||
| // 	${workspaceFolderBasename} - the name of the workspace folder that contains the tasks.json file without any slashes (/)
 | ||||
| // 	${file} - the current opened file
 | ||||
| // 	${relativeFile} - the current opened file relative to the workspace folder containing the file
 | ||||
| // 	${fileBasename} - the current opened file's basename
 | ||||
| // 	${fileBasenameNoExtension} - the current opened file's basename without the extension
 | ||||
| // 	${fileDirname} - the current opened file's dirname
 | ||||
| // 	${fileExtname} - the current opened file's extension
 | ||||
| // 	${cwd} - the task runner's current working directory on startup
 | ||||
| // 	${lineNumber} - the current selected line number in the active file
 | ||||
| // */
 | ||||
| // function commandVariableSubstitution(variable: string, document: vscode.TextDocument): string {
 | ||||
| // 	switch (variable) {
 | ||||
| // 		case "${workspaceFolder}":
 | ||||
| // 			throw new Error("[ commandVariableSubstitution ] Not Implemented.");
 | ||||
| // 		case "${workspaceFolderBasename}":
 | ||||
| // 			throw new Error("[ commandVariableSubstitution ] Not Implemented.");
 | ||||
| // 		case "${file}":
 | ||||
| // 			return document.fileName;
 | ||||
| // 		case "${relativeFile}":
 | ||||
| // 			throw new Error("[ commandVariableSubstitution ] Not Implemented.");
 | ||||
| // 		case "${fileBasename}":
 | ||||
| // 			return document.fileName.substring(document.fileName.lastIndexOf('/') + 1);
 | ||||
| // 		case "${fileBasenameNoExtension}":
 | ||||
| // 			return document.fileName.substring(document.fileName.lastIndexOf('/') + 1, document.fileName.lastIndexOf('.'));
 | ||||
| // 		case "${fileDirname}":
 | ||||
| // 			return document.fileName.substring(0, document.fileName.lastIndexOf('/'));
 | ||||
| // 		case "${fileExtname}":
 | ||||
| // 			return document.fileName.substring(document.fileName.lastIndexOf('.') + 1);
 | ||||
| // 		case "${cwd}":
 | ||||
| // 			throw new Error("[ commandVariableSubstitution ] Not supported.");
 | ||||
| // 		case "${lineNumber}":
 | ||||
| // 			throw new Error("[ commandVariableSubstitution ] Not supported.");
 | ||||
| // 		default:
 | ||||
| // 			throw new Error("[ commandVariableSubstitution ] variable not found.");
 | ||||
| // 	}
 | ||||
| // }
 | ||||
| /** | ||||
| 	${workspaceFolder} - the path of the workspace folder that contains the tasks.json file | ||||
| 	${workspaceFolderBasename} - the name of the workspace folder that contains the tasks.json file without any slashes (/) | ||||
| 	${file} - the current opened file | ||||
| 	${relativeFile} - the current opened file relative to the workspace folder containing the file | ||||
| 	${fileBasename} - the current opened file's basename | ||||
| 	${fileBasenameNoExtension} - the current opened file's basename without the extension | ||||
| 	${fileDirname} - the current opened file's dirname | ||||
| 	${fileExtname} - the current opened file's extension | ||||
| 	${cwd} - the task runner's current working directory on startup | ||||
| 	${lineNumber} - the current selected line number in the active file | ||||
| */ | ||||
| function commandVariableSubstitution(variable: string, fileName: string): string { | ||||
| 	switch (variable) { | ||||
| 		case "${workspaceFolder}": | ||||
| 			return vscode.workspace.rootPath; | ||||
| 		case "${workspaceFolderBasename}": | ||||
| 			return vscode.workspace.rootPath; // TODO:
 | ||||
| 		case "${file}": | ||||
| 			return fileName; | ||||
| 		case "${relativeFile}": | ||||
| 			throw new Error("[ commandVariableSubstitution ] Not Implemented."); | ||||
| 		case "${fileBasename}": | ||||
| 			return fileName.substring(fileName.lastIndexOf('/') + 1); | ||||
| 		case "${fileBasenameNoExtension}": | ||||
| 			return fileName.substring(fileName.lastIndexOf('/') + 1, fileName.lastIndexOf('.')); | ||||
| 		case "${fileDirname}": | ||||
| 			return fileName.substring(0, fileName.lastIndexOf('/')); | ||||
| 		case "${fileExtname}": | ||||
| 			return fileName.substring(fileName.lastIndexOf('.') + 1); | ||||
| 		case "${cwd}": | ||||
| 			return vscode.workspace.rootPath; | ||||
| 		case "${lineNumber}": | ||||
| 			throw new Error("[ commandVariableSubstitution ] Not supported."); | ||||
| 		default: | ||||
| 			throw new Error("[ commandVariableSubstitution ] variable not found."); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| var decorationOptions: vscode.DecorationRenderOptions = { | ||||
| 	borderRadius: "3px", | ||||
| @ -69,13 +69,15 @@ export default { | ||||
| 		} | ||||
| 
 | ||||
| 		var document: vscode.TextDocument = textEditor.document; | ||||
| 		var fileDir: string = document.fileName.substring(0, document.fileName.lastIndexOf('/')); | ||||
| 		var fileName: string = this.settings.rootFile || document.fileName; | ||||
| 		var fileDir: string = fileName.substring(0, fileName.lastIndexOf('/')); | ||||
| 		var outputChannel: vscode.OutputChannel = this.outputChannel; | ||||
| 
 | ||||
| 		outputChannel.clear(); // clear the outputChannel to only show the last output
 | ||||
| 		document.save(); // save the document before compile
 | ||||
| 		child_process.exec( | ||||
| 			"pdflatex -synctex=1 -interaction=nonstopmode -output-directory=\"" + fileDir + "\" \"" + document.fileName + "\"", | ||||
| 			// "pdflatex -synctex=1 -interaction=nonstopmode -output-directory=\"" + fileDir + "\" \"" + fileName + "\"",
 | ||||
| 			this.settings.pdflatex.replace(/\$\{[A-Za-z]+\}/g,(str) => commandVariableSubstitution(str, fileName)), | ||||
| 			{ cwd: fileDir }, // set the working directory
 | ||||
| 			(error: Error, stdout: string, stderr: string) => { | ||||
| 				var decorationRanges: vscode.Range[] = []; | ||||
| @ -96,7 +98,7 @@ export default { | ||||
| 					outputChannel.append(output); | ||||
| 				} else { | ||||
| 					vscode.window.setStatusBarMessage("pdflatex succeeded: see output", 5000); | ||||
| 					outputChannel.appendLine("pdflatex succeeded: created file " + document.fileName.replace('.tex', '.pdf')); | ||||
| 					outputChannel.appendLine("pdflatex succeeded: created file " + fileName.replace('.tex', '.pdf')); | ||||
| 				} | ||||
| 				textEditor.setDecorations(LaTeX_error_decoration_type, decorationRanges); | ||||
| 			} | ||||
| @ -109,7 +111,8 @@ export default { | ||||
| 		 | ||||
| 		textEditor.document.save(); // save the document before makeindex
 | ||||
| 		child_process.exec( | ||||
| 			"makeindex " + document.fileName.substring(document.fileName.lastIndexOf('/') + 1, document.fileName.lastIndexOf('.')), | ||||
| 			// "makeindex " + document.fileName.substring(document.fileName.lastIndexOf('/') + 1, document.fileName.lastIndexOf('.')),
 | ||||
| 			this.settings.makeindex.replace(/\$\{[A-Za-z]+\}/g, (str) => commandVariableSubstitution(str, document.fileName)), | ||||
| 			{ cwd: fileDir }, // set the working directory
 | ||||
| 			(error: Error, stdout: string, stderr: string) => { | ||||
| 				if (error) { | ||||
| @ -123,35 +126,5 @@ export default { | ||||
| 				} | ||||
| 			} | ||||
| 		); | ||||
| 	}, | ||||
| 	latex_cleanup: function latex_cleanup(textEditor: vscode.TextEditor, textEditorEdit: vscode.TextEditorEdit): void { | ||||
| 		var document: vscode.TextDocument = textEditor.document; | ||||
| 		var fileDir: string = document.fileName.substring(0, document.fileName.lastIndexOf('/')); | ||||
| 		var fileName: string = document.fileName.substring(document.fileName.lastIndexOf('/') + 1, document.fileName.lastIndexOf('.')); | ||||
| 		var outputChannel: vscode.OutputChannel = this.outputChannel; | ||||
| 
 | ||||
| 		child_process.exec("\ | ||||
| 			for file in \"" + fileName + "\".*; do \ | ||||
| 				for end in \"aux\" \"idx\" \"ilg\" \"ind\" \"log\" \"out\" \"toc\" \"synctex.gz\"; do \ | ||||
| 					if [[ \"$file\" == *.\"$end\" ]]; then \ | ||||
| 						rm \"$file\"; \ | ||||
| 						echo removed: \"$file\"; \ | ||||
| 					fi; \ | ||||
| 				done; \ | ||||
| 			done;", | ||||
| 			{ cwd: fileDir, shell: this.settings["latex.shell"] }, | ||||
| 			(error: Error, stdout: string, stderr: string) => { | ||||
| 				if (error) { | ||||
| 					vscode.window.showErrorMessage("cleanup Failed: see output."); | ||||
| 					outputChannel.show(); | ||||
| 					outputChannel.appendLine("cleanup Failed: " + error.message); | ||||
| 					outputChannel.append(stdout + "\n" + stderr); | ||||
| 				} else { | ||||
| 					vscode.window.setStatusBarMessage("cleanup succeeded", 5000); | ||||
| 					outputChannel.appendLine('Directory "' + fileDir + '" cleaned'); | ||||
| 					outputChannel.append(stdout); | ||||
| 				} | ||||
| 			} | ||||
| 		); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -15,7 +15,6 @@ export function activate(context: vscode.ExtensionContext) { | ||||
| 	// to be equal to the 'command' field in the package.json file
 | ||||
| 	context.subscriptions.push(vscode.commands.registerTextEditorCommand( 'latex.pdflatex', Commands.latex_pdflatex, commands_this_context )); | ||||
| 	context.subscriptions.push(vscode.commands.registerTextEditorCommand( 'latex.makeindex', Commands.latex_makeindex, commands_this_context )); | ||||
| 	context.subscriptions.push(vscode.commands.registerTextEditorCommand( 'latex.cleanup', Commands.latex_cleanup, commands_this_context )); | ||||
| 	 | ||||
| 	// Register the Completion Item Provider
 | ||||
| 	context.subscriptions.push(vscode.languages.registerCompletionItemProvider( | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user