diff --git a/ahk2 b/ahk2 index 5be91832..83dabc48 160000 --- a/ahk2 +++ b/ahk2 @@ -1 +1 @@ -Subproject commit 5be918325917ddc9a3500778c30a55ca5dd4086d +Subproject commit 83dabc48b4096c9e1d9a7708dddcbbba79ebe7a1 diff --git a/demos/manualTests/definitionProvider/included.ahk1 b/e2e/definitionProvider/included.ahk1 similarity index 86% rename from demos/manualTests/definitionProvider/included.ahk1 rename to e2e/definitionProvider/included.ahk1 index 3c3cbf77..37d727dc 100644 --- a/demos/manualTests/definitionProvider/included.ahk1 +++ b/e2e/definitionProvider/included.ahk1 @@ -4,6 +4,7 @@ SendMode, Input SetBatchLines, -1 SetWorkingDir, %A_ScriptDir% +; Hi from included.ahk1 MyDefProviderFunc() { MsgBox % "Hi from MyDefProviderFunc" } \ No newline at end of file diff --git a/demos/manualTests/definitionProvider/main.ahk1 b/e2e/definitionProvider/main.ahk1 similarity index 100% rename from demos/manualTests/definitionProvider/main.ahk1 rename to e2e/definitionProvider/main.ahk1 diff --git a/src/providers/completionProvider.ts b/src/providers/completionProvider.ts index 52be6b94..efe2f6d8 100644 --- a/src/providers/completionProvider.ts +++ b/src/providers/completionProvider.ts @@ -92,7 +92,7 @@ export const provideCompletionItemsInner = ( ): vscode.CompletionItem[] => methods .map((m) => completionItemsForMethod(m, uriString, lineNumber)) - .reduce((a, b) => a.concat(b), []) + .reduce((a, b) => a.concat(b), []) // reduce from 2D array to 1D array .concat(variables.map(completionItemForVariable)); export class CompletionProvider implements vscode.CompletionItemProvider { diff --git a/src/providers/defProvider.e2e.ts b/src/providers/defProvider.e2e.ts index 430d8542..0ae685f7 100644 --- a/src/providers/defProvider.e2e.ts +++ b/src/providers/defProvider.e2e.ts @@ -1,6 +1,36 @@ import assert from 'assert'; import { tryGetFileLink } from './defProvider'; +import path from 'path'; +import { + getActiveEditor, + getDocument, + goToDefinition, + goToLine, + showDocument, + sleep, +} from '../test/utils'; +/** Currently in `/out/src/providers`, want to get to `/` */ +const rootPath = path.join(__dirname, '..', '..', '..'); + +suite('provideDefinition', () => { + test('go to definition', async () => { + const filePath = path.resolve( + rootPath, + `./e2e/definitionProvider/main.ahk1`, + ); + const doc = await getDocument(filePath); + const editor = await showDocument(doc); + await sleep(1000); // wait for workspace to be indexed + + goToLine(editor, 10); + + await goToDefinition(); + assert(getActiveEditor().document.fileName.includes('included.ahk1')); + }); +}); + +// Unit test masked as e2e test due to dependency on vscode types suite(tryGetFileLink.name, () => { const tests: [ name: string, diff --git a/src/test/config.e2e.ts b/src/test/config.e2e.ts index eb9d0136..5bf03c45 100644 --- a/src/test/config.e2e.ts +++ b/src/test/config.e2e.ts @@ -11,10 +11,10 @@ import { sleep, updateConfig, } from './utils'; -import { resolve } from 'path'; import { ConfigKey, LibIncludeType, ShowOutput } from '../common/global'; import { suite, before, test } from 'mocha'; +/** Currently in `/out/src/test`, want to get to `/` */ const rootPath = path.join(__dirname, '..', '..', '..'); // Currently in `out` folder, need to get back to main `src` folder @@ -88,7 +88,7 @@ suite('exclude', () => { if (version === 1) { await updateConfig(ConfigKey.exclude, exclude); } - const filePath = resolve(rootPath, `./e2e/main.ahk${version}`); + const filePath = path.resolve(rootPath, `./e2e/main.ahk${version}`); const doc = await getDocument(filePath); const editor = await showDocument(doc); await sleep(1_000); // todo only these tests are extra flaky @@ -105,7 +105,7 @@ suite('v2.general.librarySuggestions', () => { let editor: vscode.TextEditor; before(async () => { await updateConfig(ConfigKey.exclude, []); - const filePath = resolve(rootPath, './e2e/main.ahk2'); + const filePath = path.resolve(rootPath, './e2e/main.ahk2'); const doc = await getDocument(filePath); editor = await showDocument(doc); await sleep(1_000); diff --git a/src/test/utils.ts b/src/test/utils.ts index 60cd54b3..00f437b1 100644 --- a/src/test/utils.ts +++ b/src/test/utils.ts @@ -53,6 +53,7 @@ export const updateConfig = async ( /** * Adds the provided snippetText at the current selection of the editor * and adds a newline to minimize syntax errors. + * * Waits after selecting so callers don't have to. */ export const addAndSelectSnippet = async ( @@ -80,3 +81,28 @@ export const getCompletionSuggestionLabels = async ( const labels = completionItems?.items.map((i) => i.label); return labels; }; + +export const goToDefinition = async (): Promise => { + await vscode.commands.executeCommand('editor.action.revealDefinition'); +}; + +/** + * Move the seleciton to the 1-based line number. + * + * Optionally provide the 1-based column number: The selection will be placed before this column. + * Provide 0 for the start of the line. + * + * `columnNumber` defaults to 0 + */ +export const goToLine = ( + editor: vscode.TextEditor, + lineNumber: number, + columnNumber: number = 0, +): void => { + const pos = new vscode.Position(lineNumber - 1, columnNumber); + editor.selection = new vscode.Selection(pos, pos); +}; + +export const getActiveEditor = (): vscode.TextEditor => { + return vscode.window.activeTextEditor; +};