Skip to content
Merged
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
18 changes: 16 additions & 2 deletions src/templates/script/parseScriptTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,20 @@ function getVariableValue(resources: IResources, variables: IVariables, data: st
return getResourceValue(resources, data);
}

export function getResourceValue(resources: IResources, data: string): string {

export function getResourceValue(resources: IResources, data: string, dontThrow: true): string | undefined;
export function getResourceValue(resources: IResources, data: string, dontThrow?: false): string;
export function getResourceValue(resources: IResources, data: string, dontThrow: boolean | undefined): string | undefined {
const matches: RegExpMatchArray | null = data.match(/\$(.*)/);
if (matches === null) {
return data;
} else {
const key: string = matches[1];
const result: string | undefined = resources.lang && resources.lang[key] ? resources.lang[key] : resources.en[key];
if (result === undefined) {
if (dontThrow) {
return undefined;
}
throw new Error(localize('resourceNotFound', 'Resource "{0}" not found.', data));
} else {
return result;
Expand All @@ -119,11 +125,19 @@ function parseScriptSetting(data: object, resources: IResources, variables: IVar
}
}

function getDescription(): string | undefined {
if (rawSetting.help) {
const resourceValue = getResourceValue(resources, rawSetting.help, true);
return resourceValue ? replaceHtmlLinkWithMarkdown(resourceValue) : undefined;
}
return undefined;
}

return {
name: getVariableValue(resources, variables, rawSetting.name),
resourceType: rawSetting.resource,
valueType: rawSetting.value,
description: rawSetting.help ? replaceHtmlLinkWithMarkdown(getResourceValue(resources, rawSetting.help)) : undefined,
description: getDescription(),
defaultValue: rawSetting.defaultValue,
label: getVariableValue(resources, variables, rawSetting.label),
enums: enums,
Expand Down