-
Notifications
You must be signed in to change notification settings - Fork 5
Limit inline values to current function-scope #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5849467
add setting to control start of inline values
fflaten 6e33928
v2
fflaten 0164640
fix tests
fflaten 9ca2bfa
optimize regex
fflaten 282baec
optimize
fflaten 903592e
cleanup and split util functions to own file
fflaten 518dffc
add tests
fflaten c657bf9
add tests
fflaten 7318a71
fix tests
fflaten fc2863a
increase timeout for tests
fflaten d3d4e47
extract documentParser and add unit tests
fflaten 1ba721c
fix typo in tests
fflaten 3caa580
fix perf excludedLines lookup
fflaten 168efff
fix perf tests
fflaten f580b4c
cleanup comments and import
fflaten File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import * as vscode from 'vscode'; | ||
import * as utils from './utils'; | ||
|
||
export class DocumentParser { | ||
// Used to avoid calling symbol provider for the same document on every stopped location | ||
private readonly functionCache: Map<string, vscode.DocumentSymbol[]> = new Map<string, vscode.DocumentSymbol[]>(); | ||
|
||
// Clear cache between debugsessions to get updated symbols | ||
clearFunctionCache(): void { | ||
this.functionCache.clear(); | ||
} | ||
|
||
async getFunctionsInScope(document: vscode.TextDocument, stoppedLocation: vscode.Range): Promise<vscode.DocumentSymbol[]> { | ||
const functions = await this.getFunctionsInDocument(document); | ||
const stoppedStart = stoppedLocation.start.line; | ||
const stoppedEnd = stoppedLocation.end.line; | ||
const res: vscode.DocumentSymbol[] = []; | ||
|
||
for (var i = 0, length = functions.length; i < length; ++i) { | ||
const func = functions[i]; | ||
// 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); | ||
} | ||
} | ||
|
||
return res; | ||
} | ||
|
||
async getFunctionsInDocument(document: vscode.TextDocument): Promise<vscode.DocumentSymbol[]> { | ||
const cacheKey = document.uri.toString(); | ||
if (this.functionCache.has(cacheKey)) { | ||
return this.functionCache.get(cacheKey)!; | ||
} | ||
|
||
const documentSymbols = await vscode.commands.executeCommand<vscode.DocumentSymbol[]>('vscode.executeDocumentSymbolProvider', document.uri); | ||
let functions: vscode.DocumentSymbol[] = []; | ||
|
||
if (documentSymbols) { | ||
// Get all functions in a flat array from the symbol-tree | ||
functions = utils.flattenSymbols(documentSymbols).filter(s => s.kind === vscode.SymbolKind.Function); | ||
} | ||
|
||
this.functionCache.set(cacheKey, functions); | ||
return functions; | ||
} | ||
|
||
async getStartLine(document: vscode.TextDocument, startLocationSetting: string, stoppedLocation: vscode.Range): Promise<number> { | ||
if (startLocationSetting === 'document') { | ||
return 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)); | ||
} | ||
|
||
async getExcludedLines(document: vscode.TextDocument, stoppedLocation: vscode.Range, startLine: number): Promise<Set<number>> { | ||
const functions = await this.getFunctionsInDocument(document); | ||
const stoppedEnd = stoppedLocation.end.line; | ||
const excludedLines = []; | ||
|
||
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 | ||
// 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)); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
import * as vscode from 'vscode'; | ||
import { PowerShellVariableInlineValuesProvider } from './powerShellVariableInlineValuesProvider'; | ||
import { DocumentParser } from './documentParser'; | ||
|
||
export function activate(context: vscode.ExtensionContext) { | ||
context.subscriptions.push(vscode.languages.registerInlineValuesProvider('powershell', new PowerShellVariableInlineValuesProvider())); | ||
const parser = new DocumentParser(); | ||
|
||
context.subscriptions.push(vscode.languages.registerInlineValuesProvider('powershell', new PowerShellVariableInlineValuesProvider(parser))); | ||
|
||
// 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') { | ||
parser.clearFunctionCache(); | ||
} | ||
}) | ||
); | ||
} | ||
|
||
export function deactivate() { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.