Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getAll = ourWords[1] == undefined;
const rx = new RegExp('^' + ourWords[1]);
// Idiotic Macros
if (this.reference.macroExists(ourWords[0])) {
const macroVal = this.reference.macroGetMacroValue(ourWords[0]);
if (macroVal) ourWords[0] = macroVal;
}
// Variables
const variableList = this.reference.instGetAllInsts(ourWords[0]);
for (const thisVar of variableList) {
if (rx.test(thisVar) || getAll) {
workingArray.push({
label: thisVar,
kind: CompletionItemKind.Variable,
textEdit: {
newText: thisVar,
range: Range.create(params.position, params.position)
}
});
}
}
// Enums
const enumMembers = this.reference.enumGetMemberNames(ourWords[0]);
if (enumMembers) {
for (const enumMember of enumMembers) {
if (rx.test(enumMember) || getAll) {
workingArray.push({
label: enumMember,
kind: CompletionItemKind.EnumMember,
// Find out which trait we're in
for (var i = 0, l = this.currentFileNode.traits.length; i < l; i++) {
let traitNode = this.currentFileNode.traits[i];
funcs = funcs.concat(traitNode.methods.filter(item => {
return this.withinBlock(item);
}));
}
if (funcs.length > 0) {
if (options.localVariables) {
for (var i = 0, l:number = funcs[0].scopeVariables.length; i < l; i++) {
let item = funcs[0].scopeVariables[i];
toReturn.push({ label: item.name, kind: CompletionItemKind.Variable, detail: `(variable) : ${item.type}` });
}
}
if (options.parameters) {
for (var i = 0, l:number = funcs[0].params.length; i < l; i++) {
let item = funcs[0].params[i];
toReturn.push({ label: item.name, kind: CompletionItemKind.Property, detail: `(parameter) : ${item.type}` });
}
}
if (options.globalVariables) {
for (var i = 0, l:number = funcs[0].globalVariables.length; i < l; i++) {
let item = funcs[0].globalVariables[i];
// TODO -- look up original variable to find the type
private createVariableCompletionItem(text: string, prefixLength: number, offset: number, brace: boolean, documentation: string): CompletionItem {
text = brace ? "${" + text + '}' : '$' + text
return {
textEdit: this.createTextEdit(prefixLength, offset, text),
label: text,
kind: CompletionItemKind.Variable,
insertTextFormat: InsertTextFormat.PlainText,
documentation: documentation
};
}
argNameMap.forEach(argName => {
const similarity = StringUtils.computeCompletionSimilarity(priorWord, argName);
if (similarity > similarityLimit) {
const completionItem = CompletionItem.create(argName);
completionItem.kind = CompletionItemKind.Variable;
const completionItemData: CompletionItemData = {
workspacePath: this._workspacePath,
filePath: this._filePath,
position: this._position
};
completionItem.data = completionItemData;
completionItem.sortText = this._makeSortText(SortCategory.NamedParameter, argName);
completionList.items.push(completionItem);
}
});
}
.map((name) => {
const list: IIdentifier[] = items[name];
return {
label: name,
kind: CompletionItemKind.Variable,
sortText,
documentation: "User defined variable",
insertText: name,
insertTextFormat: InsertTextFormat.PlainText,
data: list || [],
};
});
}
}
function buildFullFunctionSignature(docObject: MarkLogicFnDocsObject): string {
let neededParams: MarkLogicParamsObject[] = docObject.params.filter(p => {return p.optional !== true});
let optionParams: MarkLogicParamsObject[] = docObject.params.filter(p => {return p.optional === true});
let neededParamsString = neededParams.map(p => {return '$'+p.name+' as '+p.type }).join(",\n\t");
let optionParamsString = optionParams.map(p => {return '[$'+p.name+' as '+p.type+']'}).join(",\n\t");
let middleComma = ''; if (neededParams.length > 0 && optionParams.length > 0) middleComma = ",\n\t";
let nothing: string = docObject.params.length ? "\n\t" : "";
return `${docObject.prefix}:${docObject.name}(${nothing}${neededParamsString}${middleComma}${optionParamsString})
as ${docObject.return}`
}
let xqToVscCompletions: {[key:string]: CompletionItemKind} = {
"function": CompletionItemKind.Function,
"Let binding": CompletionItemKind.Variable,
"Window variable": CompletionItemKind.Variable,
"Local variable": CompletionItemKind.Variable,
"Function parameter": CompletionItemKind.Variable,
"prefix": CompletionItemKind.Class
}
export {
allMlFunctions, allMlNamespaces
}
detail: this.description
};
}
get_signature(): SignatureInformation {
return {
label: this.detail,
documentation: this.description,
parameters: this.params
};
}
}
export class DefineCompletion implements Completion {
name: string;
kind = CompletionItemKind.Variable;
constructor(name: string) {
this.name = name;
}
to_completion_item(): CompletionItem {
return {
label: this.name,
kind: this.kind,
};
}
get_signature(): SignatureInformation {
return undefined;
}
}
function convertKind(kind: ts.ScriptElementKind): CompletionItemKind {
switch (kind) {
case "primitive type":
case "keyword":
return CompletionItemKind.Keyword;
case "var":
case "local var":
return CompletionItemKind.Variable;
case "property":
case "getter":
case "setter":
return CompletionItemKind.Field;
case "function":
case "method":
case "construct":
case "call":
case "index":
return CompletionItemKind.Function;
case "enum":
return CompletionItemKind.Enum;
case "module":
return CompletionItemKind.Module;
case "class":
return CompletionItemKind.Class;
function buildFullFunctionSignature(docObject: MarkLogicFnDocsObject): string {
let neededParams: MarkLogicParamsObject[] = docObject.params.filter(p => {return p.optional !== true});
let optionParams: MarkLogicParamsObject[] = docObject.params.filter(p => {return p.optional === true});
let neededParamsString = neededParams.map(p => {return '$'+p.name+' as '+p.type }).join(",\n\t");
let optionParamsString = optionParams.map(p => {return '[$'+p.name+' as '+p.type+']'}).join(",\n\t");
let middleComma = ''; if (neededParams.length > 0 && optionParams.length > 0) middleComma = ",\n\t";
let nothing: string = docObject.params.length ? "\n\t" : "";
return `${docObject.prefix}:${docObject.name}(${nothing}${neededParamsString}${middleComma}${optionParamsString})
as ${docObject.return}`
}
let xqToVscCompletions: {[key:string]: CompletionItemKind} = {
"function": CompletionItemKind.Function,
"Let binding": CompletionItemKind.Variable,
"Window variable": CompletionItemKind.Variable,
"Local variable": CompletionItemKind.Variable,
"Function parameter": CompletionItemKind.Variable,
"prefix": CompletionItemKind.Class
}
export {
allMlFunctions, allMlNamespaces
}
private getItemKind(type: string): CompletionItemKind {
if (type.match(/.*\(.*\)/)) {
return CompletionItemKind.Function
}
else if (type.match(/^enum /)) {
return CompletionItemKind.Enum
}
else if (type.match(/^[^ ()*]+$/)) {
return CompletionItemKind.Keyword
}
else {
return CompletionItemKind.Variable
}
}