Skip to content

Commit 69b9d55

Browse files
committed
Debug hover over user defined types
Fixes #426 We register a custom Evaluatable expression which captures the entire variable from start until the correct `%` where the cursor is located.
1 parent ca58a29 commit 69b9d55

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
### Fixed
1313

14+
- Fixed hovering over user defined types while debugging
15+
([#426](https://github.com/fortran-lang/vscode-fortran-support/issues/426))
1416
- Fixes linting regex to capture a wider spectrum of errors
1517
([#295](https://github.com/krvajal/vscode-fortran-support/issues/295))
1618
- Fixes linter activation from `Disabled` to some compiler `X` without having

src/extension.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,32 @@ export async function activate(context: vscode.ExtensionContext) {
6161
if (!config.get<boolean>('fortls.disabled')) {
6262
new FortlsClient(loggingService, context).activate();
6363
}
64+
// override VS Code's default implementation of the debug hover
65+
// here we match Fortran derived types and scope them appropriately
66+
// e.g. "val%a%b" with hovering over "a" will match "val%a"
67+
context.subscriptions.push(
68+
vscode.languages.registerEvaluatableExpressionProvider(FortranDocumentSelector(), {
69+
provideEvaluatableExpression(
70+
document: vscode.TextDocument,
71+
position: vscode.Position,
72+
token: vscode.CancellationToken
73+
): vscode.ProviderResult<vscode.EvaluatableExpression> {
74+
// Match the % characters in defined types
75+
const DERIVED_TYPE_REGEX = /[a-z][\w%]*/i;
76+
// Get the word at the current position and the string matching
77+
// the derived type REGEX. Use the start of the regex and end of word as range
78+
const wordRange = document.getWordRangeAtPosition(position);
79+
const derivedTypeRange = document.getWordRangeAtPosition(position, DERIVED_TYPE_REGEX);
80+
if (wordRange) {
81+
if (derivedTypeRange) {
82+
return new vscode.EvaluatableExpression(wordRange.with(derivedTypeRange.start));
83+
}
84+
return new vscode.EvaluatableExpression(wordRange);
85+
}
86+
return undefined;
87+
},
88+
})
89+
);
6490
}
6591

6692
function detectDeprecatedOptions() {

0 commit comments

Comments
 (0)