mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 19:18:59 +01:00
add DiagnosticRelatedInformation, #10271
This commit is contained in:
@@ -599,6 +599,7 @@ export function createApiFactory(
|
||||
CompletionTriggerKind: extHostTypes.CompletionTriggerKind,
|
||||
DebugAdapterExecutable: extHostTypes.DebugAdapterExecutable,
|
||||
Diagnostic: extHostTypes.Diagnostic,
|
||||
DiagnosticRelatedInformation: extHostTypes.DiagnosticRelatedInformation,
|
||||
DiagnosticSeverity: extHostTypes.DiagnosticSeverity,
|
||||
Disposable: extHostTypes.Disposable,
|
||||
DocumentHighlight: extHostTypes.DocumentHighlight,
|
||||
|
||||
@@ -10,6 +10,7 @@ import URI from 'vs/base/common/uri';
|
||||
import * as vscode from 'vscode';
|
||||
import { MainContext, MainThreadDiagnosticsShape, ExtHostDiagnosticsShape, IMainContext } from './extHost.protocol';
|
||||
import { DiagnosticSeverity } from './extHostTypes';
|
||||
import * as converter from './extHostTypeConverters';
|
||||
import { mergeSort } from 'vs/base/common/arrays';
|
||||
import { Event, Emitter, debounceEvent, mapEvent } from 'vs/base/common/event';
|
||||
import { keys } from 'vs/base/common/map';
|
||||
@@ -115,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(DiagnosticCollection.toMarkerData(diagnostic));
|
||||
const len = marker.push(converter.fromDiagnostic(diagnostic));
|
||||
if (len === DiagnosticCollection._maxDiagnosticsPerFile) {
|
||||
break orderLoop;
|
||||
}
|
||||
@@ -133,7 +134,7 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection {
|
||||
endColumn: marker[marker.length - 1].endColumn
|
||||
});
|
||||
} else {
|
||||
marker = diagnostics.map(DiagnosticCollection.toMarkerData);
|
||||
marker = diagnostics.map(converter.fromDiagnostic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,32 +186,6 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection {
|
||||
}
|
||||
}
|
||||
|
||||
public static toMarkerData(diagnostic: vscode.Diagnostic): IMarkerData {
|
||||
|
||||
let range = diagnostic.range;
|
||||
|
||||
return <IMarkerData>{
|
||||
startLineNumber: range.start.line + 1,
|
||||
startColumn: range.start.character + 1,
|
||||
endLineNumber: range.end.line + 1,
|
||||
endColumn: range.end.character + 1,
|
||||
message: diagnostic.message,
|
||||
source: diagnostic.source,
|
||||
severity: DiagnosticCollection._convertDiagnosticsSeverity(diagnostic.severity),
|
||||
code: String(diagnostic.code)
|
||||
};
|
||||
}
|
||||
|
||||
private static _convertDiagnosticsSeverity(severity: number): MarkerSeverity {
|
||||
switch (severity) {
|
||||
case 0: return MarkerSeverity.Error;
|
||||
case 1: return MarkerSeverity.Warning;
|
||||
case 2: return MarkerSeverity.Info;
|
||||
case 3: return MarkerSeverity.Hint;
|
||||
default: return MarkerSeverity.Error;
|
||||
}
|
||||
}
|
||||
|
||||
private static _compareIndexedTuplesByUri(a: [vscode.Uri, vscode.Diagnostic[]], b: [vscode.Uri, vscode.Diagnostic[]]): number {
|
||||
if (a[0].toString() < b[0].toString()) {
|
||||
return -1;
|
||||
|
||||
@@ -15,7 +15,7 @@ import * as modes from 'vs/editor/common/modes';
|
||||
import { ExtHostHeapService } from 'vs/workbench/api/node/extHostHeapService';
|
||||
import { ExtHostDocuments } from 'vs/workbench/api/node/extHostDocuments';
|
||||
import { ExtHostCommands, CommandsConverter } from 'vs/workbench/api/node/extHostCommands';
|
||||
import { ExtHostDiagnostics, DiagnosticCollection } from 'vs/workbench/api/node/extHostDiagnostics';
|
||||
import { ExtHostDiagnostics } from 'vs/workbench/api/node/extHostDiagnostics';
|
||||
import { asWinJsPromise } from 'vs/base/common/async';
|
||||
import { MainContext, MainThreadLanguageFeaturesShape, ExtHostLanguageFeaturesShape, ObjectIdentifier, IRawColorInfo, IMainContext, IdObject, ISerializedRegExp, ISerializedIndentationRule, ISerializedOnEnterRule, ISerializedLanguageConfiguration, SymbolInformationDto, SuggestResultDto, WorkspaceSymbolsDto, SuggestionDto, CodeActionDto } from './extHost.protocol';
|
||||
import { regExpLeadsToEndlessLoop } from 'vs/base/common/strings';
|
||||
@@ -313,7 +313,7 @@ class CodeActionAdapter {
|
||||
result.push({
|
||||
title: candidate.title,
|
||||
command: candidate.command && this._commands.toInternal(candidate.command),
|
||||
diagnostics: candidate.diagnostics && candidate.diagnostics.map(DiagnosticCollection.toMarkerData),
|
||||
diagnostics: candidate.diagnostics && candidate.diagnostics.map(TypeConverters.fromDiagnostic),
|
||||
edit: candidate.edit && TypeConverters.WorkspaceEdit.from(candidate.edit),
|
||||
kind: candidate.kind && candidate.kind.value
|
||||
});
|
||||
|
||||
@@ -20,7 +20,7 @@ import * as htmlContent from 'vs/base/common/htmlContent';
|
||||
import { IRelativePattern } from 'vs/base/common/glob';
|
||||
import { LanguageSelector, LanguageFilter } from 'vs/editor/common/modes/languageSelector';
|
||||
import { WorkspaceEditDto, ResourceTextEditDto } from 'vs/workbench/api/node/extHost.protocol';
|
||||
import { MarkerSeverity } from 'vs/platform/markers/common/markers';
|
||||
import { MarkerSeverity, IRelatedInformation, IMarkerData } from 'vs/platform/markers/common/markers';
|
||||
|
||||
export interface PositionLike {
|
||||
line: number;
|
||||
@@ -83,6 +83,30 @@ export function fromPosition(position: types.Position): IPosition {
|
||||
return { lineNumber: position.line + 1, column: position.character + 1 };
|
||||
}
|
||||
|
||||
|
||||
export function fromDiagnostic(value: vscode.Diagnostic): IMarkerData {
|
||||
return {
|
||||
...fromRange(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 {
|
||||
...fromRange(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, toRange(value)), value.message);
|
||||
}
|
||||
|
||||
export function fromDiagnosticSeverity(value: number): MarkerSeverity {
|
||||
switch (value) {
|
||||
case types.DiagnosticSeverity.Error:
|
||||
@@ -111,6 +135,7 @@ export function toDiagnosticSeverty(value: MarkerSeverity): types.DiagnosticSeve
|
||||
return types.DiagnosticSeverity.Error;
|
||||
}
|
||||
|
||||
|
||||
export function fromViewColumn(column?: vscode.ViewColumn): EditorPosition {
|
||||
let editorColumn = EditorPosition.ONE;
|
||||
if (typeof column !== 'number') {
|
||||
|
||||
@@ -728,6 +728,27 @@ export class Location {
|
||||
}
|
||||
}
|
||||
|
||||
export class DiagnosticRelatedInformation {
|
||||
|
||||
static is(thing: any): thing is DiagnosticRelatedInformation {
|
||||
if (!thing) {
|
||||
return false;
|
||||
}
|
||||
return typeof (<DiagnosticRelatedInformation>thing).message === 'string'
|
||||
&& (<DiagnosticRelatedInformation>thing).location
|
||||
&& Range.isRange((<DiagnosticRelatedInformation>thing).location.range)
|
||||
&& URI.isUri((<DiagnosticRelatedInformation>thing).location.uri);
|
||||
}
|
||||
|
||||
location: Location;
|
||||
message: string;
|
||||
|
||||
constructor(location: Location, message: string) {
|
||||
this.location = location;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
export class Diagnostic {
|
||||
|
||||
range: Range;
|
||||
@@ -735,6 +756,7 @@ export class Diagnostic {
|
||||
source: string;
|
||||
code: string | number;
|
||||
severity: DiagnosticSeverity;
|
||||
relatedInformation: DiagnosticRelatedInformation[];
|
||||
|
||||
constructor(range: Range, message: string, severity: DiagnosticSeverity = DiagnosticSeverity.Error) {
|
||||
this.range = range;
|
||||
|
||||
Reference in New Issue
Block a user