[php] missing user code auto-complete on 0.10.1 #161

This commit is contained in:
Martin Aeschlimann 2015-12-03 17:38:01 +01:00
parent 3399962d42
commit 2b7dccce56
2 changed files with 27 additions and 12 deletions

View file

@ -61,7 +61,17 @@ export default class PHPCompletionItemProvider implements CompletionItemProvider
while (match = variableMatch.exec(text)) {
var word = match[0];
if (!added[word]) {
result.push(createNewProposal(CompletionItemKind.Variable, name, null));
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;
var match : RegExpExecArray = null;
while (match = functionMatch.exec(text)) {
var word = match[1];
if (!added[word]) {
added[word] = true;
result.push(createNewProposal(CompletionItemKind.Function, word, null));
}
}
return Promise.resolve(result);

View file

@ -1,5 +1,5 @@
import assert = require('assert');
import {CompletionItemProvider, CompletionItem, CompletionItemKind, CancellationToken, TextDocument, Range, Position, Uri} from 'vscode';
import {CompletionItemProvider, CompletionItem, CompletionItemKind, CancellationToken, TextDocument, Range, Position, Uri, workspace, window} from 'vscode';
import PHPCompletionItemProvider from '../features/completionItemProvider';
import HoverProvider from '../features/hoverProvider';
import SignatureHelpProvider from '../features/signatureHelpProvider';
@ -7,14 +7,19 @@ import SignatureHelpProvider from '../features/signatureHelpProvider';
var phpCompletionProvider = new PHPCompletionItemProvider();
var testSuggestionsFor = function(value:string, stringBefore:string):Promise<CompletionItem[]> {
var uri = new Uri();
var doc = new TextDocument(uri, value.split('\n'), '\n', 'php', 1, false);
var idx = stringBefore ? value.indexOf(stringBefore) + stringBefore.length : 0;
var position = new Position(0, idx);
return phpCompletionProvider.provideCompletionItems(doc, position, null);
var testSuggestionsFor = function(value:string, stringBefore:string):Thenable<CompletionItem[]> {
return workspace.openTextDocument(Uri.parse("untitled:/foo/new.js")).then(document => {
return window.showTextDocument(document).then(textEditor => {
return textEditor.edit(editBuilder => {
var lastLineLength = document.lineAt(document.lineCount - 1).text.length;
editBuilder.replace(new vscode.Range(new vscode.Position(0, 0), new vscode.Position(textEditor.document.lineCount - 1, lastLineLength)), value);
}).then(() => {
var idx = stringBefore ? value.indexOf(stringBefore) + stringBefore.length : 0;
var position = new Position(0, idx);
return phpCompletionProvider.provideCompletionItems(document, position, null);
})
})
});
};
var assertSuggestion= function(completions:CompletionItem[], label:string, kind: CompletionItemKind) {
@ -25,9 +30,9 @@ var assertSuggestion= function(completions:CompletionItem[], label:string, kind:
assert.equal(entries[0].kind, kind);
};
suite("Extension Tests", () => {
suite("PHP", () => {
test("Something 1", (testDone:(err?:any) => void) => {
test("Intellisense", (testDone:(err?:any) => void) => {
Promise.all([
testSuggestionsFor('<?php ', 'php ').then(completions => {
assertSuggestion(completions, '__CLASS__', CompletionItemKind.Field);