This commit is contained in:
Sandeep Somavarapu 2019-11-07 23:16:26 +01:00
parent dfbab75674
commit 60e8e7c39b
4 changed files with 89 additions and 42 deletions

View file

@ -117,6 +117,11 @@ export class MarkersModel {
this.resourcesByUri = new Map<string, ResourceMarkers>();
}
private _total: number = 0;
get total(): number {
return this._total;
}
getResourceMarkers(resource: URI): ResourceMarkers | null {
return withUndefinedAsNull(this.resourcesByUri.get(resource.toString()));
}
@ -129,6 +134,7 @@ export class MarkersModel {
if (resourceMarkers) {
this.resourcesByUri.delete(resource.toString());
change.removed.push(resourceMarkers);
this._total -= resourceMarkers.markers.length;
}
} else {
const resourceMarkersId = this.id(resource.toString());
@ -149,12 +155,14 @@ export class MarkersModel {
}), compareMarkers);
if (resourceMarkers) {
this._total -= resourceMarkers.markers.length;
resourceMarkers.markers = markers;
change.updated.push(resourceMarkers);
} else {
resourceMarkers = new ResourceMarkers(resourceMarkersId, resource, markers);
change.added.push(resourceMarkers);
}
this._total += resourceMarkers.markers.length;
this.resourcesByUri.set(resource.toString(), resourceMarkers);
}
}

View file

