diff --git a/src/documentParser.ts b/src/documentParser.ts index fd278b3..2093b8d 100644 --- a/src/documentParser.ts +++ b/src/documentParser.ts @@ -18,7 +18,7 @@ export class DocumentParser { for (var i = 0, length = functions.length; i < length; ++i) { const func = functions[i]; - // only return functions with stopped location in range + // Only return functions with stopped location inside range if (func.range.start.line <= stoppedStart && func.range.end.line >= stoppedEnd && func.range.contains(stoppedLocation)) { res.push(func); } @@ -37,7 +37,7 @@ export class DocumentParser { let functions: vscode.DocumentSymbol[] = []; if (documentSymbols) { - // flatten symbols and keep only functions + // Get all functions in a flat array from the symbol-tree functions = utils.flattenSymbols(documentSymbols).filter(s => s.kind === vscode.SymbolKind.Function); } @@ -50,7 +50,7 @@ export class DocumentParser { return 0; } - // Lookup closest matching function start or default to document start (0) + // Lookup closest matching function start line or default to document start (0) const functions = await this.getFunctionsInScope(document, stoppedLocation); return Math.max(0, ...functions.map(fn => fn.range.start.line)); } @@ -62,7 +62,7 @@ export class DocumentParser { for (var i = 0, length = functions.length; i < length; ++i) { const func = functions[i]; - // startLine (either document start or closest function start) are provided, so functions necessary to exclude + // StartLine (either document start or closest function start) are provided, so functions necessary to exclude // will always start >= documentStart or same as currentFunction start if nested function. // Don't bother checking functions before startLine or after stoppedLocation if (func.range.start.line >= startLine && func.range.start.line <= stoppedEnd && !func.range.contains(stoppedLocation)) { @@ -70,6 +70,8 @@ export class DocumentParser { excludedLines.push(...functionRange); } } + + // Ensure we don't exclude our stopped location and make lookup blazing fast return new Set(excludedLines.filter(line => line < stoppedLocation.start.line || line > stoppedEnd)); } } diff --git a/src/extension.ts b/src/extension.ts index 542aefe..85e6454 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -7,7 +7,7 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push(vscode.languages.registerInlineValuesProvider('powershell', new PowerShellVariableInlineValuesProvider(parser))); - // Clear function cache to get updated files in next debug session + // Clear function symbol cache to ensure we get symbols from any updated files context.subscriptions.push( vscode.debug.onDidTerminateDebugSession((e) => { if (e.type.toLowerCase() === 'powershell') { diff --git a/src/test/suite/index.ts b/src/test/suite/index.ts index 5251005..d66f35f 100644 --- a/src/test/suite/index.ts +++ b/src/test/suite/index.ts @@ -1,7 +1,7 @@ import * as path from 'path'; import * as Mocha from 'mocha'; import * as glob from 'glob'; -import * as testUtils from '../testUtils'; +import { ensureEditorServicesIsConnected } from '../testUtils'; export async function run(): Promise { // Create the mocha test @@ -13,7 +13,7 @@ export async function run(): Promise { const testsRoot = path.resolve(__dirname, '..'); // Ensure PowerShell extension is finished starting because we need it's symbol provider - await testUtils.ensureEditorServicesIsConnected(); + await ensureEditorServicesIsConnected(); return new Promise((c, e) => { glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { diff --git a/src/test/testUtils.ts b/src/test/testUtils.ts index 1949ec0..0801f66 100644 --- a/src/test/testUtils.ts +++ b/src/test/testUtils.ts @@ -21,7 +21,7 @@ export interface IPowerShellExtensionClient { } /** - * ensureEditorServicesIsConnected + * Modified version of ensureEditorServicesIsConnected() * https://github.com/PowerShell/vscode-powershell/blob/c323846803f0d43f75562a7fd1e8c225099cc528/test/utils.ts#L17-L21 */ export async function ensureExtensionIsActivated(): Promise> { @@ -31,7 +31,7 @@ export async function ensureExtensionIsActivated(): Promise { diff --git a/src/utils.ts b/src/utils.ts index 3d9de62..593f75f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,9 +1,11 @@ import { DocumentSymbol } from 'vscode'; +// Because 1..10 isn't supported here... export function range(start: number, end: number) { return Array(end - start + 1).fill(undefined).map((_, i) => start + i); } +// Convert the symbol-tree to a flat array export function flattenSymbols(symbols: DocumentSymbol[]): DocumentSymbol[] { let result: DocumentSymbol[] = []; symbols.map(symbol => {