Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Get Type if type is given as attribute, which indicates it may be used by others.
if (e.$ && e.$.type) {
derivedelements = derivedelements.concat(this.getDerivedElements(e, element.schema));
// Get Elements if type is a reference
} else if (e.$ && e.$.ref) {
e = this.getElementFromReference(e.$.ref, element.schema);
if (e && e.$ && e.$.type)
derivedelements = derivedelements.concat(this.getDerivedElements(e, element.schema));
} else {
ownelements.push(e);
}
// 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;
documentation: MarkedString.fromPlainText(value.documentation).toString(),
detail: 'Bindable Attribute',
insertText: value.customBindingSnippet === null ? `${key}.bind=${quote}$0${quote}`: value.customBindingSnippet.replace('"', quote),
insertTextFormat: InsertTextFormat.Snippet,
kind: CompletionItemKind.Value,
label: value.customLabel === null ? (key + '.bind') : value.customLabel,
});
}
if (value instanceof EmptyAttribute) {
result.push({
detail: 'Empty Custom Attribute',
documentation: MarkedString.fromPlainText(value.documentation).toString(),
insertText: `${key}`,
insertTextFormat: InsertTextFormat.PlainText,
kind: CompletionItemKind.Property,
label: key,
});
}
if (value instanceof SimpleAttribute || value instanceof BindableAttribute) {
result.push({
documentation: MarkedString.fromPlainText(value.documentation).toString(),
detail: 'Attribute',
insertText: `${key}=${quote}$0${quote}`,
insertTextFormat: InsertTextFormat.Snippet,
kind: CompletionItemKind.Property,
label: key,
});
}
}
return result;
public getDocumentByCompletionItem(
params: { label: string, kind: CompletionItemKind } | CompletionItem,
): CompletionItem | undefined {
const { kind } = params;
switch (kind) {
case CompletionItemKind.Variable:
if (!this.vimPredefinedVariableDocuments[params.label]) {
return;
}
return {
...params,
documentation: this.formatVimDocument(
this.vimPredefinedVariableDocuments[params.label],
),
};
case CompletionItemKind.Property:
if (!this.vimOptionDocuments[params.label]) {
return;
}
return {
...params,
documentation: this.formatVimDocument(
this.vimOptionDocuments[params.label],
),
};
case CompletionItemKind.Function:
if (!this.vimBuiltFunctionDocuments[params.label]) {
return;
}
return {
...params,
documentation: this.formatVimDocument(
function getTxCompletionItems(): CompletionItem[] {
return [
{
detail: '(uint): gas price of the transaction',
kind: CompletionItemKind.Property,
label: 'gas',
},
{
detail: '(address): sender of the transaction (full call chain)',
kind: CompletionItemKind.Property,
label: 'origin',
},
];
}
/**
* Maps string-based CompletionEntry::kind to enum-based CompletionItemKind
*/
const completionKinds: { [name: string]: CompletionItemKind } = {
class: CompletionItemKind.Class,
constructor: CompletionItemKind.Constructor,
enum: CompletionItemKind.Enum,
field: CompletionItemKind.Field,
file: CompletionItemKind.File,
function: CompletionItemKind.Function,
interface: CompletionItemKind.Interface,
keyword: CompletionItemKind.Keyword,
method: CompletionItemKind.Method,
module: CompletionItemKind.Module,
property: CompletionItemKind.Property,
reference: CompletionItemKind.Reference,
snippet: CompletionItemKind.Snippet,
text: CompletionItemKind.Text,
unit: CompletionItemKind.Unit,
value: CompletionItemKind.Value,
variable: CompletionItemKind.Variable
};
private getCompletionItemForSingleAttribute(attribute: Attribute, schema: StorageSchema): CompletionItem {
const ce: CompletionItem = {
label: attribute.$.name,
kind: CompletionItemKind.Property,
insertText: " " + attribute.$.name + "=\"$0\" ",
insertTextFormat: 2
}
try {
ce.detail = attribute.owner ? "from " + attribute.owner.$.name : undefined;
} catch (error) {
}
try {
ce.documentation = this.markdownText(attribute.annotation[0].documentation[0]);
} catch (error) {
}
return ce;
}
return CompletionItemKind.Enum;
case "module":
return CompletionItemKind.Module;
case "class":
return CompletionItemKind.Class;
case "interface":
return CompletionItemKind.Interface;
case "warning":
return CompletionItemKind.File;
case "script":
return CompletionItemKind.File;
case "directory":
return CompletionItemKind.Folder;
}
return CompletionItemKind.Property;
}
function getCompletionItemKind(symbol: Symbol) {
switch (symbol.kind) {
case PapyrusSymbolKind.Function:
return CompletionItemKind.Method;
case PapyrusSymbolKind.Property:
return CompletionItemKind.Property;
case PapyrusSymbolKind.Script:
return CompletionItemKind.Class;
case PapyrusSymbolKind.Struct:
return CompletionItemKind.Struct;
case PapyrusSymbolKind.Event:
return CompletionItemKind.Event;
case PapyrusSymbolKind.Variable:
if (symbol.parent.kind === PapyrusSymbolKind.Script || symbol.parent.kind === PapyrusSymbolKind.Struct) {
return CompletionItemKind.Field;
}
return CompletionItemKind.Variable;
default:
return null;
}
}
.forEach(blockClass => {
const classCompletion: CompletionItem = {
label: blockClass.name,
kind: CompletionItemKind.Property,
};
const classAttributeCompletions = blockClass
.getAttributes()
.map(
(attr): CompletionItem => ({
label: `${attr.namespace}:${attr.name}`,
kind: CompletionItemKind.Property,
}),
);
completions = completions.concat(
classCompletion,
classAttributeCompletions,
);
});
kind: CompletionItemKind.Property,
label: 'gas',
},
{
detail: '(address): sender of the message (current call)',
kind: CompletionItemKind.Property,
label: 'sender',
},
{
detail: '(bytes4): first four bytes of the calldata (i.e. function identifier)',
kind: CompletionItemKind.Property,
label: 'sig',
},
{
detail: '(uint): number of wei sent with the message',
kind: CompletionItemKind.Property,
label: 'value',
},
];
}