From e33df100a8984cc161cca8fe9503037ae3af42bd Mon Sep 17 00:00:00 2001 From: Yuku Kotani Date: Mon, 8 Mar 2021 23:05:31 +0900 Subject: [PATCH] define map object instead of switch-ase --- vti/src/commands/diagnostics.ts | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/vti/src/commands/diagnostics.ts b/vti/src/commands/diagnostics.ts index f6cf4c53b8..93632edecb 100644 --- a/vti/src/commands/diagnostics.ts +++ b/vti/src/commands/diagnostics.ts @@ -26,6 +26,12 @@ import { Range } from 'vscode-languageclient'; export type LogLevel = typeof logLevels[number]; export const logLevels = ['ERROR', 'WARN', 'INFO', 'HINT'] as const; +const logLevel2Severity = { + ERROR: DiagnosticSeverity.Error, + WARN: DiagnosticSeverity.Warning, + INFO: DiagnosticSeverity.Information, + HINT: DiagnosticSeverity.Hint +}; export async function diagnostics(workspace: string | null, logLevel: LogLevel) { console.log('===================================='); @@ -41,7 +47,7 @@ export async function diagnostics(workspace: string | null, logLevel: LogLevel) workspaceUri = URI.file(process.cwd()); } - const errCount = await getDiagnostics(workspaceUri, logLevel2Severity(logLevel)); + const errCount = await getDiagnostics(workspaceUri, logLevel2Severity[logLevel]); console.log('===================================='); if (errCount === 0) { @@ -115,19 +121,6 @@ function range2Location(range: Range): SourceLocation { }; } -function logLevel2Severity(logLevel: LogLevel): DiagnosticSeverity { - switch (logLevel) { - case 'ERROR': - return DiagnosticSeverity.Error; - case 'WARN': - return DiagnosticSeverity.Warning; - case 'INFO': - return DiagnosticSeverity.Information; - case 'HINT': - return DiagnosticSeverity.Hint; - } -} - async function getDiagnostics(workspaceUri: URI, severity: DiagnosticSeverity) { const clientConnection = await prepareClientConnection(workspaceUri);