@ -12,7 +12,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { Panel } from 'vs/workbench/browser/panel';
import { IEditorService, SIDE_GROUP, ACTIVE_GROUP } from 'vs/workbench/services/editor/common/editorService';
import Constants from 'vs/workbench/contrib/markers/browser/constants';
import { Marker, ResourceMarkers, RelatedInformation, MarkersModel, MarkerChangesEvent } from 'vs/workbench/contrib/markers/browser/markersModel';
import { Marker, ResourceMarkers, RelatedInformation, MarkerChangesEvent } from 'vs/workbench/contrib/markers/browser/markersModel';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { MarkersFilterActionViewItem, MarkersFilterAction, IMarkersFilterActionChangeEvent, IMarkerFilterController } from 'vs/workbench/contrib/markers/browser/markersPanelActions';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
@ -47,12 +47,6 @@ import { IListVirtualDelegate } from 'vs/base/browser/ui/list/list';
import { IObjectTreeOptions } from 'vs/base/browser/ui/tree/objectTree';
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
function createModelIterator(model: MarkersModel): Iterator<ITreeElement<TreeElement>> {
const resourcesIt = Iterator.fromArray(model.resourceMarkers);
return Iterator.map(resourcesIt, m => ({ element: m, children: createResourceMarkersIterator(m) }));
}
function createResourceMarkersIterator(resourceMarkers: ResourceMarkers): Iterator<ITreeElement<TreeElement>> {
const markersIt = Iterator.fromArray(resourceMarkers.markers);
@ -124,7 +118,8 @@ export class MarkersPanel extends Panel implements IMarkerFilterController {
showErrors: this.panelState['showErrors'] !== false,
showWarnings: this.panelState['showWarnings'] !== false,
showInfos: this.panelState['showInfos'] !== false,
useFilesExclude: !!this.panelState['useFilesExclude']
excludedFiles: !!this.panelState['useFilesExclude'],
activeFile: !!this.panelState['activeFile']
}));
}
@ -254,7 +249,7 @@ export class MarkersPanel extends Panel implements IMarkerFilterController {
} else {
if (markerOrChange.added.length || markerOrChange.removed.length) {
// Reset complete tree
this.tree.setChildren(null, createModelIterator(this.markersWorkbenchService.markersModel));
this.resetTree();
} else {
// Update resource
for (const updated of markerOrChange.updated) {
@ -264,7 +259,7 @@ export class MarkersPanel extends Panel implements IMarkerFilterController {
}
} else {
// Reset complete tree
this.tree.setChildren(null, createModelIterator(this.markersWorkbenchService.markersModel));
this.resetTree();
}
const { total, filtered } = this.getFilterStats();
@ -278,6 +273,21 @@ export class MarkersPanel extends Panel implements IMarkerFilterController {
this.refreshPanel(marker);
}
private resetTree(): void {
let resourceMarkers: ResourceMarkers[] = [];
if (this.filterAction.activeFile) {
if (this.currentActiveResource) {
const activeResourceMarkers = this.markersWorkbenchService.markersModel.getResourceMarkers(this.currentActiveResource);
if (activeResourceMarkers) {
resourceMarkers = [activeResourceMarkers];
}
}
} else {
resourceMarkers = this.markersWorkbenchService.markersModel.resourceMarkers;
}
this.tree.setChildren(null, Iterator.map(Iterator.fromArray(resourceMarkers), m => ({ element: m, children: createResourceMarkersIterator(m) })));
}
private updateFilter() {
this.cachedFilterStats = undefined;
this.filter.options = new FilterOptions(this.filterAction.filterText, this.getFilesExcludeExpressions(), this.filterAction.showWarnings, this.filterAction.showErrors, this.filterAction.showInfos);
@ -290,7 +300,7 @@ export class MarkersPanel extends Panel implements IMarkerFilterController {
}
private getFilesExcludeExpressions(): { root: URI, expression: IExpression }[] | IExpression {
if (!this.filterAction.useFilesExclude) {
if (!this.filterAction.excludedFiles) {
return [];
}
@ -383,7 +393,7 @@ export class MarkersPanel extends Panel implements IMarkerFilterController {
this._register(this.tree.onContextMenu(this.onContextMenu, this));
this._register(this.configurationService.onDidChangeConfiguration(e => {
if (this.filterAction.useFilesExclude && e.affectsConfiguration('files.exclude')) {
if (this.filterAction.excludedFiles && e.affectsConfiguration('files.exclude')) {
this.updateFilter();
}
}));
@ -426,7 +436,9 @@ export class MarkersPanel extends Panel implements IMarkerFilterController {
}));
this._register(this.tree.onDidChangeSelection(() => this.onSelected()));
this._register(this.filterAction.onDidChange((event: IMarkersFilterActionChangeEvent) => {
if (event.filterText || event.useFilesExclude || event.showWarnings || event.showErrors || event.showInfos) {
if (event.activeFile) {
this.refreshPanel();
} else if (event.filterText || event.excludedFiles || event.showWarnings || event.showErrors || event.showInfos) {
this.updateFilter();
}
}));
@ -468,7 +480,11 @@ export class MarkersPanel extends Panel implements IMarkerFilterController {
private onActiveEditorChanged(): void {
this.setCurrentActiveEditor();
this.autoReveal();
if (this.filterAction.activeFile) {
this.refreshPanel();
} else {
this.autoReveal();
}
}
private setCurrentActiveEditor(): void {
@ -490,7 +506,7 @@ export class MarkersPanel extends Panel implements IMarkerFilterController {
private render(): void {
this.cachedFilterStats = undefined;
this.tree.setChildren(null, createModelIterator(this.markersWorkbenchService.markersModel));
this.resetTree();
this.tree.toggleVisibility(this.isEmpty());
this.renderMessage();
}
@ -679,20 +695,17 @@ export class MarkersPanel extends Panel implements IMarkerFilterController {
private computeFilterStats(): { total: number; filtered: number; } {
const root = this.tree.getNode();
let total = 0;
let filtered = 0;
for (const resourceMarkerNode of root.children) {
for (const markerNode of resourceMarkerNode.children) {
total++;
if (resourceMarkerNode.visible && markerNode.visible) {
filtered++;
}
}
}
return { total, filtered };
return { total: this.markersWorkbenchService.markersModel.total, filtered };
}
private getTelemetryData({ source, code }: IMarker): any {
@ -705,7 +718,8 @@ export class MarkersPanel extends Panel implements IMarkerFilterController {
this.panelState['showErrors'] = this.filterAction.showErrors;
this.panelState['showWarnings'] = this.filterAction.showWarnings;
this.panelState['showInfos'] = this.filterAction.showInfos;
this.panelState['useFilesExclude'] = this.filterAction.useFilesExclude;
this.panelState['useFilesExclude'] = this.filterAction.excludedFiles;
this.panelState['activeFile'] = this.filterAction.activeFile;
this.panelState['multiline'] = this.markersViewModel.multiline;
super.saveState();

View file

@ -63,10 +63,11 @@ export class ShowProblemsPanelAction extends Action {
export interface IMarkersFilterActionChangeEvent extends IActionChangeEvent {
filterText?: boolean;
useFilesExclude?: boolean;
excludedFiles?: boolean;
showWarnings?: boolean;
showErrors?: boolean;
showInfos?: boolean;
activeFile?: boolean;
}
export interface IMarkersFilterActionOptions {
@ -75,7 +76,8 @@ export interface IMarkersFilterActionOptions {
showErrors: boolean;
showWarnings: boolean;
showInfos: boolean;
useFilesExclude: boolean;
excludedFiles: boolean;
activeFile: boolean;
}
export class MarkersFilterAction extends Action {
@ -91,7 +93,8 @@ export class MarkersFilterAction extends Action {
this._showErrors = options.showErrors;
this._showWarnings = options.showWarnings;
this._showInfos = options.showInfos;
this._useFilesExclude = options.useFilesExclude;
this._excludedFiles = options.excludedFiles;
this._activeFile = options.activeFile;
this.filterHistory = options.filterHistory;
}
@ -108,14 +111,25 @@ export class MarkersFilterAction extends Action {
filterHistory: string[];
private _useFilesExclude: boolean;
get useFilesExclude(): boolean {
return this._useFilesExclude;
private _excludedFiles: boolean;
get excludedFiles(): boolean {
return this._excludedFiles;
}
set useFilesExclude(filesExclude: boolean) {
if (this._useFilesExclude !== filesExclude) {
this._useFilesExclude = filesExclude;
this._onDidChange.fire(<IMarkersFilterActionChangeEvent>{ useFilesExclude: true });
set excludedFiles(filesExclude: boolean) {
if (this._excludedFiles !== filesExclude) {
this._excludedFiles = filesExclude;
this._onDidChange.fire(<IMarkersFilterActionChangeEvent>{ excludedFiles: true });
}
}
private _activeFile: boolean;
get activeFile(): boolean {
return this._activeFile;
}
set activeFile(activeFile: boolean) {
if (this._activeFile !== activeFile) {
this._activeFile = activeFile;
this._onDidChange.fire(<IMarkersFilterActionChangeEvent>{ activeFile: true });
}
}
@ -201,7 +215,7 @@ class FiltersDropdownMenuActionViewItem extends DropdownMenuActionViewItem {
class: undefined,
enabled: true,
id: 'showErrors',
label: Messages.MARKERS_PANEL_ACTION_LABEL_SHOW_ERRORS,
label: Messages.MARKERS_PANEL_FILTER_LABEL_SHOW_ERRORS,
run: async () => this.filterAction.showErrors = !this.filterAction.showErrors,
tooltip: '',
dispose: () => null
@ -211,7 +225,7 @@ class FiltersDropdownMenuActionViewItem extends DropdownMenuActionViewItem {
class: undefined,
enabled: true,
id: 'showWarnings',
label: Messages.MARKERS_PANEL_ACTION_LABEL_SHOW_WARNINGS,
label: Messages.MARKERS_PANEL_FILTER_LABEL_SHOW_WARNINGS,
run: async () => this.filterAction.showWarnings = !this.filterAction.showWarnings,
tooltip: '',
dispose: () => null
@ -221,22 +235,32 @@ class FiltersDropdownMenuActionViewItem extends DropdownMenuActionViewItem {
class: undefined,
enabled: true,
id: 'showInfos',
label: Messages.MARKERS_PANEL_ACTION_LABEL_SHOW_INFOS,
label: Messages.MARKERS_PANEL_FILTER_LABEL_SHOW_INFOS,
run: async () => this.filterAction.showInfos = !this.filterAction.showInfos,
tooltip: '',
dispose: () => null
},
new Separator(),
{
checked: this.filterAction.useFilesExclude,
checked: this.filterAction.activeFile,
class: undefined,
enabled: true,
id: 'activeFile',
label: Messages.MARKERS_PANEL_FILTER_LABEL_ACTIVE_FILE,
run: async () => this.filterAction.activeFile = !this.filterAction.activeFile,
tooltip: '',
dispose: () => null
},
{
checked: this.filterAction.excludedFiles,
class: undefined,
enabled: true,
id: 'useFilesExclude',
label: Messages.MARKERS_PANEL_ACTION_LABEL_USE_FILES_EXCLUDE,
run: async () => this.filterAction.useFilesExclude = !this.filterAction.useFilesExclude,
label: Messages.MARKERS_PANEL_FILTER_LABEL_EXCLUDED_FILES,
run: async () => this.filterAction.excludedFiles = !this.filterAction.excludedFiles,
tooltip: '',
dispose: () => null
}
},
];
}
@ -293,7 +317,7 @@ export class MarkersFilterActionViewItem extends BaseActionViewItem {
}
private hasFiltersChanged(): boolean {
return !this.action.showErrors || !this.action.showWarnings || !this.action.showInfos || this.action.useFilesExclude;
return !this.action.showErrors || !this.action.showWarnings || !this.action.showInfos || this.action.excludedFiles || this.action.activeFile;
}
private createInput(container: HTMLElement): void {

View file

@ -23,10 +23,11 @@ export default class Messages {
public static MARKERS_PANEL_NO_PROBLEMS_FILTERS: string = nls.localize('markers.panel.no.problems.filters', "No results found with provided filter criteria.");
public static MARKERS_PANEL_ACTION_TOOLTIP_MORE_FILTERS: string = nls.localize('markers.panel.action.moreFilters', "More Filters...");
public static MARKERS_PANEL_ACTION_LABEL_SHOW_ERRORS: string = nls.localize('markers.panel.action.showErrors', "Errors");
public static MARKERS_PANEL_ACTION_LABEL_SHOW_WARNINGS: string = nls.localize('markers.panel.action.showWarnings', "Warnings");
public static MARKERS_PANEL_ACTION_LABEL_SHOW_INFOS: string = nls.localize('markers.panel.action.showInfos', "Infos");
public static MARKERS_PANEL_ACTION_LABEL_USE_FILES_EXCLUDE: string = nls.localize('markers.panel.action.useFilesExclude', "Use Files Exclude Setting");
public static MARKERS_PANEL_FILTER_LABEL_SHOW_ERRORS: string = nls.localize('markers.panel.filter.showErrors', "Errors");
public static MARKERS_PANEL_FILTER_LABEL_SHOW_WARNINGS: string = nls.localize('markers.panel.filter.showWarnings', "Warnings");
public static MARKERS_PANEL_FILTER_LABEL_SHOW_INFOS: string = nls.localize('markers.panel.filter.showInfos', "Infos");
public static MARKERS_PANEL_FILTER_LABEL_EXCLUDED_FILES: string = nls.localize('markers.panel.filter.useFilesExclude', "Excluded Files");
public static MARKERS_PANEL_FILTER_LABEL_ACTIVE_FILE: string = nls.localize('markers.panel.filter.activeFile', "Active File");
public static MARKERS_PANEL_ACTION_TOOLTIP_FILTER: string = nls.localize('markers.panel.action.filter', "Filter Problems");
public static MARKERS_PANEL_ACTION_TOOLTIP_QUICKFIX: string = nls.localize('markers.panel.action.quickfix', "Show fixes");
public static MARKERS_PANEL_FILTER_ARIA_LABEL: string = nls.localize('markers.panel.filter.ariaLabel', "Filter Problems");