提交 dce7b0cd 编写于 作者: J Johannes Rieken

simplify outline model again

上级 1e5b337c
......@@ -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() : [];
}
......
......@@ -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<IMarkerDecorationsService>('markerDecorationsService');
......@@ -16,7 +17,7 @@ export interface IMarkerDecorationsService {
onDidChangeMarker: Event<ITextModel>;
getMarker(model: ITextModel, decoration: IModelDecoration): IMarker | null;
getMarker(uri: URI, decoration: IModelDecoration): IMarker | null;
getLiveMarkers(model: ITextModel): [Range, IMarker][];
getLiveMarkers(uri: URI): [Range, IMarker][];
}
......@@ -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<OutlineModel> {
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<string, OutlineGroup>();
children = new Map<string, OutlineGroup | OutlineElement>();
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) {
......
......@@ -75,7 +75,7 @@ export class MarkerHoverParticipant implements IEditorHoverParticipant<MarkerHov
const startColumn = (d.range.startLineNumber === lineNumber) ? d.range.startColumn : 1;
const endColumn = (d.range.endLineNumber === lineNumber) ? d.range.endColumn : maxColumn;
const marker = this._markerDecorationsService.getMarker(model, d);
const marker = this._markerDecorationsService.getMarker(model.uri, d);
if (!marker) {
continue;
}
......
......@@ -33,6 +33,7 @@ import { localize } from 'vs/nls';
import { OutlineConfigKeys } from 'vs/editor/contrib/documentSymbols/outline';
import { IMarkerDecorationsService } from 'vs/editor/common/services/markersDecorationService';
import { MarkerSeverity } from 'vs/platform/markers/common/markers';
import { isEqual } from 'vs/base/common/resources';
type DocumentSymbolItem = OutlineGroup | OutlineElement;
......@@ -232,7 +233,7 @@ class DocumentSymbolsOutline implements IOutline<DocumentSymbolItem> {
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<DocumentSymbolItem> {
// 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<DocumentSymbolItem> {
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 });
}
......
......@@ -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<DocumentSymbolItem> {
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);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册