Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
// Append additional elements
for (const ns in this.usedNamespaces) {
if (this.usedNamespaces[ns] === element.schema.targetNamespace) {
foundElements.push({ namespace: ns, elements: ownelements, ciKind: CompletionItemKind.Property });
break;
}
}
foundElements = foundElements.concat(derivedelements);
let ret: CompletionItem[] = [];
for (let item of foundElements) {
for (const entry of item.elements)
try {
const citem = CompletionItem.create(entry.$.name);
const nsprefix = item.namespace.length > 0 ? item.namespace + ":" : "";
citem.insertText = "<" + nsprefix + entry.$.name + ">$0";
citem.insertTextFormat = 2;
citem.kind = item.ciKind || CompletionItemKind.Class;
if (item.namespace.length > 0)
citem.detail = "Namespace: " + item.namespace;
try {
citem.documentation = this.markdownText(entry.annotation[0].documentation[0]);
} catch (error) {
}
ret.push(citem);
} catch (error) {
this.connection.console.error("Item error: " + error.toString());
}
}
private _addNameToCompletionList(name: string, itemKind: CompletionItemKind,
filter: string, completionList: CompletionList, typeDetail?: string,
documentation?: string, autoImportText?: string, textEdit?: TextEdit,
additionalTextEdits?: TextEditAction[], symbolId?: number) {
const similarity = StringUtils.computeCompletionSimilarity(filter, name);
if (similarity > similarityLimit) {
const completionItem = CompletionItem.create(name);
completionItem.kind = itemKind;
const completionItemData: CompletionItemData = {
workspacePath: this._workspacePath,
filePath: this._filePath,
position: this._position
};
completionItem.data = completionItemData;
if (autoImportText) {
// Force auto-import entries to the end.
completionItem.sortText =
this._makeSortText(SortCategory.AutoImport, name, autoImportText);
completionItemData.autoImportText = autoImportText;
} else if (SymbolNameUtils.isDunderName(name)) {
// Force dunder-named symbols to appear after all other symbols.
nameParts: node.nameParts.map(part => part.value),
importedSymbols: []
};
const completions = this._importResolver.getCompletionSuggestions(this._filePath,
execEnvironment, moduleDescriptor, similarityLimit);
const completionList = CompletionList.create();
// If we're in the middle of a "from X import Y" statement, offer
// the "import" keyword as a completion.
if (!node.hasTrailingDot && node.parent && node.parent.nodeType === ParseNodeType.ImportFrom &&
node.parent.missingImportKeyword) {
const keyword = 'import';
const completionItem = CompletionItem.create(keyword);
completionItem.kind = CompletionItemKind.Keyword;
completionList.items.push(completionItem);
completionItem.sortText =
this._makeSortText(SortCategory.Keyword, keyword);
}
completions.forEach(completionName => {
const completionItem = CompletionItem.create(completionName);
completionItem.kind = CompletionItemKind.Module;
completionList.items.push(completionItem);
completionItem.sortText =
this._makeSortText(SortCategory.ImportModuleName, completionName);
});
return completionList;
}
types.forEach(type => {
const completionItem = CompletionItem.create(type);
completionItem.kind = CompletionItemKind.Keyword;
completionItem.detail = type + ' type';
completionItems.push(completionItem);
});
// add mapping
private _addStringLiteralToCompletionList(value: string, priorString: string | undefined,
postText: string | undefined, quoteCharacter: string, completionList: CompletionList) {
const isSimilar = StringUtils.computeCompletionSimilarity(priorString || '', value) > similarityLimit;
if (isSimilar) {
const valueWithQuotes = `${ quoteCharacter }${ value }${ quoteCharacter }`;
const completionItem = CompletionItem.create(valueWithQuotes);
completionItem.kind = CompletionItemKind.Text;
completionItem.sortText = this._makeSortText(SortCategory.LiteralValue, valueWithQuotes);
let rangeStartCol = this._position.column;
if (priorString !== undefined) {
rangeStartCol -= priorString.length + 1;
}
// If the text after the insertion point is the closing quote,
// replace it.
let rangeEndCol = this._position.column;
if (postText !== undefined) {
if (postText.startsWith(quoteCharacter)) {
rangeEndCol++;
}
}
private _createSingleKeywordCompletionList(keyword: string): CompletionList {
const completionItem = CompletionItem.create(keyword);
completionItem.kind = CompletionItemKind.Keyword;
completionItem.sortText =
this._makeSortText(SortCategory.LikelyKeyword, keyword);
return CompletionList.create([completionItem]);
}
areas.forEach(a => {
let item = CompletionItem.create(a);
items.push(item);
});
return items;
results['suggestions'].forEach((sugg) => {
var item = CompletionItem.create(sugg.label);
item.kind = CompletionItemKind[sugg.kind];
item.textEdit = {
range: {
start: begin,
end: textDocumentPosition.position
},
newText: sugg.insert
}
if (sugg.documentation) {
item.documentation = formatDocumentation(sugg.documentation);
} else if (sugg.has_doc) {
item.documentation = 'Loading...';
} else {
item.documentation = "\n" + sugg.path;
}
if (sugg['kind'] == 'Method' && sugg['arguments'].length > 0) {
function CreateCompletionItem(label: string, kind: CompletionItemKind, detail: string) {
const completionItem = CompletionItem.create(label);
completionItem.kind = kind;
completionItem.detail = detail;
return completionItem;
}
return suggestions.map(label => {
const completionItem = CompletionItem.create(label)
completionItem.kind = CompletionItemKind.Module
return completionItem
})
}