Path: blob/main/src/vs/workbench/api/browser/mainThreadDiagnostics.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { IMarkerService, IMarkerData, type IMarker } from '../../../platform/markers/common/markers.js';6import { URI, UriComponents } from '../../../base/common/uri.js';7import { MainThreadDiagnosticsShape, MainContext, ExtHostDiagnosticsShape, ExtHostContext } from '../common/extHost.protocol.js';8import { extHostNamedCustomer, IExtHostContext } from '../../services/extensions/common/extHostCustomers.js';9import { IDisposable } from '../../../base/common/lifecycle.js';10import { IUriIdentityService } from '../../../platform/uriIdentity/common/uriIdentity.js';11import { ResourceMap } from '../../../base/common/map.js';1213@extHostNamedCustomer(MainContext.MainThreadDiagnostics)14export class MainThreadDiagnostics implements MainThreadDiagnosticsShape {1516private readonly _activeOwners = new Set<string>();1718private readonly _proxy: ExtHostDiagnosticsShape;19private readonly _markerListener: IDisposable;2021private static ExtHostCounter: number = 1;22private readonly extHostId: string;2324constructor(25extHostContext: IExtHostContext,26@IMarkerService private readonly _markerService: IMarkerService,27@IUriIdentityService private readonly _uriIdentService: IUriIdentityService,28) {29this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostDiagnostics);3031this._markerListener = this._markerService.onMarkerChanged(this._forwardMarkers, this);32this.extHostId = `extHost${MainThreadDiagnostics.ExtHostCounter++}`;33}3435dispose(): void {36this._markerListener.dispose();37for (const owner of this._activeOwners) {38const markersData: ResourceMap<IMarker[]> = new ResourceMap<IMarker[]>();39for (const marker of this._markerService.read({ owner })) {40let data = markersData.get(marker.resource);41if (data === undefined) {42data = [];43markersData.set(marker.resource, data);44}45if (marker.origin !== this.extHostId) {46data.push(marker);47}48}49for (const [resource, local] of markersData.entries()) {50this._markerService.changeOne(owner, resource, local);51}52}53this._activeOwners.clear();54}5556private _forwardMarkers(resources: readonly URI[]): void {57const data: [UriComponents, IMarkerData[]][] = [];58for (const resource of resources) {59const allMarkerData = this._markerService.read({ resource, ignoreResourceFilters: true });60if (allMarkerData.length === 0) {61data.push([resource, []]);62} else {63const foreignMarkerData = allMarkerData.filter(marker => marker?.origin !== this.extHostId);64if (foreignMarkerData.length > 0) {65data.push([resource, foreignMarkerData]);66}67}68}69if (data.length > 0) {70this._proxy.$acceptMarkersChange(data);71}72}7374$changeMany(owner: string, entries: [UriComponents, IMarkerData[]][]): void {75for (const entry of entries) {76const [uri, markers] = entry;77if (markers) {78for (const marker of markers) {79if (marker.relatedInformation) {80for (const relatedInformation of marker.relatedInformation) {81relatedInformation.resource = URI.revive(relatedInformation.resource);82}83}84if (marker.code && typeof marker.code !== 'string') {85marker.code.target = URI.revive(marker.code.target);86}87if (marker.origin === undefined) {88marker.origin = this.extHostId;89}90}91}92this._markerService.changeOne(owner, this._uriIdentService.asCanonicalUri(URI.revive(uri)), markers);93}94this._activeOwners.add(owner);95}9697$clear(owner: string): void {98this._markerService.changeAll(owner, []);99this._activeOwners.delete(owner);100}101}102103104