type converters, use namespace for Diagnostics

This commit is contained in:
Johannes Rieken
2018-05-04 18:26:52 +02:00
parent 9f6053242f
commit d52bf577dc
3 changed files with 53 additions and 48 deletions

View File

@@ -116,7 +116,7 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection {
orderLoop: for (let i = 0; i < 4; i++) {
for (let diagnostic of diagnostics) {
if (diagnostic.severity === order[i]) {
const len = marker.push(converter.fromDiagnostic(diagnostic));
const len = marker.push(converter.Diagnostic.from(diagnostic));
if (len === DiagnosticCollection._maxDiagnosticsPerFile) {
break orderLoop;
}
@@ -134,7 +134,7 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection {
endColumn: marker[marker.length - 1].endColumn
});
} else {
marker = diagnostics.map(converter.fromDiagnostic);
marker = diagnostics.map(converter.Diagnostic.from);
}
}

View File

@@ -311,7 +311,7 @@ class CodeActionAdapter {
result.push({
title: candidate.title,
command: candidate.command && this._commands.toInternal(candidate.command),
diagnostics: candidate.diagnostics && candidate.diagnostics.map(typeConvert.fromDiagnostic),
diagnostics: candidate.diagnostics && candidate.diagnostics.map(typeConvert.Diagnostic.from),
edit: candidate.edit && typeConvert.WorkspaceEdit.from(candidate.edit),
kind: candidate.kind && candidate.kind.value
});

View File

@@ -88,55 +88,60 @@ export namespace Position {
}
}
export function fromDiagnostic(value: vscode.Diagnostic): IMarkerData {
return {
...Range.from(value.range),
message: value.message,
source: value.source,
code: String(value.code),
severity: fromDiagnosticSeverity(value.severity),
relatedInformation: value.relatedInformation && value.relatedInformation.map(fromDiagnosticRelatedInformation)
};
}
export function fromDiagnosticRelatedInformation(value: types.DiagnosticRelatedInformation): IRelatedInformation {
return {
...Range.from(value.location.range),
message: value.message,
resource: value.location.uri
};
}
export function toDiagnosticRelatedInformation(value: IRelatedInformation): types.DiagnosticRelatedInformation {
return new types.DiagnosticRelatedInformation(new types.Location(value.resource, Range.to(value)), value.message);
}
export function fromDiagnosticSeverity(value: number): MarkerSeverity {
switch (value) {
case types.DiagnosticSeverity.Error:
return MarkerSeverity.Error;
case types.DiagnosticSeverity.Warning:
return MarkerSeverity.Warning;
case types.DiagnosticSeverity.Information:
return MarkerSeverity.Info;
case types.DiagnosticSeverity.Hint:
return MarkerSeverity.Hint;
export namespace Diagnostic {
export function from(value: vscode.Diagnostic): IMarkerData {
return {
...Range.from(value.range),
message: value.message,
source: value.source,
code: String(value.code),
severity: DiagnosticSeverity.from(value.severity),
relatedInformation: value.relatedInformation && value.relatedInformation.map(DiagnosticRelatedInformation.from)
};
}
return MarkerSeverity.Error;
}
export function toDiagnosticSeverty(value: MarkerSeverity): types.DiagnosticSeverity {
switch (value) {
case MarkerSeverity.Info:
return types.DiagnosticSeverity.Information;
case MarkerSeverity.Warning:
return types.DiagnosticSeverity.Warning;
case MarkerSeverity.Error:
return types.DiagnosticSeverity.Error;
case MarkerSeverity.Hint:
return types.DiagnosticSeverity.Hint;
export namespace DiagnosticRelatedInformation {
export function from(value: types.DiagnosticRelatedInformation): IRelatedInformation {
return {
...Range.from(value.location.range),
message: value.message,
resource: value.location.uri
};
}
export function to(value: IRelatedInformation): types.DiagnosticRelatedInformation {
return new types.DiagnosticRelatedInformation(new types.Location(value.resource, Range.to(value)), value.message);
}
}
export namespace DiagnosticSeverity {
export function from(value: number): MarkerSeverity {
switch (value) {
case types.DiagnosticSeverity.Error:
return MarkerSeverity.Error;
case types.DiagnosticSeverity.Warning:
return MarkerSeverity.Warning;
case types.DiagnosticSeverity.Information:
return MarkerSeverity.Info;
case types.DiagnosticSeverity.Hint:
return MarkerSeverity.Hint;
}
return MarkerSeverity.Error;
}
export function to(value: MarkerSeverity): types.DiagnosticSeverity {
switch (value) {
case MarkerSeverity.Info:
return types.DiagnosticSeverity.Information;
case MarkerSeverity.Warning:
return types.DiagnosticSeverity.Warning;
case MarkerSeverity.Error:
return types.DiagnosticSeverity.Error;
case MarkerSeverity.Hint:
return types.DiagnosticSeverity.Hint;
}
return types.DiagnosticSeverity.Error;
}
return types.DiagnosticSeverity.Error;
}