Make LogLevel converters safer and consistent with other converters, from @jrieken feedback

This commit is contained in:
Rob Lourens
2018-12-06 11:02:09 -08:00
parent b2e8dcc412
commit 9be224980c
3 changed files with 57 additions and 7 deletions

View File

@@ -246,11 +246,11 @@ export function createApiFactory(
get appRoot() { return initData.environment.appRoot.fsPath; },
get logLevel() {
checkProposedApiEnabled(extension);
return typeConverters.LogLevel.fromMainLogLevel(extHostLogService.getLevel());
return typeConverters.LogLevel.to(extHostLogService.getLevel());
},
get onDidChangeLogLevel() {
checkProposedApiEnabled(extension);
return mapEvent(extHostLogService.onDidChangeLogLevel, l => typeConverters.LogLevel.fromMainLogLevel(l));
return mapEvent(extHostLogService.onDidChangeLogLevel, l => typeConverters.LogLevel.to(l));
},
get clipboard(): vscode.Clipboard {
return extHostClipboard;

View File

@@ -970,11 +970,49 @@ export namespace LanguageSelector {
}
export namespace LogLevel {
export function fromMainLogLevel(mainLevel: _MainLogLevel): types.LogLevel {
return mainLevel + 1;
export function from(extLevel: types.LogLevel): _MainLogLevel {
switch (extLevel) {
case types.LogLevel.Trace:
return _MainLogLevel.Trace;
case types.LogLevel.Debug:
return _MainLogLevel.Debug;
case types.LogLevel.Info:
return _MainLogLevel.Info;
case types.LogLevel.Warning:
return _MainLogLevel.Warning;
case types.LogLevel.Error:
return _MainLogLevel.Error;
case types.LogLevel.Critical:
return _MainLogLevel.Critical;
case types.LogLevel.Critical:
return _MainLogLevel.Critical;
case types.LogLevel.Off:
return _MainLogLevel.Off;
}
return _MainLogLevel.Info;
}
export function toMainLogLevel(extLevel: types.LogLevel): _MainLogLevel {
return extLevel - 1;
export function to(mainLevel: _MainLogLevel): types.LogLevel {
switch (mainLevel) {
case _MainLogLevel.Trace:
return types.LogLevel.Trace;
case _MainLogLevel.Debug:
return types.LogLevel.Debug;
case _MainLogLevel.Info:
return types.LogLevel.Info;
case _MainLogLevel.Warning:
return types.LogLevel.Warning;
case _MainLogLevel.Error:
return types.LogLevel.Error;
case _MainLogLevel.Critical:
return types.LogLevel.Critical;
case _MainLogLevel.Critical:
return types.LogLevel.Critical;
case _MainLogLevel.Off:
return types.LogLevel.Off;
}
return types.LogLevel.Info;
}
}