From dce7b0cd63b1451450f5495bd62dcc915eaba8ef Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Mon, 4 Jan 2021 11:24:39 +0100 Subject: [PATCH] simplify outline model again --- .../common/services/markerDecorationsServiceImpl.ts | 8 ++++---- .../editor/common/services/markersDecorationService.ts | 5 +++-- src/vs/editor/contrib/documentSymbols/outlineModel.ts | 9 +++++---- src/vs/editor/contrib/hover/markerHoverParticipant.ts | 2 +- .../browser/outline/documentSymbolsOutline.ts | 7 ++++--- .../codeEditor/browser/outline/documentSymbolsTree.ts | 10 +--------- 6 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/vs/editor/common/services/markerDecorationsServiceImpl.ts b/src/vs/editor/common/services/markerDecorationsServiceImpl.ts index eb2d6795d48..a80302ddbcc 100644 --- a/src/vs/editor/common/services/markerDecorationsServiceImpl.ts +++ b/src/vs/editor/common/services/markerDecorationsServiceImpl.ts @@ -87,13 +87,13 @@ export class MarkerDecorationsService extends Disposable implements IMarkerDecor this._markerDecorations.clear(); } - getMarker(model: ITextModel, decoration: IModelDecoration): IMarker | null { - const markerDecorations = this._markerDecorations.get(MODEL_ID(model.uri)); + getMarker(uri: URI, decoration: IModelDecoration): IMarker | null { + const markerDecorations = this._markerDecorations.get(MODEL_ID(uri)); return markerDecorations ? (markerDecorations.getMarker(decoration) || null) : null; } - getLiveMarkers(model: ITextModel): [Range, IMarker][] { - const markerDecorations = this._markerDecorations.get(MODEL_ID(model.uri)); + getLiveMarkers(uri: URI): [Range, IMarker][] { + const markerDecorations = this._markerDecorations.get(MODEL_ID(uri)); return markerDecorations ? markerDecorations.getMarkers() : []; } diff --git a/src/vs/editor/common/services/markersDecorationService.ts b/src/vs/editor/common/services/markersDecorationService.ts index 745260c8884..221f72379b3 100644 --- a/src/vs/editor/common/services/markersDecorationService.ts +++ b/src/vs/editor/common/services/markersDecorationService.ts @@ -8,6 +8,7 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation' import { IMarker } from 'vs/platform/markers/common/markers'; import { Event } from 'vs/base/common/event'; import { Range } from 'vs/editor/common/core/range'; +import { URI } from 'vs/base/common/uri'; export const IMarkerDecorationsService = createDecorator('markerDecorationsService'); @@ -16,7 +17,7 @@ export interface IMarkerDecorationsService { onDidChangeMarker: Event; - getMarker(model: ITextModel, decoration: IModelDecoration): IMarker | null; + getMarker(uri: URI, decoration: IModelDecoration): IMarker | null; - getLiveMarkers(model: ITextModel): [Range, IMarker][]; + getLiveMarkers(uri: URI): [Range, IMarker][]; } diff --git a/src/vs/editor/contrib/documentSymbols/outlineModel.ts b/src/vs/editor/contrib/documentSymbols/outlineModel.ts index b904bd37ecc..5638223f9b3 100644 --- a/src/vs/editor/contrib/documentSymbols/outlineModel.ts +++ b/src/vs/editor/contrib/documentSymbols/outlineModel.ts @@ -15,6 +15,7 @@ import { DocumentSymbol, DocumentSymbolProvider, DocumentSymbolProviderRegistry import { MarkerSeverity } from 'vs/platform/markers/common/markers'; import { Iterable } from 'vs/base/common/iterator'; import { LanguageFeatureRequestDelays } from 'vs/editor/common/modes/languageFeatureRegistry'; +import { URI } from 'vs/base/common/uri'; export abstract class TreeElement { @@ -287,7 +288,7 @@ export class OutlineModel extends TreeElement { private static _create(textModel: ITextModel, token: CancellationToken): Promise { const cts = new CancellationTokenSource(token); - const result = new OutlineModel(textModel); + const result = new OutlineModel(textModel.uri); const provider = DocumentSymbolProviderRegistry.ordered(textModel); const promises = provider.map((provider, index) => { @@ -356,7 +357,7 @@ export class OutlineModel extends TreeElement { protected _groups = new Map(); children = new Map(); - protected constructor(readonly textModel: ITextModel) { + protected constructor(readonly uri: URI) { super(); this.id = 'root'; @@ -364,7 +365,7 @@ export class OutlineModel extends TreeElement { } adopt(): OutlineModel { - let res = new OutlineModel(this.textModel); + let res = new OutlineModel(this.uri); for (const [key, value] of this._groups) { res._groups.set(key, value.adopt(res)); } @@ -395,7 +396,7 @@ export class OutlineModel extends TreeElement { } merge(other: OutlineModel): boolean { - if (this.textModel.uri.toString() !== other.textModel.uri.toString()) { + if (this.uri.toString() !== other.uri.toString()) { return false; } if (this._groups.size !== other._groups.size) { diff --git a/src/vs/editor/contrib/hover/markerHoverParticipant.ts b/src/vs/editor/contrib/hover/markerHoverParticipant.ts index 25beefaa53e..ad739c89225 100644 --- a/src/vs/editor/contrib/hover/markerHoverParticipant.ts +++ b/src/vs/editor/contrib/hover/markerHoverParticipant.ts @@ -75,7 +75,7 @@ export class MarkerHoverParticipant implements IEditorHoverParticipant { return; } await this._codeEditorService.openCodeEditor({ - resource: model.textModel.uri, + resource: model.uri, options: { ...options, selection: Range.collapseToStart(entry.symbol.selectionRange), @@ -327,7 +328,7 @@ class DocumentSymbolsOutline implements IOutline { // feature: show markers with outline element this._applyMarkersToOutline(model); this._outlineDisposables.add(this._markerDecorationsService.onDidChangeMarker(textModel => { - if (model?.textModel === textModel) { + if (isEqual(model.uri, textModel.uri)) { this._applyMarkersToOutline(model); this._onDidChange.fire({}); } @@ -386,7 +387,7 @@ class DocumentSymbolsOutline implements IOutline { return; } const markers: IOutlineMarker[] = []; - for (const [range, marker] of this._markerDecorationsService.getLiveMarkers(model.textModel)) { + for (const [range, marker] of this._markerDecorationsService.getLiveMarkers(model.uri)) { if (marker.severity === MarkerSeverity.Error || marker.severity === MarkerSeverity.Warning) { markers.push({ ...range, severity: marker.severity }); } diff --git a/src/vs/workbench/contrib/codeEditor/browser/outline/documentSymbolsTree.ts b/src/vs/workbench/contrib/codeEditor/browser/outline/documentSymbolsTree.ts index bee363f791f..e35ed3ebada 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/outline/documentSymbolsTree.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/outline/documentSymbolsTree.ts @@ -21,7 +21,6 @@ import { IThemeService, registerThemingParticipant, IColorTheme, ICssStyleCollec import { registerColor, listErrorForeground, listWarningForeground, foreground } from 'vs/platform/theme/common/colorRegistry'; import { IdleValue } from 'vs/base/common/async'; import { ITextResourceConfigurationService } from 'vs/editor/common/services/textResourceConfigurationService'; -import { URI } from 'vs/base/common/uri'; import { IListAccessibilityProvider } from 'vs/base/browser/ui/list/listWidget'; import { Codicon } from 'vs/base/common/codicons'; import { IOutlineComparator } from 'vs/workbench/services/outline/browser/outline'; @@ -267,19 +266,12 @@ export class DocumentSymbolFilter implements ITreeFilter { filter(element: DocumentSymbolItem): boolean { const outline = OutlineModel.get(element); - let uri: URI | undefined; - - if (outline) { - uri = outline.textModel.uri; - } - if (!(element instanceof OutlineElement)) { return true; } - const configName = DocumentSymbolFilter.kindToConfigName[element.symbol.kind]; const configKey = `${this._prefix}.${configName}`; - return this._textResourceConfigService.getValue(uri, configKey); + return this._textResourceConfigService.getValue(outline?.uri, configKey); } } -- GitLab