add: Enabled completionItemprovider to work async (added Promise),
add: input, include, ... commands and parameters to *_symbols
This commit is contained in:
parent
0bd3ed39a7
commit
8bce5ac877
|
@ -244,6 +244,12 @@ export default {
|
||||||
"h": { documentation: "hier" },
|
"h": { documentation: "hier" },
|
||||||
"l": { documentation: "low" },
|
"l": { documentation: "low" },
|
||||||
"p": { documentation: "page" },
|
"p": { documentation: "page" },
|
||||||
|
},
|
||||||
|
includegraphics: {
|
||||||
|
width: { detail: "width=<value>", insertText: "width=${0:<value>}", documentation: "scale graphic to the specified <value>.", },
|
||||||
|
height: { detail: "height=<value>", insertText: "height=${0:<value>}", documentation: "scale graphic to the specified <value>.", },
|
||||||
|
angle: { detail: "angle=<value>", insertText: "angle=${0:<value>}", documentation: "rotate graphic counterclockwise.", },
|
||||||
|
scale: { detail: "scale=<value>", insertText: "scale=${0:<value>}", documentation: "scale graphic by <value>.", },
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,13 +3,52 @@ import { latex_types } from "./symbol_types";
|
||||||
var preamble = "Define in preamble!";
|
var preamble = "Define in preamble!";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
"documentclass": { insertText: "documentclass", kind: latex_types.keyword },
|
documentclass: {
|
||||||
|
insertText: "documentclass",
|
||||||
"usepackage": { insertText: "usepackage{$1}", documentation: "usepackage", kind: latex_types.keyword },
|
kind: latex_types.keyword
|
||||||
"newenvironment": { insertText: "newenvironment{${1:name}}[$2]{$3}{$0}", documentation: "newenvironment", kind: latex_types.keyword },
|
},
|
||||||
"newcommand": { insertText: "newcommand{${1:name}}[$2]{$3}", documentation: "newcommand", kind: latex_types.keyword },
|
|
||||||
"renewcommand": { insertText: "renewcommand{${1:name}}[$2]{$3}", documentation: "renewcommand", kind: latex_types.keyword },
|
|
||||||
|
|
||||||
"DeclareMathOperator": { insertText: "DeclareMathOperator{${1:operatorcommand}}{${2:operatorname}}$0", detail: preamble, documentation: "Defines a new math operator. Use the stared version for operators with limits.", kind: latex_types.keyword },
|
usepackage: {
|
||||||
"DeclareMathOperator*": { insertText: "DeclareMathOperator*{${1:operatorcommand}}{${2:operatorname}}$0", detail: preamble, documentation: "Defines a new math operator with limits.", kind: latex_types.keyword },
|
insertText: "usepackage{$1}",
|
||||||
|
documentation: "usepackage",
|
||||||
|
kind: latex_types.keyword
|
||||||
|
},
|
||||||
|
newenvironment: {
|
||||||
|
insertText: "newenvironment{${1:name}}[$2]{$3}{$0}",
|
||||||
|
documentation: "newenvironment",
|
||||||
|
kind: latex_types.keyword
|
||||||
|
},
|
||||||
|
newcommand: {
|
||||||
|
insertText: "newcommand{${1:name}}[$2]{$3}",
|
||||||
|
documentation: "newcommand",
|
||||||
|
kind: latex_types.keyword
|
||||||
|
},
|
||||||
|
renewcommand: {
|
||||||
|
insertText: "renewcommand{${1:name}}[$2]{$3}",
|
||||||
|
documentation: "renewcommand",
|
||||||
|
kind: latex_types.keyword
|
||||||
|
},
|
||||||
|
|
||||||
|
includeonly: {
|
||||||
|
documentation: "After this command is executed in the preamble of the document, only \\include commands for the filenames which are listed in the argument of the \\includeonly command will be executed. Note that there must be no spaces between the filenames and the commas.",
|
||||||
|
kind: latex_types.keyword
|
||||||
|
},
|
||||||
|
input: {
|
||||||
|
documentation: "Includes the sourcecode from the target .tex file.",
|
||||||
|
kind: latex_types.keyword
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
DeclareMathOperator: {
|
||||||
|
insertText: "DeclareMathOperator{${1:operatorcommand}}{${2:operatorname}}$0",
|
||||||
|
detail: preamble,
|
||||||
|
documentation: "Defines a new math operator. Use the stared version for operators with limits.",
|
||||||
|
kind: latex_types.keyword
|
||||||
|
},
|
||||||
|
"DeclareMathOperator*": {
|
||||||
|
insertText: "DeclareMathOperator*{${1:operatorcommand}}{${2:operatorname}}$0",
|
||||||
|
detail: preamble,
|
||||||
|
documentation: "Defines a new math operator with limits.",
|
||||||
|
kind: latex_types.keyword
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,30 @@
|
||||||
import { latex_types } from "./symbol_types";
|
import { latex_types } from "./symbol_types";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
input: {
|
||||||
|
detail: "\\input{<filename>}",
|
||||||
|
insertText: "input{${0:<filename>}}",
|
||||||
|
documentation: "Includes the sourcecode from the target .tex file.",
|
||||||
|
kind: latex_types.keyword
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
detail: "\\include{<filename>}",
|
||||||
|
insertText: "include{${0:<filename>}}",
|
||||||
|
documentation: "Includes the rendered content from the target .tex file on a new page. Note: If \\includeonly is specified in the preamble, all NOT specified files are ignored.",
|
||||||
|
kind: latex_types.keyword
|
||||||
|
},
|
||||||
|
includegraphics: {
|
||||||
|
detail: "\\includegraphics[<key>=<value>,...]{<filename>}\nRequired package \"graphicx\"",
|
||||||
|
insertText: "includegraphics[$1]{${0:<filename>}}",
|
||||||
|
documentation: "Use the command \\includegraphics[<key>=<value>,...]{<file>} to include <file> into your document. The optional parameter accepts a comma separated list of <key>'s and associated <value>'s. The <key>'s can be used to alter the width, height and rotation of the included graphic.",
|
||||||
|
kind: latex_types.keyword
|
||||||
|
},
|
||||||
|
verbatiminput: {
|
||||||
|
detail: "\\verbatiminput{<filename>}\nRequired package \"verbatim\"",
|
||||||
|
insertText: "verbatiminput{${0:<filename>}}",
|
||||||
|
documentation: "Allows to include raw ASCII text into your document as if it was inside a verbatim environment.",
|
||||||
|
kind: latex_types.keyword
|
||||||
|
},
|
||||||
|
|
||||||
"usepackage": { insertText: "usepackage{$1}", documentation: "usepackage", kind: latex_types.keyword },
|
"usepackage": { insertText: "usepackage{$1}", documentation: "usepackage", kind: latex_types.keyword },
|
||||||
"newenvironment": { insertText: "newenvironment{${1:name}}[$2]{$3}{$0}", documentation: "newenvironment", kind: latex_types.keyword },
|
"newenvironment": { insertText: "newenvironment{${1:name}}[$2]{$3}{$0}", documentation: "newenvironment", kind: latex_types.keyword },
|
||||||
|
|
|
@ -8,6 +8,8 @@ import environment_symbols from '../dictionary/environment_symbols';
|
||||||
import tikz_symbols from '../dictionary/tikz_symbols';
|
import tikz_symbols from '../dictionary/tikz_symbols';
|
||||||
import parameter_dictionary from '../dictionary/parameter_dictionary';
|
import parameter_dictionary from '../dictionary/parameter_dictionary';
|
||||||
|
|
||||||
|
import * as child_process from 'child_process';
|
||||||
|
|
||||||
function convertToItemKind(type: latex_types): vscode.CompletionItemKind {
|
function convertToItemKind(type: latex_types): vscode.CompletionItemKind {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case latex_types.symbol:
|
case latex_types.symbol:
|
||||||
|
@ -220,53 +222,88 @@ export default class Provider implements vscode.CompletionItemProvider {
|
||||||
return filtert_symbols;
|
return filtert_symbols;
|
||||||
}
|
}
|
||||||
|
|
||||||
provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): vscode.CompletionItem[] {
|
|
||||||
var line = document.lineAt(position);
|
|
||||||
if (line.isEmptyOrWhitespace) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
var line_text = line.text;
|
|
||||||
var line_before_pos = line_text.substring(0, position.character).trim();
|
|
||||||
|
|
||||||
var start_index: number;
|
// // var p: Promise<string> = new Promise (function (resolve: (str: string) => void, reject: (str: string) => void) {
|
||||||
var end_index: number;
|
// // const argumentOfThen: string = "hello from Promise";
|
||||||
var symbol_lable: string;
|
// // resolve(argumentOfThen);
|
||||||
var symbol_parameter: string;
|
// // }).then((result) => {
|
||||||
if ((start_index = line_before_pos.lastIndexOf("\\") + 1) > 0) {
|
// // return result;
|
||||||
if ((end_index = line_before_pos.indexOf("{", start_index)) > -1) {
|
// // });
|
||||||
symbol_lable = line_before_pos.substring(start_index, end_index);
|
// /**
|
||||||
symbol_parameter = line_before_pos.substring(end_index + 1);
|
// * Encapsulates results from syncrone calculations in a promise and passes them throuw immediately
|
||||||
switch (symbol_lable) {
|
// * @param result The return value from .then's function
|
||||||
case "begin":
|
// */
|
||||||
case "end":
|
// private promiseResult(result: vscode.CompletionItem[]): Thenable<vscode.CompletionItem[]> {
|
||||||
return this.filterSymbols(this.environment_symbols, symbol_parameter, position);
|
// return new Promise<vscode.CompletionItem[]>((resolve, reject) => { resolve(result); }).then((res) => res);
|
||||||
case "ref":
|
// }
|
||||||
case "eqref":
|
|
||||||
case "pageref":
|
private getFileNames(path: string, resolve: (completionItems: vscode.CompletionItem[]) => void, reject: (message: string) => void): void {
|
||||||
return this.searchAndCreateLableSymbols(document, symbol_parameter, position);
|
child_process.exec("ls " + path + " -t", (error: Error, stdout: string, stderr: string) => {
|
||||||
case "usepackage": // provide package symbols by first all usepackage parameters before the last ","
|
var fileNames = stdout.split("\n");
|
||||||
return this.filterSymbols(this.package_symbols, symbol_parameter.substring(symbol_parameter.lastIndexOf(",") + 1).trim(), position);
|
var completionItems = new Array<vscode.CompletionItem>();
|
||||||
default: // default to NO suggestions
|
for (var i = 0; i < fileNames.length; i++) {
|
||||||
return [];
|
completionItems.push(new vscode.CompletionItem(fileNames[i], vscode.CompletionItemKind.File));
|
||||||
}
|
}
|
||||||
} else if ((end_index = line_before_pos.indexOf("[", start_index)) > -1) {
|
resolve(completionItems);
|
||||||
symbol_lable = line_before_pos.substring(start_index, end_index);
|
});
|
||||||
symbol_parameter = line_before_pos.substring(end_index + 1)
|
}
|
||||||
return this.filterParameters(symbol_lable, symbol_parameter.substring(symbol_parameter.lastIndexOf(",") + 1).trim(), position);
|
|
||||||
} else {
|
provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Thenable<vscode.CompletionItem[]> {
|
||||||
symbol_lable = line_before_pos.substring(start_index);
|
return new Promise<vscode.CompletionItem[]>((resolve, reject) => {
|
||||||
switch (this.getEnvironmentType(document, line_before_pos, position)) {
|
var line = document.lineAt(position);
|
||||||
case "math":
|
if (line.isEmptyOrWhitespace) {
|
||||||
return this.filterSymbols(this.math_symbols, symbol_lable, position);
|
return resolve([]);
|
||||||
case "tikz":
|
}
|
||||||
return this.filterSymbols(this.tikz_symbols, symbol_lable, position);
|
var line_text = line.text;
|
||||||
case "text":
|
var line_before_pos = line_text.substring(0, position.character).trim();
|
||||||
return this.filterSymbols(this.text_symbols, symbol_lable, position);
|
|
||||||
default:
|
var start_index: number;
|
||||||
return this.filterSymbols(this.preamble_symbols, symbol_lable, position);
|
var end_index: number;
|
||||||
|
var symbol_lable: string;
|
||||||
|
var symbol_parameter: string;
|
||||||
|
if ((start_index = line_before_pos.lastIndexOf("\\") + 1) > 0) {
|
||||||
|
if ((end_index = line_before_pos.indexOf("{", start_index)) > -1) {
|
||||||
|
symbol_lable = line_before_pos.substring(start_index, end_index);
|
||||||
|
symbol_parameter = line_before_pos.substring(end_index + 1);
|
||||||
|
if ((end_index = symbol_lable.indexOf("[")) > -1) { // check for optional symbol parameters and ignore them if present
|
||||||
|
symbol_lable = symbol_lable.substring(0, end_index);
|
||||||
|
}
|
||||||
|
switch (symbol_lable) {
|
||||||
|
case "begin":
|
||||||
|
case "end":
|
||||||
|
return resolve(this.filterSymbols(this.environment_symbols, symbol_parameter, position));
|
||||||
|
case "ref":
|
||||||
|
case "eqref":
|
||||||
|
case "pageref":
|
||||||
|
return resolve(this.searchAndCreateLableSymbols(document, symbol_parameter, position));
|
||||||
|
case "usepackage": // provide package symbols by first all usepackage parameters before the last ","
|
||||||
|
return resolve(this.filterSymbols(this.package_symbols, symbol_parameter.substring(symbol_parameter.lastIndexOf(",") + 1).trim(), position));
|
||||||
|
case "input":
|
||||||
|
case "include":
|
||||||
|
case "includegraphics":
|
||||||
|
return this.getFileNames(symbol_parameter, resolve, reject); // runs async -> let getFileNames resolve / reject the promise
|
||||||
|
default: // default to NO suggestions
|
||||||
|
return resolve([]);
|
||||||
|
}
|
||||||
|
} else if ((end_index = line_before_pos.indexOf("[", start_index)) > -1) {
|
||||||
|
symbol_lable = line_before_pos.substring(start_index, end_index);
|
||||||
|
symbol_parameter = line_before_pos.substring(end_index + 1)
|
||||||
|
return resolve(this.filterParameters(symbol_lable, symbol_parameter.substring(symbol_parameter.lastIndexOf(",") + 1).trim(), position));
|
||||||
|
} else {
|
||||||
|
symbol_lable = line_before_pos.substring(start_index);
|
||||||
|
switch (this.getEnvironmentType(document, line_before_pos, position)) {
|
||||||
|
case "math":
|
||||||
|
return resolve(this.filterSymbols(this.math_symbols, symbol_lable, position));
|
||||||
|
case "tikz":
|
||||||
|
return resolve(this.filterSymbols(this.tikz_symbols, symbol_lable, position));
|
||||||
|
case "text":
|
||||||
|
return resolve(this.filterSymbols(this.text_symbols, symbol_lable, position));
|
||||||
|
default:
|
||||||
|
return resolve(this.filterSymbols(this.preamble_symbols, symbol_lable, position));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
resolve([]);
|
||||||
return [];
|
}).then((res) => res);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue