Skip to content

Commit 185630f

Browse files
committed
add MarkerSeverity, microsoft#44141
1 parent 0a165e8 commit 185630f

20 files changed

Lines changed: 138 additions & 107 deletions

File tree

build/monaco/monaco.d.ts.recipe

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ declare module monaco {
3232
Error = 3,
3333
}
3434

35+
export enum MarkerSeverity {
36+
Hint = 1,
37+
Info = 2,
38+
Warning = 4,
39+
Error = 8,
40+
}
41+
42+
3543
#include(vs/base/common/winjs.base.d.ts): TValueCallback, ProgressCallback, Promise
3644
#include(vs/base/common/cancellation): CancellationTokenSource, CancellationToken
3745
#include(vs/base/common/uri): URI, UriComponents

src/vs/base/common/severity.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,8 @@ namespace Severity {
4646
if (strings.equalsIgnoreCase(_info, value)) {
4747
return Severity.Info;
4848
}
49-
5049
return Severity.Ignore;
5150
}
52-
53-
export function toString(value: Severity): string {
54-
return _displayStrings[value] || strings.empty;
55-
}
56-
57-
export function compare(a: Severity, b: Severity): number {
58-
return b - a;
59-
}
6051
}
6152

62-
export default Severity;
53+
export default Severity;

