-
Notifications
You must be signed in to change notification settings - Fork 29.3k
/
markers.ts
191 lines (166 loc) · 5.36 KB
/
markers.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Event } from '../../../base/common/event.js';
import Severity from '../../../base/common/severity.js';
import { URI } from '../../../base/common/uri.js';
import { localize } from '../../../nls.js';
import { createDecorator } from '../../instantiation/common/instantiation.js';
export interface IMarkerService {
readonly _serviceBrand: undefined;
getStatistics(): MarkerStatistics;
changeOne(owner: string, resource: URI, markers: IMarkerData[]): void;
changeAll(owner: string, data: IResourceMarker[]): void;
remove(owner: string, resources: URI[]): void;
read(filter?: { owner?: string; resource?: URI; severities?: number; take?: number }): IMarker[];
readonly onMarkerChanged: Event<readonly URI[]>;
}
/**
*
*/
export interface IRelatedInformation {
resource: URI;
message: string;
startLineNumber: number;
startColumn: number;
endLineNumber: number;
endColumn: number;
}
export const enum MarkerTag {
Unnecessary = 1,
Deprecated = 2
}
export enum MarkerSeverity {
Hint = 1,
Info = 2,
Warning = 4,
Error = 8,
}
export namespace MarkerSeverity {
export function compare(a: MarkerSeverity, b: MarkerSeverity): number {
return b - a;
}
const _displayStrings: { [value: number]: string } = Object.create(null);
_displayStrings[MarkerSeverity.Error] = localize('sev.error', "Error");
_displayStrings[MarkerSeverity.Warning] = localize('sev.warning', "Warning");
_displayStrings[MarkerSeverity.Info] = localize('sev.info', "Info");
export function toString(a: MarkerSeverity): string {
return _displayStrings[a] || '';
}
export function fromSeverity(severity: Severity): MarkerSeverity {
switch (severity) {
case Severity.Error: return MarkerSeverity.Error;
case Severity.Warning: return MarkerSeverity.Warning;
case Severity.Info: return MarkerSeverity.Info;
case Severity.Ignore: return MarkerSeverity.Hint;
}
}
export function toSeverity(severity: MarkerSeverity): Severity {
switch (severity) {
case MarkerSeverity.Error: return Severity.Error;
case MarkerSeverity.Warning: return Severity.Warning;
case MarkerSeverity.Info: return Severity.Info;
case MarkerSeverity.Hint: return Severity.Ignore;
}
}
}
/**
* A structure defining a problem/warning/etc.
*/
export interface IMarkerData {
code?: string | { value: string; target: URI };
severity: MarkerSeverity;
message: string;
source?: string;
startLineNumber: number;
startColumn: number;
endLineNumber: number;
endColumn: number;
modelVersionId?: number;
relatedInformation?: IRelatedInformation[];
tags?: MarkerTag[];
}
export interface IResourceMarker {
resource: URI;
marker: IMarkerData;
}
export interface IMarker {
owner: string;
resource: URI;
severity: MarkerSeverity;
code?: string | { value: string; target: URI };
message: string;
source?: string;
startLineNumber: number;
startColumn: number;
endLineNumber: number;
endColumn: number;
modelVersionId?: number;
relatedInformation?: IRelatedInformation[];
tags?: MarkerTag[];
}
export interface MarkerStatistics {
errors: number;
warnings: number;
infos: number;
unknowns: number;
}
export namespace IMarkerData {
const emptyString = '';
export function makeKey(markerData: IMarkerData): string {
return makeKeyOptionalMessage(markerData, true);
}
export function makeKeyOptionalMessage(markerData: IMarkerData, useMessage: boolean): string {
const result: string[] = [emptyString];
if (markerData.source) {
result.push(markerData.source.replace('¦', '\\¦'));
} else {
result.push(emptyString);
}
if (markerData.code) {
if (typeof markerData.code === 'string') {
result.push(markerData.code.replace('¦', '\\¦'));
} else {
result.push(markerData.code.value.replace('¦', '\\¦'));
}
} else {
result.push(emptyString);
}
if (markerData.severity !== undefined && markerData.severity !== null) {
result.push(MarkerSeverity.toString(markerData.severity));
} else {
result.push(emptyString);
}
// Modifed to not include the message as part of the marker key to work around
// https://github.com/microsoft/vscode/issues/77475
if (markerData.message && useMessage) {
result.push(markerData.message.replace('¦', '\\¦'));
} else {
result.push(emptyString);
}
if (markerData.startLineNumber !== undefined && markerData.startLineNumber !== null) {
result.push(markerData.startLineNumber.toString());
} else {
result.push(emptyString);
}
if (markerData.startColumn !== undefined && markerData.startColumn !== null) {
result.push(markerData.startColumn.toString());
} else {
result.push(emptyString);
}
if (markerData.endLineNumber !== undefined && markerData.endLineNumber !== null) {
result.push(markerData.endLineNumber.toString());
} else {
result.push(emptyString);
}
if (markerData.endColumn !== undefined && markerData.endColumn !== null) {
result.push(markerData.endColumn.toString());
} else {
result.push(emptyString);
}
result.push(emptyString);
return result.join('¦');
}
}
export const IMarkerService = createDecorator<IMarkerService>('markerService');