Skip to content

Commit 2b472d1

Browse files
committed
register a marker list provider for notebooks, #96708
1 parent 337c788 commit 2b472d1

File tree

3 files changed

+72
-11
lines changed

3 files changed

+72
-11
lines changed

src/vs/editor/contrib/gotoError/markerNavigationService.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,38 @@ export class MarkerList {
2929
private readonly _onDidChange = new Emitter<void>();
3030
readonly onDidChange: Event<void> = this._onDidChange.event;
3131

32+
private readonly _resourceFilter?: (uri: URI) => boolean;
3233
private readonly _dispoables = new DisposableStore();
3334

3435
private _markers: IMarker[] = [];
3536
private _nextIdx: number = -1;
3637

3738
constructor(
38-
private readonly _scope: URI | undefined,
39+
resourceFilter: URI | ((uri: URI) => boolean) | undefined,
3940
@IMarkerService private readonly _markerService: IMarkerService,
4041
) {
42+
if (URI.isUri(resourceFilter)) {
43+
this._resourceFilter = uri => uri.toString() === resourceFilter.toString();
44+
} else if (resourceFilter) {
45+
this._resourceFilter = resourceFilter;
46+
}
47+
48+
const updateMarker = () => {
49+
this._markers = this._markerService.read({
50+
resource: URI.isUri(resourceFilter) ? resourceFilter : undefined,
51+
severities: MarkerSeverity.Error | MarkerSeverity.Warning | MarkerSeverity.Info
52+
});
53+
if (typeof resourceFilter === 'function') {
54+
this._markers = this._markers.filter(m => this._resourceFilter!(m.resource));
55+
}
56+
this._markers.sort(MarkerList._compareMarker);
57+
};
4158

42-
const filter = { resource: this._scope, severities: MarkerSeverity.Error | MarkerSeverity.Warning | MarkerSeverity.Info };
43-
this._markers = this._markerService.read(filter).sort(MarkerList._compareMarker);
59+
updateMarker();
4460

45-
this._dispoables.add(_markerService.onMarkerChanged(e => {
46-
if (!this._scope || e.some(e => e.toString() === _scope?.toString())) {
47-
this._markers = this._markerService.read(filter).sort(MarkerList._compareMarker);
61+
this._dispoables.add(_markerService.onMarkerChanged(uris => {
62+
if (!this._resourceFilter || uris.some(uri => this._resourceFilter!(uri))) {
63+
updateMarker();
4864
this._nextIdx = -1;
4965
this._onDidChange.fire();
5066
}
@@ -57,13 +73,10 @@ export class MarkerList {
5773
}
5874

5975
matches(uri: URI | undefined) {
60-
if (this._scope === uri) {
76+
if (!this._resourceFilter) {
6177
return true;
6278
}
63-
if (this._scope && uri && this._scope.toString() === uri.toString()) {
64-
return true;
65-
}
66-
return false;
79+
return uri && this._resourceFilter(uri);
6780
}
6881

6982
get selected(): MarkerCoordinate | undefined {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 { URI } from 'vs/base/common/uri';
7+
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
8+
import { Registry } from 'vs/platform/registry/common/platform';
9+
import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';
10+
import { IMarkerListProvider, MarkerList, IMarkerNavigationService } from 'vs/editor/contrib/gotoError/markerNavigationService';
11+
import { CellUri } from 'vs/workbench/contrib/notebook/common/notebookCommon';
12+
import { IMarkerService } from 'vs/platform/markers/common/markers';
13+
import { IDisposable } from 'vs/base/common/lifecycle';
14+
15+
class MarkerListProvider implements IMarkerListProvider {
16+
17+
private readonly _dispoables: IDisposable;
18+
19+
constructor(
20+
@IMarkerService private readonly _markerService: IMarkerService,
21+
@IMarkerNavigationService markerNavigation: IMarkerNavigationService,
22+
) {
23+
this._dispoables = markerNavigation.registerProvider(this);
24+
}
25+
26+
dispose() {
27+
this._dispoables.dispose();
28+
}
29+
30+
getMarkerList(resource: URI | undefined): MarkerList | undefined {
31+
if (!resource) {
32+
return undefined;
33+
}
34+
const data = CellUri.parse(resource);
35+
if (!data) {
36+
return undefined;
37+
}
38+
return new MarkerList(uri => {
39+
const otherData = CellUri.parse(uri);
40+
return otherData?.notebook.toString() === data.notebook.toString();
41+
}, this._markerService);
42+
}
43+
}
44+
45+
Registry
46+
.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench)
47+
.registerWorkbenchContribution(MarkerListProvider, LifecyclePhase.Ready);

src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import 'vs/workbench/contrib/notebook/browser/contrib/find/findController';
4444
import 'vs/workbench/contrib/notebook/browser/contrib/fold/folding';
4545
import 'vs/workbench/contrib/notebook/browser/contrib/format/formatting';
4646
import 'vs/workbench/contrib/notebook/browser/contrib/toc/tocProvider';
47+
import 'vs/workbench/contrib/notebook/browser/contrib/marker/markerProvider';
4748

4849
// Output renderers registration
4950

0 commit comments

Comments
 (0)