Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1289: Tooltip for linked template code lens #1292

Merged
merged 1 commit into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
});