diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ebab5e3..8721feb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed +- Fixed hovering over user defined types while debugging + ([#426](https://github.com/fortran-lang/vscode-fortran-support/issues/426)) - Fixes linting regex to capture a wider spectrum of errors ([#295](https://github.com/krvajal/vscode-fortran-support/issues/295)) - Fixes linter activation from `Disabled` to some compiler `X` without having diff --git a/src/extension.ts b/src/extension.ts index 57ff4953..41968e20 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -61,6 +61,32 @@ export async function activate(context: vscode.ExtensionContext) { if (!config.get('fortls.disabled')) { new FortlsClient(loggingService, context).activate(); } + // override VS Code's default implementation of the debug hover + // here we match Fortran derived types and scope them appropriately + // e.g. "val%a%b" with hovering over "a" will match "val%a" + context.subscriptions.push( + vscode.languages.registerEvaluatableExpressionProvider(FortranDocumentSelector(), { + provideEvaluatableExpression( + document: vscode.TextDocument, + position: vscode.Position, + token: vscode.CancellationToken + ): vscode.ProviderResult { + // Match the % characters in defined types + const DERIVED_TYPE_REGEX = /[a-z][\w%]*/i; + // Get the word at the current position and the string matching + // the derived type REGEX. Use the start of the regex and end of word as range + const wordRange = document.getWordRangeAtPosition(position); + const derivedTypeRange = document.getWordRangeAtPosition(position, DERIVED_TYPE_REGEX); + if (wordRange) { + if (derivedTypeRange) { + return new vscode.EvaluatableExpression(wordRange.with(derivedTypeRange.start)); + } + return new vscode.EvaluatableExpression(wordRange); + } + return undefined; + }, + }) + ); } function detectDeprecatedOptions() {