From 2b472d1e4aaaecdda5ca96289869f90ae82de3a1 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Mon, 11 May 2020 11:19:56 +0200 Subject: [PATCH] register a marker list provider for notebooks, #96708 --- .../gotoError/markerNavigationService.ts | 35 +++++++++----- .../browser/contrib/marker/markerProvider.ts | 47 +++++++++++++++++++ .../notebook/browser/notebook.contribution.ts | 1 + 3 files changed, 72 insertions(+), 11 deletions(-) create mode 100644 src/vs/workbench/contrib/notebook/browser/contrib/marker/markerProvider.ts diff --git a/src/vs/editor/contrib/gotoError/markerNavigationService.ts b/src/vs/editor/contrib/gotoError/markerNavigationService.ts index 57869dc4f69..11cac8ecd7a 100644 --- a/src/vs/editor/contrib/gotoError/markerNavigationService.ts +++ b/src/vs/editor/contrib/gotoError/markerNavigationService.ts @@ -29,22 +29,38 @@ export class MarkerList { private readonly _onDidChange = new Emitter(); readonly onDidChange: Event = this._onDidChange.event; + private readonly _resourceFilter?: (uri: URI) => boolean; private readonly _dispoables = new DisposableStore(); private _markers: IMarker[] = []; private _nextIdx: number = -1; constructor( - private readonly _scope: URI | undefined, + resourceFilter: URI | ((uri: URI) => boolean) | undefined, @IMarkerService private readonly _markerService: IMarkerService, ) { + if (URI.isUri(resourceFilter)) { + this._resourceFilter = uri => uri.toString() === resourceFilter.toString(); + } else if (resourceFilter) { + this._resourceFilter = resourceFilter; + } + + const updateMarker = () => { + this._markers = this._markerService.read({ + resource: URI.isUri(resourceFilter) ? resourceFilter : undefined, + severities: MarkerSeverity.Error | MarkerSeverity.Warning | MarkerSeverity.Info + }); + if (typeof resourceFilter === 'function') { + this._markers = this._markers.filter(m => this._resourceFilter!(m.resource)); + } + this._markers.sort(MarkerList._compareMarker); + }; - const filter = { resource: this._scope, severities: MarkerSeverity.Error | MarkerSeverity.Warning | MarkerSeverity.Info }; - this._markers = this._markerService.read(filter).sort(MarkerList._compareMarker); + updateMarker(); - this._dispoables.add(_markerService.onMarkerChanged(e => { - if (!this._scope || e.some(e => e.toString() === _scope?.toString())) { - this._markers = this._markerService.read(filter).sort(MarkerList._compareMarker); + this._dispoables.add(_markerService.onMarkerChanged(uris => { + if (!this._resourceFilter || uris.some(uri => this._resourceFilter!(uri))) { + updateMarker(); this._nextIdx = -1; this._onDidChange.fire(); } @@ -57,13 +73,10 @@ export class MarkerList { } matches(uri: URI | undefined) { - if (this._scope === uri) { + if (!this._resourceFilter) { return true; } - if (this._scope && uri && this._scope.toString() === uri.toString()) { - return true; - } - return false; + return uri && this._resourceFilter(uri); } get selected(): MarkerCoordinate | undefined { diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/marker/markerProvider.ts b/src/vs/workbench/contrib/notebook/browser/contrib/marker/markerProvider.ts new file mode 100644 index 00000000000..6d7d9c8a64f --- /dev/null +++ b/src/vs/workbench/contrib/notebook/browser/contrib/marker/markerProvider.ts @@ -0,0 +1,47 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { URI } from 'vs/base/common/uri'; +import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle'; +import { Registry } from 'vs/platform/registry/common/platform'; +import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions'; +import { IMarkerListProvider, MarkerList, IMarkerNavigationService } from 'vs/editor/contrib/gotoError/markerNavigationService'; +import { CellUri } from 'vs/workbench/contrib/notebook/common/notebookCommon'; +import { IMarkerService } from 'vs/platform/markers/common/markers'; +import { IDisposable } from 'vs/base/common/lifecycle'; + +class MarkerListProvider implements IMarkerListProvider { + + private readonly _dispoables: IDisposable; + + constructor( + @IMarkerService private readonly _markerService: IMarkerService, + @IMarkerNavigationService markerNavigation: IMarkerNavigationService, + ) { + this._dispoables = markerNavigation.registerProvider(this); + } + + dispose() { + this._dispoables.dispose(); + } + + getMarkerList(resource: URI | undefined): MarkerList | undefined { + if (!resource) { + return undefined; + } + const data = CellUri.parse(resource); + if (!data) { + return undefined; + } + return new MarkerList(uri => { + const otherData = CellUri.parse(uri); + return otherData?.notebook.toString() === data.notebook.toString(); + }, this._markerService); + } +} + +Registry + .as(WorkbenchExtensions.Workbench) + .registerWorkbenchContribution(MarkerListProvider, LifecyclePhase.Ready); diff --git a/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts b/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts index a726ac0d66a..eb035c05aca 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts @@ -44,6 +44,7 @@ import 'vs/workbench/contrib/notebook/browser/contrib/find/findController'; import 'vs/workbench/contrib/notebook/browser/contrib/fold/folding'; import 'vs/workbench/contrib/notebook/browser/contrib/format/formatting'; import 'vs/workbench/contrib/notebook/browser/contrib/toc/tocProvider'; +import 'vs/workbench/contrib/notebook/browser/contrib/marker/markerProvider'; // Output renderers registration -- GitLab