diff --git a/src/completions.ts b/src/completions.ts index 6e5353c..ca524cd 100644 --- a/src/completions.ts +++ b/src/completions.ts @@ -1,7 +1,7 @@ import {TextDocument, Position, CancellationToken, ProviderResult, CompletionItem, CompletionItemProvider, Range, SnippetString, CompletionItemKind, window} from "vscode"; import { Documenter } from "./documenter"; -export class Completions implements CompletionItemProvider +export default class Completions implements CompletionItemProvider { protected tags = [ { @@ -54,7 +54,7 @@ export class Completions implements CompletionItemProvider result.push(block); } - let match = part.match(/.*?(@[a-z])$/); + let match = part.match(/.*?\* (@[a-z]+)$/); if (match == null) { return result; @@ -66,7 +66,7 @@ export class Completions implements CompletionItemProvider return tag.tag.match(prefix) !== null; }); - let range:Range = document.getWordRangeAtPosition(position, /@[a-z]/); + let range:Range = document.getWordRangeAtPosition(position, /@[a-z]+/); potential.forEach(tag => { let item = new CompletionItem(tag.tag, CompletionItemKind.Snippet); @@ -78,4 +78,4 @@ export class Completions implements CompletionItemProvider return result; } -} \ No newline at end of file +} diff --git a/src/extension.ts b/src/extension.ts index 0ced9a0..8a51f39 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -3,7 +3,7 @@ import * as vscode from 'vscode'; import { spawn, execFile, exec, ChildProcess } from 'child_process'; import * as path from 'path'; import { Documenter } from "./documenter"; -import { Completions } from "./completions"; +import Completions from "./completions"; export function activate(context: vscode.ExtensionContext) { vscode.languages.setLanguageConfiguration('php', { @@ -29,9 +29,14 @@ export function activate(context: vscode.ExtensionContext) { ] }); - vscode.languages.registerCompletionItemProvider('php', new Completions(), '*'); + vscode.languages.registerCompletionItemProvider( + 'php', + new Completions(), + '*', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', + 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u','v', 'w', 'x', 'y' + ); } // this method is called when your extension is deactivated export function deactivate() { -} \ No newline at end of file +} diff --git a/test/completions.test.ts b/test/completions.test.ts new file mode 100644 index 0000000..6cc5938 --- /dev/null +++ b/test/completions.test.ts @@ -0,0 +1,35 @@ +import * as assert from 'assert'; +import {TextEditor, TextDocument, CancellationTokenSource, CancellationToken, Position, ProviderResult, CompletionItem} from 'vscode'; +import Helper from './helpers'; +import Completions from '../src/completions'; + +suite("Completion tests", () => { + let editor:TextEditor; + let document:TextDocument; + let testPositions:any = {}; + let completions = new Completions(); + + let map = Helper.getFixtureMap('completions.php.json'); + + suiteSetup(function(done) { + Helper.loadFixture('completions.php', (edit:TextEditor, doc:TextDocument) => { + editor = edit; + document = doc; + testPositions = Helper.getFixturePositions(document); + done(); + }); + }); + + map.forEach(testData => { + test("Completion: "+ testData.name, () => { + let pos:Position = testPositions[testData.key]; + let result:ProviderResult = completions.provideCompletionItems( + document, + document.lineAt(pos.line+1).range.end, + new CancellationTokenSource().token + ); + + assert.equal(testData.tag, result[0].label); + }); + }); +}); diff --git a/test/fixtures/completions.php b/test/fixtures/completions.php new file mode 100644 index 0000000..510571d --- /dev/null +++ b/test/fixtures/completions.php @@ -0,0 +1,10 @@ + + +////=> param + * @para + +////=> return + * @ret + +////=> package + * @pack diff --git a/test/fixtures/completions.php.json b/test/fixtures/completions.php.json new file mode 100644 index 0000000..071e96e --- /dev/null +++ b/test/fixtures/completions.php.json @@ -0,0 +1,17 @@ +[ + { + "key": "param", + "name": "Param tag", + "tag": "@param" + }, + { + "key": "return", + "name": "Return tag", + "tag": "@return" + }, + { + "key": "package", + "name": "Package tag", + "tag": "@package" + } +]