mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
[php] prefilter completion proposals based on prefix
This commit is contained in:
parent
bdae5cdc6d
commit
4732e95b1d
|
@ -14,6 +14,8 @@ export default class PHPCompletionItemProvider implements CompletionItemProvider
|
|||
|
||||
public provideCompletionItems(document: TextDocument, position: Position, token: CancellationToken): Promise<CompletionItem[]> {
|
||||
let result: CompletionItem[] = [];
|
||||
var range = document.getWordRangeAtPosition(position);
|
||||
var prefix = range ? document.getText(range) : '';
|
||||
|
||||
var added : any = {};
|
||||
var createNewProposal = function(kind: CompletionItemKind, name: string, entry: phpGlobals.IEntry) : CompletionItem {
|
||||
|
@ -30,39 +32,45 @@ export default class PHPCompletionItemProvider implements CompletionItemProvider
|
|||
return proposal;
|
||||
};
|
||||
|
||||
var matches = (name:string) => {
|
||||
return prefix.length === 0 || name.length > prefix.length && name.substr(0, prefix.length) === prefix;
|
||||
}
|
||||
|
||||
for (var name in phpGlobals.globalvariables) {
|
||||
if (phpGlobals.globalvariables.hasOwnProperty(name)) {
|
||||
if (phpGlobals.globalvariables.hasOwnProperty(name) && matches(name)) {
|
||||
added[name] = true;
|
||||
result.push(createNewProposal(CompletionItemKind.Variable, name, phpGlobals.globalvariables[name]));
|
||||
}
|
||||
}
|
||||
for (var name in phpGlobals.globalfunctions) {
|
||||
if (phpGlobals.globalfunctions.hasOwnProperty(name)) {
|
||||
if (phpGlobals.globalfunctions.hasOwnProperty(name) && matches(name)) {
|
||||
added[name] = true;
|
||||
result.push(createNewProposal(CompletionItemKind.Function, name, phpGlobals.globalfunctions[name]));
|
||||
}
|
||||
}
|
||||
for (var name in phpGlobals.compiletimeconstants) {
|
||||
if (phpGlobals.compiletimeconstants.hasOwnProperty(name)) {
|
||||
if (phpGlobals.compiletimeconstants.hasOwnProperty(name) && matches(name)) {
|
||||
added[name] = true;
|
||||
result.push(createNewProposal(CompletionItemKind.Field, name, phpGlobals.compiletimeconstants[name]));
|
||||
}
|
||||
}
|
||||
for (var name in phpGlobals.keywords) {
|
||||
if (phpGlobals.keywords.hasOwnProperty(name)) {
|
||||
if (phpGlobals.keywords.hasOwnProperty(name) && matches(name)) {
|
||||
added[name] = true;
|
||||
result.push(createNewProposal(CompletionItemKind.Keyword, name, phpGlobals.keywords[name]));
|
||||
}
|
||||
}
|
||||
|
||||
var text = document.getText();
|
||||
var variableMatch = /\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)/g;
|
||||
var match : RegExpExecArray = null;
|
||||
while (match = variableMatch.exec(text)) {
|
||||
var word = match[0];
|
||||
if (!added[word]) {
|
||||
added[word] = true;
|
||||
result.push(createNewProposal(CompletionItemKind.Variable, word, null));
|
||||
if (matches('$')) {
|
||||
var variableMatch = /\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)/g;
|
||||
var match : RegExpExecArray = null;
|
||||
while (match = variableMatch.exec(text)) {
|
||||
var word = match[0];
|
||||
if (!added[word]) {
|
||||
added[word] = true;
|
||||
result.push(createNewProposal(CompletionItemKind.Variable, word, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
var functionMatch = /function\s+([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\s*\(/g;
|
||||
|
|
Loading…
Reference in a new issue