Skip to content

Commit

Permalink
cleanup comments and import
Browse files Browse the repository at this point in the history
  • Loading branch information
fflaten committed Aug 12, 2022
1 parent 168efff commit f580b4c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
10 changes: 6 additions & 4 deletions src/documentParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}

Expand All @@ -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));
}
Expand All @@ -62,14 +62,16 @@ 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)) {
const functionRange = utils.range(func.range.start.line, func.range.end.line);
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));
}
}
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
4 changes: 2 additions & 2 deletions src/test/suite/index.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
// Create the mocha test
Expand All @@ -13,7 +13,7 @@ export async function run(): Promise<void> {
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) => {
Expand Down
4 changes: 2 additions & 2 deletions src/test/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<vscode.Extension<any>> {
Expand All @@ -31,7 +31,7 @@ export async function ensureExtensionIsActivated(): Promise<vscode.Extension<any
}

/**
* ensureEditorServicesIsConnected
* ensureEditorServicesIsConnected()
* https://github.com/PowerShell/vscode-powershell/blob/c323846803f0d43f75562a7fd1e8c225099cc528/test/utils.ts#L23-L29
*/
export async function ensureEditorServicesIsConnected(): Promise<void> {
Expand Down
2 changes: 2 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -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 => {
Expand Down

0 comments on commit f580b4c

Please sign in to comment.