-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display variable value in tooltip on hover.
This requires a functioning language server, e.g. `verible-verilog-ls`.
- Loading branch information
1 parent
ff0d5bc
commit 2d1729e
Showing
7 changed files
with
146 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,63 @@ | ||
import * as vscode from 'vscode'; | ||
|
||
import { CXXRTLDebugger } from '../debugger'; | ||
import { UnboundReference } from '../model/sample'; | ||
import { ScalarVariable, Variable } from '../model/variable'; | ||
import { DisplayStyle, languageForDisplayStyle, variableDescription, variableValue } from '../model/styling'; | ||
import { Session } from '../debug/session'; | ||
|
||
export class HoverProvider implements vscode.HoverProvider { | ||
static readonly SUPPORTED_LANGUAGES: string[] = ['verilog']; | ||
|
||
constructor( | ||
private rtlDebugger: CXXRTLDebugger | ||
) {} | ||
|
||
private async hoverForVariables(session: Session, variables: Variable[]): Promise<vscode.Hover | null> { | ||
if (variables.length === 0) { | ||
return null; | ||
} | ||
const displayStyle = vscode.workspace.getConfiguration('rtlDebugger').get('displayStyle') as DisplayStyle; | ||
const hoverText = new vscode.MarkdownString(); | ||
const unboundReference = new UnboundReference(); | ||
for (const variable of variables) { | ||
if (variable instanceof ScalarVariable) { | ||
unboundReference.add(variable.designation()); | ||
} | ||
} | ||
const reference = session.bindReference('hover', unboundReference); | ||
const sample = await session.queryAtCursor(reference); | ||
for (const [designation, handle] of reference.allHandles()) { | ||
const variable = designation.variable; | ||
const descriptionText = variableDescription(displayStyle, variable); | ||
const valueText = variableValue(displayStyle, variable, sample.extract(handle)); | ||
hoverText.appendCodeblock( | ||
`${variable.fullName.join('.')}${descriptionText} = ${valueText}`, | ||
languageForDisplayStyle(displayStyle) | ||
); | ||
} | ||
return new vscode.Hover(hoverText); | ||
} | ||
|
||
async provideHover(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Promise<vscode.Hover | null> { | ||
const session = this.rtlDebugger.session; | ||
if (session !== null) { | ||
const definitions = await ( | ||
vscode.commands.executeCommand('vscode.executeDefinitionProvider', document.uri, position) as | ||
vscode.ProviderResult<vscode.Definition | vscode.LocationLink[]> | ||
); | ||
let definition: vscode.Location | undefined; | ||
if (definitions instanceof vscode.Location) { | ||
definition = definitions; | ||
} else if (definitions instanceof Array && definitions.length === 1 && definitions[0] instanceof vscode.Location) { | ||
definition = definitions[0]; | ||
} else { | ||
console.warn('vscode.executeDefinitionProvider did not return a single Location: ', definition); | ||
return null; | ||
} | ||
const variables = await session.getVariablesForLocation(definition.uri.fsPath, definition.range.start); | ||
return await this.hoverForVariables(session, variables); | ||
} | ||
return null; | ||
} | ||
} |