diff --git a/src/timeline/adjustment.ts b/src/timeline/adjustment.ts index 8cf39e1..44bb62e 100644 --- a/src/timeline/adjustment.ts +++ b/src/timeline/adjustment.ts @@ -1,6 +1,9 @@ import { Range, Selection, TextEditor, window } from 'vscode' +import * as nls from 'vscode-nls' -import { adjustTime, localize } from '../utils' +import { adjustTime } from '../utils' + +const localize = nls.loadMessageBundle() /** indicate the whole lines is selected */ const selectWholeLines = (selection: Selection, editor: TextEditor): Range => { diff --git a/src/timeline/code-lens.ts b/src/timeline/code-lens.ts index c758cce..c24f45e 100644 --- a/src/timeline/code-lens.ts +++ b/src/timeline/code-lens.ts @@ -2,8 +2,11 @@ import { exec } from 'child_process' import { promisify } from 'util' import * as vscode from 'vscode' +import * as nls from 'vscode-nls' -import { localize } from '../utils' +import { output } from '../utils' + +const localize = nls.loadMessageBundle() export class TimelineCodeLensProvider implements vscode.CodeLensProvider { // eslint-disable-next-line @typescript-eslint/naming-convention @@ -28,16 +31,19 @@ export class TimelineCodeLensProvider implements vscode.CodeLensProvider { codeLenses.push( new vscode.CodeLens(range, { command: 'cactbot.timeline.runGenerateScript', - title: 'run make_timeline', - tooltip: localize('codeLens.makeTimeline.run', 'Run `make_timeline` command'), + title: localize('codeLens.makeTimeline.run.title', 'run make_timeline'), + tooltip: localize('codeLens.makeTimeline.run.tooltip', 'Run `make_timeline` command'), arguments: args, }), ) codeLenses.push( new vscode.CodeLens(range, { command: 'cactbot.timeline.runGenerateScriptWithoutExecution', - title: 'send make_timeline', - tooltip: localize('codeLens.makeTimeline.send', 'Send `make_timeline` command to terminal without execution'), + title: localize('codeLens.makeTimeline.send.title', 'send make_timeline'), + tooltip: localize( + 'codeLens.makeTimeline.send.tooltip', + 'Send `make_timeline` command to terminal without execution', + ), arguments: args, }), ) @@ -63,7 +69,13 @@ export async function runMakeTimeline(args: IArguments[], run = true): Promise => { @@ -104,7 +108,7 @@ export class TranslatedTimelineProvider implements TextDocumentContentProvider { } } - async provideTextDocumentContent(uri: Uri): Promise { + async provideTextDocumentContent(uri: Uri) { const timelineFilePath = uri.path const triggerFilePath = await this.getTriggerFilePath(timelineFilePath) if (!triggerFilePath) { @@ -123,14 +127,26 @@ export class TranslatedTimelineProvider implements TextDocumentContentProvider { }) } catch (e) { const err = e as Error - return localize( - 'error.timeline.translate.stack', - 'Error when translating file "{0}":\n{1}\n{2}\n{3}', - uri.path, - err.name, - err.message, - err.stack, + const ans = await window.showErrorMessage( + localize( + 'error.timeline.translate.dialog', + 'Error when translating file "{0}": {1}\nShow more details?', + uri.path, + err.name, + ), + { modal: true }, + localize('error.timeline.translate.dialog.buttons.yes', 'Yes'), + localize('error.timeline.translate.dialog.buttons.no', 'No'), + ) + + output.appendLine( + localize('error.timeline.translate.stack', '{0}: {1}\n{2}{3}', uri.path, err.name, err.message, err.stack), ) + + if (ans === localize('error.timeline.translate.dialog.buttons.yes', 'Yes')) { + // switch to output panel + output.show() + } } } @@ -221,9 +237,9 @@ export class TranslatedTimelineProvider implements TextDocumentContentProvider { } } catch (err) { const error = err as Error - console.warn( + throw new Error( localize( - 'error.transle.line.stack', + 'error.translate.line.stack', 'Error in translating line {0}:\n{1}\n{2}\n{3}', index, error.name, @@ -285,16 +301,6 @@ export const translateTimeline = async (): Promise => { return } let filename = document.fileName - if (!/\w*ui.raidboss.data.\d\d.*\.(ts|js|txt)/.test(filename)) { - await window.showErrorMessage( - localize( - 'error.timeline.file.not.valid', - '{0} is not a valid file path, please make sure the path of your active file is "ui/raidboss/data/**/*.(js|ts)"', - filename, - ), - ) - return - } // TODO: very hacky way // maybe it should be the `timelineFile` or `timeline` key in the trigger file diff --git a/src/utils/i18n.ts b/src/utils/i18n.ts deleted file mode 100644 index 8bbb77f..0000000 --- a/src/utils/i18n.ts +++ /dev/null @@ -1,3 +0,0 @@ -import * as nls from 'vscode-nls' - -export const localize = nls.loadMessageBundle() diff --git a/src/utils/index.ts b/src/utils/index.ts index df292cb..178e1bb 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,2 +1,2 @@ export * from './timeline' -export * from './i18n' +export * from './vscode' diff --git a/src/utils/vscode.ts b/src/utils/vscode.ts new file mode 100644 index 0000000..1a0d6f1 --- /dev/null +++ b/src/utils/vscode.ts @@ -0,0 +1,4 @@ +import * as vscode from 'vscode' + +export const output = vscode.window.createOutputChannel('Cactbot Timeline') +