Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/api/browser/mainThreadDiagnostics.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 { IMarkerService, IMarkerData, type IMarker } from '../../../platform/markers/common/markers.js';
7
import { URI, UriComponents } from '../../../base/common/uri.js';
8
import { MainThreadDiagnosticsShape, MainContext, ExtHostDiagnosticsShape, ExtHostContext } from '../common/extHost.protocol.js';
9
import { extHostNamedCustomer, IExtHostContext } from '../../services/extensions/common/extHostCustomers.js';
10
import { IDisposable } from '../../../base/common/lifecycle.js';
11
import { IUriIdentityService } from '../../../platform/uriIdentity/common/uriIdentity.js';
12
import { ResourceMap } from '../../../base/common/map.js';
13
14
@extHostNamedCustomer(MainContext.MainThreadDiagnostics)
15
export class MainThreadDiagnostics implements MainThreadDiagnosticsShape {
16
17
private readonly _activeOwners = new Set<string>();
18
19
private readonly _proxy: ExtHostDiagnosticsShape;
20
private readonly _markerListener: IDisposable;
21
22
private static ExtHostCounter: number = 1;
23
private readonly extHostId: string;
24
25
constructor(
26
extHostContext: IExtHostContext,
27
@IMarkerService private readonly _markerService: IMarkerService,
28
@IUriIdentityService private readonly _uriIdentService: IUriIdentityService,
29
) {
30
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostDiagnostics);
31
32
this._markerListener = this._markerService.onMarkerChanged(this._forwardMarkers, this);
33
this.extHostId = `extHost${MainThreadDiagnostics.ExtHostCounter++}`;
34
}
35
36
dispose(): void {
37
this._markerListener.dispose();
38
for (const owner of this._activeOwners) {
39
const markersData: ResourceMap<IMarker[]> = new ResourceMap<IMarker[]>();
40
for (const marker of this._markerService.read({ owner })) {
41
let data = markersData.get(marker.resource);
42
if (data === undefined) {
43
data = [];
44
markersData.set(marker.resource, data);
45
}
46
if (marker.origin !== this.extHostId) {
47
data.push(marker);
48
}
49
}
50
for (const [resource, local] of markersData.entries()) {
51
this._markerService.changeOne(owner, resource, local);
52
}
53
}
54
this._activeOwners.clear();
55
}
56
57
private _forwardMarkers(resources: readonly URI[]): void {
58
const data: [UriComponents, IMarkerData[]][] = [];
59
for (const resource of resources) {
60
const allMarkerData = this._markerService.read({ resource, ignoreResourceFilters: true });
61
if (allMarkerData.length === 0) {
62
data.push([resource, []]);
63
} else {
64
const foreignMarkerData = allMarkerData.filter(marker => marker?.origin !== this.extHostId);
65
if (foreignMarkerData.length > 0) {
66
data.push([resource, foreignMarkerData]);
67
}
68
}
69
}
70
if (data.length > 0) {
71
this._proxy.$acceptMarkersChange(data);
72
}
73
}
74
75
$changeMany(owner: string, entries: [UriComponents, IMarkerData[]][]): void {
76
for (const entry of entries) {
77
const [uri, markers] = entry;
78
if (markers) {
79
for (const marker of markers) {
80
if (marker.relatedInformation) {
81
for (const relatedInformation of marker.relatedInformation) {
82
relatedInformation.resource = URI.revive(relatedInformation.resource);
83
}
84
}
85
if (marker.code && typeof marker.code !== 'string') {
86
marker.code.target = URI.revive(marker.code.target);
87
}
88
if (marker.origin === undefined) {
89
marker.origin = this.extHostId;
90
}
91
}
92
}
93
this._markerService.changeOne(owner, this._uriIdentService.asCanonicalUri(URI.revive(uri)), markers);
94
}
95
this._activeOwners.add(owner);
96
}
97
98
$clear(owner: string): void {
99
this._markerService.changeAll(owner, []);
100
this._activeOwners.delete(owner);
101
}
102
}
103
104