Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/api/test/browser/mainThreadDiagnostics.test.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import assert from 'assert';
7
import { timeout } from '../../../../base/common/async.js';
8
import { URI, UriComponents } from '../../../../base/common/uri.js';
9
import { runWithFakedTimers } from '../../../../base/test/common/timeTravelScheduler.js';
10
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js';
11
import { MarkerService } from '../../../../platform/markers/common/markerService.js';
12
import { IMarkerData } from '../../../../platform/markers/common/markers.js';
13
import { IUriIdentityService } from '../../../../platform/uriIdentity/common/uriIdentity.js';
14
import { MainThreadDiagnostics } from '../../browser/mainThreadDiagnostics.js';
15
import { IExtHostContext } from '../../../services/extensions/common/extHostCustomers.js';
16
import { ExtensionHostKind } from '../../../services/extensions/common/extensionHostKind.js';
17
import { mock } from '../../../test/common/workbenchTestServices.js';
18
19
20
suite('MainThreadDiagnostics', function () {
21
22
let markerService: MarkerService;
23
24
setup(function () {
25
markerService = new MarkerService();
26
});
27
28
teardown(function () {
29
markerService.dispose();
30
});
31
32
ensureNoDisposablesAreLeakedInTestSuite();
33
34
test('clear markers on dispose', function () {
35
36
const diag = new MainThreadDiagnostics(
37
new class implements IExtHostContext {
38
remoteAuthority = '';
39
extensionHostKind = ExtensionHostKind.LocalProcess;
40
dispose() { }
41
assertRegistered() { }
42
set(v: any): any { return null; }
43
getProxy(): any {
44
return {
45
$acceptMarkersChange() { }
46
};
47
}
48
drain(): any { return null; }
49
},
50
markerService,
51
new class extends mock<IUriIdentityService>() {
52
override asCanonicalUri(uri: URI) { return uri; }
53
}
54
);
55
56
diag.$changeMany('foo', [[URI.file('a'), [{
57
code: '666',
58
startLineNumber: 1,
59
startColumn: 1,
60
endLineNumber: 1,
61
endColumn: 1,
62
message: 'fffff',
63
severity: 1,
64
source: 'me'
65
}]]]);
66
67
assert.strictEqual(markerService.read().length, 1);
68
diag.dispose();
69
assert.strictEqual(markerService.read().length, 0);
70
});
71
72
test('OnDidChangeDiagnostics triggers twice on same diagnostics #136434', function () {
73
74
return runWithFakedTimers({}, async () => {
75
76
const changedData: [UriComponents, IMarkerData[]][][] = [];
77
78
const diag = new MainThreadDiagnostics(
79
new class implements IExtHostContext {
80
remoteAuthority = '';
81
extensionHostKind = ExtensionHostKind.LocalProcess;
82
dispose() { }
83
assertRegistered() { }
84
set(v: any): any { return null; }
85
getProxy(): any {
86
return {
87
$acceptMarkersChange(data: [UriComponents, IMarkerData[]][]) {
88
changedData.push(data);
89
}
90
};
91
}
92
drain(): any { return null; }
93
},
94
markerService,
95
new class extends mock<IUriIdentityService>() {
96
override asCanonicalUri(uri: URI) { return uri; }
97
}
98
);
99
100
const markerDataStub = {
101
code: '666',
102
startLineNumber: 1,
103
startColumn: 1,
104
endLineNumber: 1,
105
endColumn: 1,
106
severity: 1,
107
source: 'me'
108
};
109
const target = URI.file('a');
110
diag.$changeMany('foo', [[target, [{ ...markerDataStub, message: 'same_owner' }]]]);
111
markerService.changeOne('bar', target, [{ ...markerDataStub, message: 'forgein_owner' }]);
112
113
// added one marker via the API and one via the ext host. the latter must not
114
// trigger an event to the extension host
115
116
await timeout(0);
117
assert.strictEqual(markerService.read().length, 2);
118
assert.strictEqual(changedData.length, 1);
119
assert.strictEqual(changedData[0].length, 1);
120
assert.strictEqual(changedData[0][0][1][0].message, 'forgein_owner');
121
122
diag.dispose();
123
});
124
});
125
126
test('onDidChangeDiagnostics different behavior when "extensionKind" ui running on remote workspace #136955', function () {
127
return runWithFakedTimers({}, async () => {
128
129
const markerData: IMarkerData = {
130
code: '666',
131
startLineNumber: 1,
132
startColumn: 1,
133
endLineNumber: 1,
134
endColumn: 1,
135
severity: 1,
136
source: 'me',
137
message: 'message'
138
};
139
const target = URI.file('a');
140
markerService.changeOne('bar', target, [markerData]);
141
142
const changedData: [UriComponents, IMarkerData[]][][] = [];
143
144
const diag = new MainThreadDiagnostics(
145
new class implements IExtHostContext {
146
remoteAuthority = '';
147
extensionHostKind = ExtensionHostKind.LocalProcess;
148
dispose() { }
149
assertRegistered() { }
150
set(v: any): any { return null; }
151
getProxy(): any {
152
return {
153
$acceptMarkersChange(data: [UriComponents, IMarkerData[]][]) {
154
changedData.push(data);
155
}
156
};
157
}
158
drain(): any { return null; }
159
},
160
markerService,
161
new class extends mock<IUriIdentityService>() {
162
override asCanonicalUri(uri: URI) { return uri; }
163
}
164
);
165
166
diag.$clear('bar');
167
await timeout(0);
168
assert.strictEqual(markerService.read().length, 0);
169
assert.strictEqual(changedData.length, 1);
170
171
diag.dispose();
172
});
173
});
174
});
175
176