src/vs/editor/common/services/modelServiceImpl.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ import network = require('vs/base/common/network');
99
import Event, { Emitter } from 'vs/base/common/event';
1010
import { MarkdownString } from 'vs/base/common/htmlContent';
1111
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
12-
import Severity from 'vs/base/common/severity';
1312
import URI from 'vs/base/common/uri';
1413
import { TPromise } from 'vs/base/common/winjs.base';
15-
import { IMarker, IMarkerService } from 'vs/platform/markers/common/markers';
14+
import { IMarker, IMarkerService, MarkerSeverity } from 'vs/platform/markers/common/markers';
1615
import { Range } from 'vs/editor/common/core/range';
1716
import { Selection } from 'vs/editor/common/core/selection';
1817
import { TextModel, createTextBuffer } from 'vs/editor/common/model/textModel';
@@ -120,20 +119,20 @@ class ModelMarkerHandler {
120119
let darkColor: ThemeColor;
121120

122121
switch (marker.severity) {
123-
case Severity.Ignore:
122+
case MarkerSeverity.Hint:
124123
// do something
125124
break;
126-
case Severity.Warning:
125+
case MarkerSeverity.Warning:
127126
className = ClassName.EditorWarningDecoration;
128127
color = themeColorFromId(overviewRulerWarning);
129128
darkColor = themeColorFromId(overviewRulerWarning);
130129
break;
131-
case Severity.Info:
130+
case MarkerSeverity.Info:
132131
className = ClassName.EditorInfoDecoration;
133132
color = themeColorFromId(overviewRulerInfo);
134133
darkColor = themeColorFromId(overviewRulerInfo);
135134
break;
136-
case Severity.Error:
135+
case MarkerSeverity.Error:
137136
default:
138137
className = ClassName.EditorErrorDecoration;
139138
color = themeColorFromId(overviewRulerError);

src/vs/editor/common/standalone/standaloneBase.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
1313
import { CancellationTokenSource } from 'vs/base/common/cancellation';
1414
import { Token } from 'vs/editor/common/core/token';
1515
import URI from 'vs/base/common/uri';
16+
import { MarkerSeverity } from 'vs/platform/markers/common/markers';
1617

1718
// --------------------------------------------
1819
// This is repeated here so it can be exported
@@ -238,6 +239,7 @@ export function createMonacoBaseAPI(): typeof monaco {
238239
Selection: Selection,
239240
SelectionDirection: SelectionDirection,
240241
Severity: Severity,
242+
MarkerSeverity: MarkerSeverity,
241243
Promise: TPromise,
242244
Uri: <any>URI,
243245
Token: Token

src/vs/editor/contrib/gotoError/gotoError.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ import * as nls from 'vs/nls';
99
import { Emitter } from 'vs/base/common/event';
1010
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
1111
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
12-
import Severity from 'vs/base/common/severity';
1312
import URI from 'vs/base/common/uri';
1413
import { RawContextKey, IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
15-
import { IMarker, IMarkerService } from 'vs/platform/markers/common/markers';
14+
import { IMarker, IMarkerService, MarkerSeverity } from 'vs/platform/markers/common/markers';
1615
import { Position } from 'vs/editor/common/core/position';
1716
import { Range } from 'vs/editor/common/core/range';
1817
import * as editorCommon from 'vs/editor/common/editorCommon';
@@ -308,7 +307,7 @@ class MarkerNavigationAction extends EditorAction {
308307
return undefined;
309308
}
310309

311-
let oldMarker = model.currentMarker || { resource: editor.getModel().uri, severity: Severity.Error, startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 };
310+
let oldMarker = model.currentMarker || <IMarker>{ resource: editor.getModel().uri, severity: MarkerSeverity.Error, startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 };
312311
let idx = binarySearch(markers, oldMarker, MarkerNavigationAction.compareMarker);
313312
if (idx < 0) {
314313
// find best match...
@@ -346,7 +345,7 @@ class MarkerNavigationAction extends EditorAction {
346345
static compareMarker(a: IMarker, b: IMarker): number {
347346
let res = compare(a.resource.toString(), b.resource.toString());
348347
if (res === 0) {
349-
res = Severity.compare(a.severity, b.severity);
348+
res = MarkerSeverity.compare(a.severity, b.severity);
350349
}
351350
if (res === 0) {
352351
res = Range.compareRangesUsingStarts(a, b);

src/vs/editor/contrib/gotoError/gotoErrorWidget.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
import 'vs/css!./gotoErrorWidget';
99
import * as nls from 'vs/nls';
1010
import * as dom from 'vs/base/browser/dom';
11-
import Severity from 'vs/base/common/severity';
1211
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
13-
import { IMarker } from 'vs/platform/markers/common/markers';
12+
import { IMarker, MarkerSeverity } from 'vs/platform/markers/common/markers';
1413
import { Position } from 'vs/editor/common/core/position';
1514
import { Range } from 'vs/editor/common/core/range';
1615
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
@@ -98,15 +97,15 @@ export class MarkerNavigationWidget extends ZoneWidget {
9897
private _title: HTMLElement;
9998
private _message: MessageWidget;
10099
private _callOnDispose: IDisposable[] = [];
101-
private _severity: Severity;
100+
private _severity: MarkerSeverity;
102101
private _backgroundColor: Color;
103102

104103
constructor(
105104
editor: ICodeEditor,
106105
private _themeService: IThemeService
107106
) {
108107
super(editor, { showArrow: true, showFrame: true, isAccessible: true });
109-
this._severity = Severity.Warning;
108+
this._severity = MarkerSeverity.Warning;
110109
this._backgroundColor = Color.white;
111110

112111
this._applyTheme(_themeService.getTheme());
@@ -118,9 +117,9 @@ export class MarkerNavigationWidget extends ZoneWidget {
118117
private _applyTheme(theme: ITheme) {
119118
this._backgroundColor = theme.getColor(editorMarkerNavigationBackground);
120119
let colorId = editorMarkerNavigationError;
121-
if (this._severity === Severity.Warning) {
120+
if (this._severity === MarkerSeverity.Warning) {
122121
colorId = editorMarkerNavigationWarning;
123-
} else if (this._severity === Severity.Info) {
122+
} else if (this._severity === MarkerSeverity.Info) {
124123
colorId = editorMarkerNavigationInfo;
125124
}
126125
let frameColor = theme.getColor(colorId);

src/vs/editor/contrib/quickFix/test/quickFix.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
import * as assert from 'assert';
88
import URI from 'vs/base/common/uri';
9-
import Severity from 'vs/base/common/severity';
109
import { TextModel } from 'vs/editor/common/model/textModel';
1110
import { CodeActionProviderRegistry, LanguageIdentifier, CodeActionProvider, Command, WorkspaceEdit, ResourceTextEdit, CodeAction, CodeActionContext } from 'vs/editor/common/modes';
1211
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
1312
import { Range } from 'vs/editor/common/core/range';
1413
import { getCodeActions } from 'vs/editor/contrib/quickFix/quickFix';
1514
import { CodeActionKind } from 'vs/editor/contrib/quickFix/codeActionTrigger';
15+
import { MarkerSeverity } from 'vs/platform/markers/common/markers';
1616

1717
suite('QuickFix', () => {
1818

@@ -29,7 +29,7 @@ suite('QuickFix', () => {
2929
startColumn: 1,
3030
endLineNumber: 2,
3131
endColumn: 1,
32-
severity: Severity.Error,
32+
severity: MarkerSeverity.Error,
3333
message: 'abc'
3434
}]
3535
},
@@ -40,7 +40,7 @@ suite('QuickFix', () => {
4040
startColumn: 1,
4141
endLineNumber: 2,
4242
endColumn: 1,
43-
severity: Severity.Error,
43+
severity: MarkerSeverity.Error,
4444
message: 'bcd'
4545
}]
4646
}

src/vs/monaco.d.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ declare module monaco {
3232
Error = 3,
3333
}
3434

35+
export enum MarkerSeverity {
36+
Hint = 1,
37+
Info = 2,
38+
Warning = 4,
39+
Error = 8,
40+
}
41+
42+
3543

3644

3745
export type TValueCallback<T = any> = (value: T | PromiseLike<T>) => void;
@@ -1068,7 +1076,7 @@ declare module monaco.editor {
10681076
export interface IMarker {
10691077
owner: string;
10701078
resource: Uri;
1071-
severity: Severity;
1079+
severity: MarkerSeverity;
10721080
code?: string;
10731081
message: string;
10741082
source?: string;
@@ -1084,7 +1092,7 @@ declare module monaco.editor {
10841092
*/
10851093
export interface IMarkerData {
10861094
code?: string;
1087-
severity: Severity;
1095+
severity: MarkerSeverity;
10881096
message: string;
10891097
source?: string;
10901098
startLineNumber: number;

src/vs/platform/markers/common/markerService.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import { IDisposable } from 'vs/base/common/lifecycle';
1010
import { isEmptyObject } from 'vs/base/common/types';
1111
import URI from 'vs/base/common/uri';
1212
import Event, { Emitter, debounceEvent } from 'vs/base/common/event';
13-
import Severity from 'vs/base/common/severity';
14-
import { IMarkerService, IMarkerData, IResourceMarker, IMarker, MarkerStatistics } from './markers';
13+
import { IMarkerService, IMarkerData, IResourceMarker, IMarker, MarkerStatistics, MarkerSeverity } from './markers';
1514

1615
interface MapMap<V> {
1716
[key: string]: { [key: string]: V };
@@ -88,11 +87,11 @@ class MarkerStats implements MarkerStatistics {
8887
}
8988

9089
for (const { severity } of this._service.read({ resource })) {
91-
if (severity === Severity.Error) {
90+
if (severity === MarkerSeverity.Error) {
9291
result.errors += 1;
93-
} else if (severity === Severity.Warning) {
92+
} else if (severity === MarkerSeverity.Warning) {
9493
result.warnings += 1;
95-
} else if (severity === Severity.Info) {
94+
} else if (severity === MarkerSeverity.Info) {
9695
result.infos += 1;
9796
} else {
9897
result.unknowns += 1;

src/vs/platform/markers/common/markers.ts

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
'use strict';
66

77
import URI from 'vs/base/common/uri';
8-
import Severity from 'vs/base/common/severity';
98
import Event from 'vs/base/common/event';
109
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
10+
import { localize } from 'vs/nls';
11+
import Severity from 'vs/base/common/severity';
1112

1213
export interface IMarkerService {
1314
_serviceBrand: any;
@@ -37,12 +38,44 @@ export interface IRelatedInformation {
3738
endColumn: number;
3839
}
3940

41+
export enum MarkerSeverity {
42+
Hint = 1,
43+
Info = 2,
44+
Warning = 4,
45+
Error = 8,
46+
}
47+
48+
export namespace MarkerSeverity {
49+
50+
export function compare(a: MarkerSeverity, b: MarkerSeverity): number {
51+
return b - a;
52+
}
53+
54+
const _displayStrings: { [value: number]: string; } = Object.create(null);
55+
_displayStrings[MarkerSeverity.Error] = localize('sev.error', "Error");
56+
_displayStrings[MarkerSeverity.Warning] = localize('sev.warning', "Warning");
57+
_displayStrings[MarkerSeverity.Info] = localize('sev.info', "Info");
58+
59+
export function toString(a: MarkerSeverity): string {
60+
return _displayStrings[a] || '';
61+
}
62+
63+
export function fromSeverity(severity: Severity): MarkerSeverity {
64+
switch (severity) {
65+
case Severity.Error: return MarkerSeverity.Error;
66+
case Severity.Warning: return MarkerSeverity.Warning;
67+
case Severity.Info: return MarkerSeverity.Info;
68+
case Severity.Ignore: return MarkerSeverity.Hint;
69+
}
70+
}
71+
}
72+
4073
/**
4174
* A structure defining a problem/warning/etc.
4275
*/
4376
export interface IMarkerData {
4477
code?: string;
45-
severity: Severity;
78+
severity: MarkerSeverity;
4679
message: string;
4780
source?: string;
4881
startLineNumber: number;
@@ -60,7 +93,7 @@ export interface IResourceMarker {
6093
export interface IMarker {
6194
owner: string;
6295
resource: URI;
63-
severity: Severity;
96+
severity: MarkerSeverity;
6497
code?: string;
6598
message: string;
6699
source?: string;
@@ -93,7 +126,7 @@ export namespace IMarkerData {
93126
result.push(emptyString);
94127
}
95128
if (markerData.severity !== void 0 && markerData.severity !== null) {
96-
result.push(Severity.toString(markerData.severity));
129+
result.push(MarkerSeverity.toString(markerData.severity));
97130
} else {
98131
result.push(emptyString);
99132
}

0 commit comments

Comments
 (0)