Skip to content

Commit

Permalink
1289: Tooltip for linked template code lens (#1292)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephen Weatherford <[email protected]>
  • Loading branch information
StephenWeatherford and Stephen Weatherford authored Apr 16, 2021
1 parent 052dcf4 commit dd242ee
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
23 changes: 17 additions & 6 deletions src/documents/templates/ChildTemplateCodeLens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -37,8 +37,7 @@ export class NestedTemplateCodeLens extends ChildTemplateCodeLens {
super(scope, span);
this.command = {
title: title,
command: '',
tooltip: "TOOLTIP"
command: ''
};
}

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand Down
7 changes: 6 additions & 1 deletion test/global.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});

0 comments on commit dd242ee

Please sign in to comment.