mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-25 15:35:43 +01:00
register a marker list provider for notebooks, #96708
This commit is contained in:
@@ -29,22 +29,38 @@ export class MarkerList {
|
||||
private readonly _onDidChange = new Emitter<void>();
|
||||
readonly onDidChange: Event<void> = 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 filter = { resource: this._scope, severities: MarkerSeverity.Error | MarkerSeverity.Warning | MarkerSeverity.Info };
|
||||
this._markers = this._markerService.read(filter).sort(MarkerList._compareMarker);
|
||||
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);
|
||||
};
|
||||
|
||||
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);
|
||||
updateMarker();
|
||||
|
||||
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 {
|
||||
|
||||
@@ -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<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench)
|
||||
.registerWorkbenchContribution(MarkerListProvider, LifecyclePhase.Ready);
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user