vscode#CompletionList TypeScript Examples
The following examples show how to use
vscode#CompletionList.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: element-completion-item-povider.ts From element-ui-helper with MIT License | 6 votes |
/**
* 提供自动完成提示
*
* @param document 文档
* @param position 位置
* @param token token
* @param context 上下文
*/
provideCompletionItems(document: TextDocument, position: Position, token: CancellationToken, context: CompletionContext): ProviderResult<CompletionItem[] | CompletionList<CompletionItem>> {
this._document = document
this._position = position
this.token = token
let tag: TagObject | undefined = this.getPreTag()
let attr = this.getPreAttr()
if (!tag || !/^[E|e]l/.test(tag.text || '')) {
// 如果不是element的标签(E|el开头) 则返回 null 表示没有hover
return null
} else if (this.isAttrValueStart(tag, attr)) {
// 如果是属性值的开始
return this.getAttrValueCompletionItems(tag.text, attr)
} else if (this.isEventStart(tag)) {
// 优先判定事件
return this.getEventCompletionItems(tag.text)
} else if (this.isAttrStart(tag)) {
// 判断属性
return this.getAttrCompletionItems(tag.text)
} else if (this.isTagStart()) {
// 判断标签
return this.getTagCompletionItems(tag.text)
}
return null
}
Example #2
Source File: sourceAutocompletionProvider.ts From vscode-dbt-power-user with MIT License | 6 votes |
provideCompletionItems(
document: TextDocument,
position: Position,
token: CancellationToken,
context: CompletionContext
): ProviderResult<CompletionItem[] | CompletionList<CompletionItem>> {
const linePrefix = document
.lineAt(position)
.text.substr(0, position.character);
if (!isEnclosedWithinCodeBlock(document, position)) {
return undefined;
}
const projectRootpath = this.dbtProjectContainer.getProjectRootpath(
document.uri
);
if (projectRootpath === undefined) {
return;
}
if (linePrefix.match(SourceAutocompletionProvider.ENDS_WITH_SOURCE)) {
return this.showSourceNameAutocompletionItems(projectRootpath);
}
if (
linePrefix.match(SourceAutocompletionProvider.GET_SOURCE_NAME) &&
linePrefix.includes("source")
) {
return this.showTableNameAutocompletionItems(linePrefix, projectRootpath);
}
return undefined;
}
Example #3
Source File: modelAutocompletionProvider.ts From vscode-dbt-power-user with MIT License | 6 votes |
provideCompletionItems(
document: TextDocument,
position: Position,
token: CancellationToken,
context: CompletionContext
): ProviderResult<CompletionItem[] | CompletionList<CompletionItem>> {
const linePrefix = document
.lineAt(position)
.text.substr(0, position.character);
if (
linePrefix.match(ModelAutocompletionProvider.ENDS_WITH_REF) &&
isEnclosedWithinCodeBlock(document, position)
) {
return this.getAutoCompleteItems(document.uri);
}
return undefined;
}
Example #4
Source File: macroAutocompletionProvider.ts From vscode-dbt-power-user with MIT License | 6 votes |
provideCompletionItems(
document: TextDocument,
position: Position,
token: CancellationToken,
context: CompletionContext
): ProviderResult<CompletionItem[] | CompletionList<CompletionItem>> {
const range = document.getWordRangeAtPosition(position);
if (range && isEnclosedWithinCodeBlock(document, range)) {
return this.getAutoCompleteItems(document.uri);
}
return undefined;
}
Example #5
Source File: spCompletionsGetters.ts From sourcepawn-vscode with MIT License | 6 votes |
function getMethodItems(
allItems: SPItem[],
variableTypes: (MethodMapItem | EnumStructItem)[],
isMethodMap: boolean,
lastFunc: MethodItem | FunctionItem
): CompletionList {
let items = new Set<CompletionItem | undefined>();
try {
for (let item of allItems) {
if (
MP.includes(item.kind) &&
variableTypes.includes(item.parent as EnumStructItem | MethodMapItem) &&
// Don't include the constructor of the methodmap
!variableTypes.includes(item as EnumStructItem | MethodMapItem) &&
// Don't include static methods if we are not calling a method from its type.
// This handles suggestions for 'Database.Connect()' for example.
isMethodMap === /\bstatic\b[^\(]*\(/.test(item.detail as string)
) {
items.add(item.toCompletionItem(lastFunc));
}
}
} catch (e) {
console.debug(e);
}
items.delete(undefined);
return new CompletionList(
Array.from(items).filter((e) => e !== undefined) as CompletionItem[]
);
}
Example #6
Source File: spCompletionsGetters.ts From sourcepawn-vscode with MIT License | 6 votes |
function getNonMethodItems(
allItems: SPItem[],
lastFunc: FunctionItem | MethodItem
): CompletionList {
let items = new Set<CompletionItem | undefined>();
for (let item of allItems) {
if (!MP.includes(item.kind)) {
items.add(item.toCompletionItem(lastFunc) as CompletionItem);
}
}
items.delete(undefined);
return new CompletionList(
Array.from(items).filter((e) => e !== undefined) as CompletionItem[]
);
}
Example #7
Source File: lexMode.ts From yash with MIT License | 6 votes |
export function getLEXMode(lexLanguageService: LEXLanguageService): LanguageMode {
const cache = CreateDocumentCache<LexDocument>(10, 60, document => lexLanguageService.parseLexDocument(document));
return {
getId() {
return 'lex';
},
doValidation(document: TextDocument): Diagnostic[] {
const lex = cache.get(document);
return lexLanguageService.doValidation(document, lex);
},
doComplete(document: TextDocument, position: Position): CompletionList | CompletionItem[] {
const lex = cache.get(document);
return lexLanguageService.doComplete(document, position, lex);
},
doHover(document: TextDocument, position: Position): Hover | null {
const lex = cache.get(document);
return lexLanguageService.doHover(document, position, lex);
},
findDefinition(document: TextDocument, position: Position): Definition | null {
const lex = cache.get(document);
return lexLanguageService.findDefinition(document, position, lex);
},
findReferences(document: TextDocument, position: Position): Location[] {
const lex = cache.get(document);
return lexLanguageService.findReferences(document, position, lex);
},
doRename(document: TextDocument, position: Position, newName: string): WorkspaceEdit | null {
const lex = cache.get(document);
return lexLanguageService.doRename(document, position, newName, lex);
},
onDocumentRemoved(document: TextDocument) {
cache.onDocumentRemoved(document);
},
dispose() {
cache.dispose();
}
};
}
Example #8
Source File: microProfileCompletionItemProvider.ts From vscode-microprofile with Apache License 2.0 | 5 votes |
provideCompletionItems(
document: TextDocument,
position: Position,
_token: CancellationToken,
_context: CompletionContext): ProviderResult<CompletionItem[] | CompletionList<CompletionItem>> {
return commands.executeCommand("java.execute.workspaceCommand", JAVA_COMPLETION_REQUEST, adaptToMicroProfileCompletionParams(document, position));
}
Example #9
Source File: ALDocCommentProvider.ts From vscode-alxmldocumentation with MIT License | 5 votes |
/**
* Provide XML Documentation Completion Items (IntelliSense) based on triggering position.
* @param document Actual Document.
* @param position Trigger Position.
* @param token CancellationToken.
* @param context CompletionContext.
*/
async provideCompletionItems(document: TextDocument, position: Position, token: CancellationToken, context: CompletionContext): Promise<CompletionItem[] | CompletionList<CompletionItem> | null | undefined> {
this.alXmlDocCompletionItems = [];
if (!Configuration.IntelliSenseDocumentationIsEnabled(document.uri)) {
return;
}
if (context.triggerCharacter === undefined) {
return;
}
let activeLine = ALSyntaxUtil.SplitALCodeToLines(document.getText())[position.line];
if (activeLine.match(/^[ \t]*\/{3}[ \t]*$/) === null) {
return;
}
let alObject: ALObject | null = await ALSyntaxUtil.GetALObject(document);
if (alObject === null) {
return;
}
if (alObject.LineNo > position.line) {
this.ProvideALObjectCompletionItems(alObject);
} else {
// find procedure
let alProcedure: ALProcedure | undefined = alObject.Procedures?.find(alProcedure => (alProcedure.LineNo > position.line));
if (!alProcedure) {
return;
}
await this.ProvideALProcedureCompletionItems(alObject, alProcedure);
}
return this.alXmlDocCompletionItems;
}
Example #10
Source File: yaccMode.ts From yash with MIT License | 5 votes |
export function getYACCMode(yaccLanguageService: YACCLanguageService): LanguageMode {
const cache = CreateDocumentCache<YACCDocument>(10, 60, document => yaccLanguageService.parseYACCDocument(document));
return {
getId() {
return 'yacc';
},
doValidation(document: TextDocument, force?:boolean): Diagnostic[] {
if (force) {
return yaccLanguageService.doValidation(document, yaccLanguageService.parseYACCDocument(document));
}
const yacc = cache.get(document);
return yaccLanguageService.doValidation(document, yacc);
},
doComplete(document: TextDocument, position: Position): CompletionList | CompletionItem[] {
const yacc = cache.get(document);
return yaccLanguageService.doComplete(document, position, yacc);
},
doHover(document: TextDocument, position: Position): Hover | null {
const yacc = cache.get(document);
return yaccLanguageService.doHover(document, position, yacc);
},
findTypeDefinition(document: TextDocument, position: Position): Definition | null {
const yacc = cache.get(document);
return yaccLanguageService.findTypeDefinition(document, position, yacc);
},
findDefinition(document: TextDocument, position: Position): Definition | null {
const yacc = cache.get(document);
return yaccLanguageService.findDefinition(document, position, yacc);
},
findReferences(document: TextDocument, position: Position): Location[] {
const yacc = cache.get(document);
return yaccLanguageService.findReferences(document, position, yacc);
},
doRename(document: TextDocument, position: Position, newName: string): WorkspaceEdit | null {
const yacc = cache.get(document);
return yaccLanguageService.doRename(document, position, newName, yacc);
},
getSemanticTokens(document: TextDocument): SemanticTokenData[] {
const yacc = cache.get(document);
return yaccLanguageService.getSemanticTokens(document, yacc);
},
getSemanticTokenLegend() {
return { types: tokenTypes, modifiers: tokenModifiers };
},
onDocumentRemoved(document: TextDocument) {
cache.onDocumentRemoved(document);
},
dispose() {
cache.dispose();
}
};
}
Example #11
Source File: yaccCompletions.ts From yash with MIT License | 5 votes |
export function doYACCComplete(document: TextDocument, position: Position, yaccDocument: YACCDocument): CompletionItem[] | CompletionList {
const offset = document.offsetAt(position);
const text = document.getText();
const embedded = yaccDocument.getEmbeddedNode(offset);
if (embedded !== undefined) {
return [];
}
const scanner = createScanner(text, offset - 1);
if (scanner.scan() === TokenType.Percent) {
if (position.character === 1 && offset < yaccDocument.rulesRange[0])
return keywords.map((keyword) => {
const completion = new CompletionItem(keyword);
completion.detail = "keyword";
completion.kind = CompletionItemKind.Constructor;
return completion;
});
return [];
}
const word = document.getText(document.getWordRangeAtPosition(position)).toUpperCase();
// this is used to match the completion items before we feed them out
// if we return an empty list, VSCode will fall back to the default 'abc' completions, which is what we want
const node = yaccDocument.getNodeByOffset(offset);
if (node === undefined) {
return [];
}
var completion: CompletionItem;
const result: CompletionItem[] = [];
switch (node.nodeType) {
case NodeType.Token:
case NodeType.Type:
if (node.typeOffset && offset > node.typeOffset) {
if (!node.typeEnd || offset <= node.typeEnd) {
Object.keys(yaccDocument.types).filter(t=>t.toUpperCase().startsWith(word)).forEach((type) => {
completion = new CompletionItem(type)
completion.detail = "type"
completion.kind = CompletionItemKind.TypeParameter;
result.push(completion);
})
break;
}
}
if (node.nodeType === NodeType.Type)
Object.keys(yaccDocument.symbols).filter(t=>t.toUpperCase().startsWith(word)).forEach((symbol) => {
completion = new CompletionItem(symbol)
completion.detail = "user defined non-terminal";
completion.kind = CompletionItemKind.Class;
result.push(completion);
});
break;
case NodeType.Rule:
Object.keys(yaccDocument.symbols).filter(t=>t.toUpperCase().startsWith(word)).forEach((symbol) => {
completion = new CompletionItem(symbol)
completion.detail = "user defined non-terminal";
completion.kind = CompletionItemKind.Class;
result.push(completion);
});
Object.keys(yaccDocument.tokens).filter(t=>t.toUpperCase().startsWith(word)).forEach((token) => {
completion = new CompletionItem(token)
completion.detail = "user defined token";
completion.kind = CompletionItemKind.Field;
result.push(completion);
});
Object.keys(predefined).filter(t=>t.toUpperCase().startsWith(word)).forEach(key => {
completion = new CompletionItem(key)
completion.detail = "predefined symbol";
completion.kind = CompletionItemKind.Method;
result.push(completion);
});
break;
default:
break;
}
return result;
}
Example #12
Source File: lexCompletions.ts From yash with MIT License | 5 votes |
export function doLEXCompletion(document: TextDocument, position: Position, lexDocument: LexDocument): CompletionItem[] | CompletionList {
const offset = document.offsetAt(position);
const text = document.getText();
const embedded = lexDocument.getEmbeddedCode(offset);
if (embedded !== undefined) {
return [];
}
const scanner = createScanner(text, offset - 1);
if (scanner.scan() === TokenType.Percent) {
if (position.character === 1 && offset < lexDocument.rulesRange[0])
return keywords.map((keyword) => {
const completion = new CompletionItem(keyword);
completion.detail = "keyword";
completion.kind = CompletionItemKind.Constructor;
return completion;
});
return [];
}
const word = document.getText(document.getWordRangeAtPosition(position)).toUpperCase();
const line = document.lineAt(position.line).text.substring(0, position.character);
const result: CompletionItem[] = [];
if (offset < lexDocument.rulesRange[0]) {
// if before rules zone, definition need to be on the right
const ok = line.match(/^\w+.*({\w*}?)+/);
if (ok) {
Object.keys(lexDocument.defines).filter(t=>t.toUpperCase().startsWith(word)).forEach((key) => {
const completion = new CompletionItem(key);
completion.detail = "definition";
completion.kind = CompletionItemKind.Class;
result.push(completion);
})
}
} else if (offset < lexDocument.rulesRange[1]) {
const res = line.match(/^[^\s]*(?:{\w*}?)+$/);
if (res) {
if (res[0].length >= position.character) {
Object.keys(lexDocument.defines).filter(t=>t.toUpperCase().startsWith(word)).forEach((key) => {
const completion = new CompletionItem(key);
completion.detail = "definition";
completion.kind = CompletionItemKind.Class;
result.push(completion);
})
}
} else {
if (line.match(/^<[\w,]*>[^\s]*(?:{\w*}?)+$/)) {
Object.keys(lexDocument.defines).filter(t=>t.toUpperCase().startsWith(word)).forEach((key) => {
const completion = new CompletionItem(key);
completion.detail = "definition";
completion.kind = CompletionItemKind.Class;
result.push(completion);
})
} else if (line.match(/^<[\w,]*$/)) { // TODO: fix completion for {} after <>
Object.keys(lexDocument.states).filter(t=>t.toUpperCase().startsWith(word)).forEach((key) => {
const completion = new CompletionItem(key);
completion.detail = "initial state";
completion.kind = CompletionItemKind.Class;
result.push(completion);
})
}
}
}
return result;
}
Example #13
Source File: spCompletionsGetters.ts From sourcepawn-vscode with MIT License | 5 votes |
/**
* Returns a CompletionList object of all the objects available at that position's scope.
* @param {ItemsRepository} itemsRepo The itemsRepository object constructed in the activation event.
* @param {TextDocument} document The document the completions are requested for.
* @param {Position} position The position at which the completions are requested.
* @returns CompletionList
*/
export function getCompletionListFromPosition(
itemsRepo: ItemsRepository,
document: TextDocument,
position: Position
): CompletionList {
const allItems: SPItem[] = itemsRepo.getAllItems(document.uri);
if (allItems === []) {
return new CompletionList();
}
const line = document.lineAt(position.line).text;
const isMethod = isMethodCall(line, position);
const lastFunc = getLastFunc(position, document, allItems);
if (!isMethod) {
return getNonMethodItems(allItems, lastFunc);
}
const lastEnumStructOrMethodMap = getLastEnumStructNameOrMethodMap(
position,
document.uri.fsPath,
allItems
);
let { variableType, words } = getTypeOfVariable(
line,
position,
allItems,
lastFunc,
lastEnumStructOrMethodMap
);
let variableTypeItem = allItems.find(
(e) =>
[CompletionItemKind.Class, CompletionItemKind.Struct].includes(e.kind) &&
e.name === variableType
) as MethodMapItem | EnumStructItem;
let variableTypes: (MethodMapItem | EnumStructItem)[];
if (variableTypeItem.kind === CompletionItemKind.Class) {
variableTypes = getAllInheritances(
variableTypeItem as MethodMapItem,
allItems
);
} else {
variableTypes = [variableTypeItem as EnumStructItem];
}
const isMethodMap =
words.length === 1 &&
undefined !==
allItems.find(
(e) => e.name === words[0] && e.kind === CompletionItemKind.Class
);
return getMethodItems(allItems, variableTypes, isMethodMap, lastFunc);
}
Example #14
Source File: spCompletionsGetters.ts From sourcepawn-vscode with MIT License | 5 votes |
/**
* Generate a CompletionList object of the possible includes file that can fit the already typed #include statement.
* @param {Set<string>} knownIncs Set of parsed include files (.sp and .inc).
* @param {TextDocument} document The document being edited.
* @param {string} tempName The string that has already been typed in the #include statement.
* @returns CompletionList
*/
export function getIncludeFileCompletionList(
knownIncs: Set<string>,
document: TextDocument,
tempName: string,
useAp: boolean
): CompletionList {
const incURIs = getAllPossibleIncludeFolderPaths(document.uri).map((e) =>
URI.file(e)
);
const prevPath = tempName.replace(/((?:[^\'\<\/]+\/)+)+/, "$1");
let items: CompletionItem[] = [];
Array.from(knownIncs).forEach((e) =>
incURIs.find((incURI) => {
const fileMatchRe = RegExp(
`${incURI.toString()}\\/${prevPath}[^<>:;,?"*|/]+\\.(?:inc|sp)$`
);
if (fileMatchRe.test(e)) {
const path = URI.parse(e).fsPath;
items.push({
label: basename(path, ".inc"),
insertText: `${basename(path, ".inc")}${useAp ? '"' : ">"}`,
kind: CompletionItemKind.File,
detail: path,
});
return true;
}
return false;
})
);
const availableIncFolderPaths = new Set<string>();
knownIncs.forEach((e) => {
incURIs.forEach((incURI) => {
const folderMatchRe = RegExp(
`${incURI.toString()}\\/${prevPath}(\\w[^*/><?\\|:]+)\\/`
);
const match = e.match(folderMatchRe);
if (match) {
availableIncFolderPaths.add(`${incURI.toString()}/${match[1]}`);
}
});
});
availableIncFolderPaths.forEach((e) => {
const path = URI.parse(e).fsPath;
items.push({
label: basename(path),
kind: CompletionItemKind.Folder,
detail: path,
});
});
return new CompletionList(items);
}
Example #15
Source File: spProviders.ts From sourcepawn-vscode with MIT License | 5 votes |
public async provideCompletionItems(
document: TextDocument,
position: Position,
token: CancellationToken
): Promise<CompletionList> {
return completionProvider(this.itemsRepository, document, position, token);
}
Example #16
Source File: spItemsRepository.ts From sourcepawn-vscode with MIT License | 5 votes |
public getEventCompletions(): CompletionList {
return new CompletionList(events);
}
Example #17
Source File: spCompletionProvider.ts From sourcepawn-vscode with MIT License | 4 votes |
export function completionProvider(
itemsRepo: ItemsRepository,
document: TextDocument,
position: Position,
token: CancellationToken
): CompletionList {
const text = document
.lineAt(position.line)
.text.substring(0, position.character);
// If the trigger char is a space, check if there is a
// "new" behind, and deal with the associated constructor.
if (text[text.length - 1] === " ") {
if (position.character > 0) {
const line = document
.lineAt(position.line)
.text.substring(0, position.character);
let match = line.match(
/(\w*)\s+([\w.\(\)]+)(?:\[[\w+ \d]+\])*\s*\=\s*new\s+(\w*)$/
);
if (match) {
let type: string | undefined;
if (!match[1]) {
// If the variable is not declared here, look up its type, as it
// has not yet been parsed.
let allItems = itemsRepo.getAllItems(document.uri);
const lastFunc = getLastFunc(position, document, allItems);
let newPos = new Position(1, match[2].length + 1);
const lastEnumStructOrMethodMap = getLastEnumStructNameOrMethodMap(
position,
document.uri.fsPath,
allItems
);
let { variableType, words } = getTypeOfVariable(
// Hack to use getTypeOfVariable
match[2] + ".",
newPos,
allItems,
lastFunc,
lastEnumStructOrMethodMap
);
type = variableType;
} else {
// If the variable is declared here, search its type directly.
type = itemsRepo
.getAllItems(document.uri)
.find(
(item) =>
item.kind === CompletionItemKind.Class && item.name === match[1]
).name;
}
// Filter the item to only keep the constructors.
let items = itemsRepo
.getAllItems(document.uri)
.filter((item) => item.kind === CompletionItemKind.Constructor);
return new CompletionList(
items.map((e) => {
// Show the associated type's constructor first.
if (e.name === type) {
let tmp = e.toCompletionItem();
tmp.preselect = true;
return tmp;
}
return e.toCompletionItem();
})
);
}
}
return new CompletionList();
}
// Check if we are dealing with an include.
let match = text.match(/^\s*#\s*include\s*(?:\<([^>]*)\>?)/);
let useAp = false;
if (!match) {
match = text.match(/^\s*#\s*include\s*(?:\"([^\"]*)\"?)/);
useAp = true;
}
if (match) {
return getIncludeFileCompletionList(
itemsRepo.documents,
document,
match[1],
useAp
);
}
match = text.match(
/^\s*(?:HookEvent|HookEventEx)\s*\(\s*(\"[^\"]*|\'[^\']*)$/
);
if (match) {
return itemsRepo.getEventCompletions();
}
if (['"', "'", "<", "/", "\\"].includes(text[text.length - 1]))
return undefined;
if (/[^:]\:$/.test(text)) {
return undefined;
}
return getCompletionListFromPosition(itemsRepo, document, position);
}