Skip to content

Commit

Permalink
define map object instead of switch-case
Browse files Browse the repository at this point in the history
  • Loading branch information
yukukotani committed Mar 8, 2021
1 parent 2d7f019 commit e4b3788
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions vti/src/commands/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('====================================');
Expand All @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit e4b3788

Please sign in to comment.