From dd242eea59a63f5b35111e40665cb910f4ffd726 Mon Sep 17 00:00:00 2001 From: "Stephen Weatherford (MSFT)" Date: Thu, 15 Apr 2021 17:43:34 -0700 Subject: [PATCH] 1289: Tooltip for linked template code lens (#1292) Co-authored-by: Stephen Weatherford --- .../templates/ChildTemplateCodeLens.ts | 23 ++++++++++++++----- test/global.test.ts | 7 +++++- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/documents/templates/ChildTemplateCodeLens.ts b/src/documents/templates/ChildTemplateCodeLens.ts index dbae96318..2499acaab 100644 --- a/src/documents/templates/ChildTemplateCodeLens.ts +++ b/src/documents/templates/ChildTemplateCodeLens.ts @@ -13,7 +13,7 @@ import { assert } from "../../fixed_assert"; import { Span } from '../../language/Span'; import { LanguageServerState } from '../../languageclient/startArmLanguageServer'; import { assertNever } from '../../util/assertNever'; -import { parseUri, stringifyUri } from "../../util/uri"; +import { parseUri } from "../../util/uri"; import { ResolvableCodeLens } from '../DeploymentDocument'; import { IParameterValuesSourceProvider } from '../parameters/IParameterValuesSourceProvider'; import { SelectParameterFileCodeLens } from "./deploymentTemplateCodeLenses"; @@ -37,8 +37,7 @@ export class NestedTemplateCodeLens extends ChildTemplateCodeLens { super(scope, span); this.command = { title: title, - command: '', - tooltip: "TOOLTIP" + command: '' }; } @@ -97,12 +96,14 @@ export class LinkedTemplateCodeLens extends ChildTemplateCodeLens { scope: TemplateScope, span: Span, title: string, - linkedFileUri?: Uri + linkedFileUri?: Uri, + tooltip?: string ) { super(scope, span); this.command = { title: title, command: linkedFileUri ? 'azurerm-vscode-tools.codeLens.openLinkedTemplateFile' : '', + tooltip, arguments: linkedFileUri ? [linkedFileUri] @@ -151,17 +152,27 @@ export class LinkedTemplateCodeLens extends ChildTemplateCodeLens { let linkedUri: Uri | undefined; let friendlyPath: string | undefined; + let fullPath: string | undefined; try { const templateUri = scope.document.documentUri; linkedUri = firstLinkedTemplateRef?.fullUri ? parseUri(firstLinkedTemplateRef.fullUri) : undefined; if (linkedUri && templateUri.fsPath && linkedUri.scheme === documentSchemes.file) { const templateFolder = path.dirname(templateUri.fsPath); friendlyPath = path.relative(templateFolder, linkedUri.fsPath); + fullPath = linkedUri.fsPath; if (!path.isAbsolute(friendlyPath) && !friendlyPath.startsWith('.')) { friendlyPath = `.${ext.pathSeparator}${friendlyPath}`; } } else { - friendlyPath = linkedUri ? stringifyUri(linkedUri) : undefined; + const maxQueryLength = 40; + let shortenedUri = linkedUri; + fullPath = linkedUri?.toString(true); + if (linkedUri && linkedUri?.query.length > maxQueryLength) { + shortenedUri = shortenedUri?.with({ + query: `${linkedUri.query.slice(0, maxQueryLength)}...` + }); + } + friendlyPath = shortenedUri ? shortenedUri.toString(true) : undefined; } } catch (error) { console.warn(parseError(error).message); @@ -179,7 +190,7 @@ export class LinkedTemplateCodeLens extends ChildTemplateCodeLens { title += ` - ${langServerLoadState}`; } - lenses.push(new LinkedTemplateCodeLens(scope, span, title, linkedUri)); + lenses.push(new LinkedTemplateCodeLens(scope, span, title, linkedUri, fullPath)); addSelectParamFileLensIfNeeded(lenses, fullValidationStatus, topLevelParameterValuesProvider, scope, span); diff --git a/test/global.test.ts b/test/global.test.ts index 54a372385..f51cd07eb 100644 --- a/test/global.test.ts +++ b/test/global.test.ts @@ -99,7 +99,12 @@ setup(function (this: Mocha.IBeforeAndAfterContext): void { teardown(function (this: Mocha.IBeforeAndAfterContext): void { // console.warn("Teardown"); if (!this.currentTest.state || this.currentTest.state === 'failed') { - console.warn(`\n========= TESTLOG =========:\n${testLog.toString()}\n`); + if (testLog.toString()) { + console.warn("Failed"); + console.warn(`Failed. TEST LOG:\n${testLog.toString()}\n`); + } else { + console.warn("Failed (test log is empty)"); + } deleteTestLog(); } });