Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement filtering by marker type #83797

Merged
merged 8 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions src/vs/workbench/contrib/markers/browser/markersFilterOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import Messages from 'vs/workbench/contrib/markers/browser/messages';
import { IFilter, matchesPrefix, matchesFuzzy, matchesFuzzy2 } from 'vs/base/common/filters';
import { IFilter, matchesFuzzy, matchesFuzzy2 } from 'vs/base/common/filters';
import { IExpression, splitGlobAware, getEmptyExpression } from 'vs/base/common/glob';
import * as strings from 'vs/base/common/strings';
import { URI } from 'vs/base/common/uri';
Expand All @@ -15,15 +14,18 @@ export class FilterOptions {
static readonly _filter: IFilter = matchesFuzzy2;
static readonly _messageFilter: IFilter = matchesFuzzy;

readonly filterErrors: boolean = false;
readonly filterWarnings: boolean = false;
readonly filterInfos: boolean = false;
readonly _showWarnings: boolean = false;
readonly _showErrors: boolean = false;
readonly _showInfos: boolean = false;
readonly textFilter: string = '';
readonly excludesMatcher: ResourceGlobMatcher;
readonly includesMatcher: ResourceGlobMatcher;

constructor(readonly filter: string = '', filesExclude: { root: URI, expression: IExpression }[] | IExpression = []) {
constructor(readonly filter: string = '', filesExclude: { root: URI, expression: IExpression }[] | IExpression = [], readonly showWarnings: boolean = false, readonly showErrors: boolean = false, readonly showInfos: boolean = false) {
filter = filter.trim();
this._showWarnings = showWarnings;
this._showErrors = showErrors;
this._showInfos = showInfos;

const filesExcludeByRoot = Array.isArray(filesExclude) ? filesExclude : [];
const excludesExpression: IExpression = Array.isArray(filesExclude) ? getEmptyExpression() : filesExclude;
Expand All @@ -32,9 +34,6 @@ export class FilterOptions {
if (filter) {
const filters = splitGlobAware(filter, ',').map(s => s.trim()).filter(s => !!s.length);
for (const f of filters) {
this.filterErrors = this.filterErrors || this.matches(f, Messages.MARKERS_PANEL_FILTER_ERRORS);
this.filterWarnings = this.filterWarnings || this.matches(f, Messages.MARKERS_PANEL_FILTER_WARNINGS);
this.filterInfos = this.filterInfos || this.matches(f, Messages.MARKERS_PANEL_FILTER_INFOS);
if (strings.startsWith(f, '!')) {
this.setPattern(excludesExpression, strings.ltrim(f, '!'));
} else {
Expand All @@ -56,9 +55,4 @@ export class FilterOptions {
expression[`**/${pattern}/**`] = true;
expression[`**/${pattern}`] = true;
}

private matches(prefix: string, word: string): boolean {
const result = matchesPrefix(prefix, word);
return !!(result && result.length > 0);
}
}
4 changes: 2 additions & 2 deletions src/vs/workbench/contrib/markers/browser/markersPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export class MarkersPanel extends Panel implements IMarkerFilterController {

private updateFilter() {
this.cachedFilterStats = undefined;
this.filter.options = new FilterOptions(this.filterAction.filterText, this.getFilesExcludeExpressions());
this.filter.options = new FilterOptions(this.filterAction.filterText, this.getFilesExcludeExpressions(), this.filterAction.showWarnings, this.filterAction.showErrors, this.filterAction.showInfos);
this.tree.refilter();
this._onDidFilter.fire();

Expand Down Expand Up @@ -420,7 +420,7 @@ 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) {
if (event.filterText || event.useFilesExclude || event.showWarnings || event.showErrors || event.showInfos) {
this.updateFilter();
}
}));
Expand Down
108 changes: 105 additions & 3 deletions src/vs/workbench/contrib/markers/browser/markersPanelActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ export class ShowProblemsPanelAction extends Action {
export interface IMarkersFilterActionChangeEvent extends IActionChangeEvent {
filterText?: boolean;
useFilesExclude?: boolean;
showWarnings?: boolean;
showErrors?: boolean;
showInfos?: boolean;
}

export interface IMarkersFilterActionOptions {
Expand Down Expand Up @@ -111,6 +114,39 @@ export class MarkersFilterAction extends Action {
}
}

private _showWarnings: boolean = true;
get showWarnings(): boolean {
return this._showWarnings;
}
set showWarnings(showWarnings: boolean) {
if (this._showWarnings !== showWarnings) {
this._showWarnings = showWarnings;
this._onDidChange.fire(<IMarkersFilterActionChangeEvent>{ showWarnings: true });
}
}

private _showErrors: boolean = true;
get showErrors(): boolean {
return this._showErrors;
}
set showErrors(showErrors: boolean) {
if (this._showErrors !== showErrors) {
this._showErrors = showErrors;
this._onDidChange.fire(<IMarkersFilterActionChangeEvent>{ showErrors: true });
}
}

private _showInfos: boolean = true;
get showInfos(): boolean {
return this._showInfos;
}
set showInfos(showInfos: boolean) {
if (this._showInfos !== showInfos) {
this._showInfos = showInfos;
this._onDidChange.fire(<IMarkersFilterActionChangeEvent>{ showInfos: true });
}
}

focus(): void {
this._onFocus.fire();
}
Expand Down Expand Up @@ -203,6 +239,9 @@ export class MarkersFilterActionViewItem extends BaseActionViewItem {
const controlsContainer = DOM.append(container, DOM.$('.markers-panel-filter-controls'));
this.createBadge(controlsContainer);
this.createFilesExcludeCheckbox(controlsContainer);
this.createErrorsCheckbox(controlsContainer);
this.createWarningsCheckbox(controlsContainer);
this.createInfosCheckbox(controlsContainer);
}

private createBadge(container: HTMLElement): void {
Expand Down Expand Up @@ -244,6 +283,69 @@ export class MarkersFilterActionViewItem extends BaseActionViewItem {
container.appendChild(filesExcludeFilter.domNode);
}

private createWarningsCheckbox(container: HTMLElement): void {
const warningsFilter = this._register(new Checkbox({
actionClassName: 'codicon codicon-warning',
title: this.action.showWarnings ? Messages.MARKERS_PANEL_ACTION_TOOLTIP_DO_NOT_SHOW_WARNINGS : Messages.MARKERS_PANEL_ACTION_TOOLTIP_SHOW_WARNINGS,
isChecked: this.action.showWarnings
}));
this._register(warningsFilter.onChange(() => {
warningsFilter.domNode.title = warningsFilter.checked ? Messages.MARKERS_PANEL_ACTION_TOOLTIP_DO_NOT_SHOW_WARNINGS : Messages.MARKERS_PANEL_ACTION_TOOLTIP_SHOW_WARNINGS;
this.action.showWarnings = warningsFilter.checked;
this.focus();
}));
this._register(this.action.onDidChange((event: IMarkersFilterActionChangeEvent) => {
if (event.showWarnings) {
warningsFilter.checked = this.action.showWarnings;
}
}));

this._register(attachCheckboxStyler(warningsFilter, this.themeService));
container.appendChild(warningsFilter.domNode);
}

private createErrorsCheckbox(container: HTMLElement): void {
const errorsFilter = this._register(new Checkbox({
actionClassName: 'codicon codicon-error',
title: this.action.showErrors ? Messages.MARKERS_PANEL_ACTION_TOOLTIP_DO_NOT_SHOW_ERRORS : Messages.MARKERS_PANEL_ACTION_TOOLTIP_SHOW_ERRORS,
isChecked: this.action.showErrors
}));
this._register(errorsFilter.onChange(() => {
errorsFilter.domNode.title = errorsFilter.checked ? Messages.MARKERS_PANEL_ACTION_TOOLTIP_DO_NOT_SHOW_ERRORS : Messages.MARKERS_PANEL_ACTION_TOOLTIP_SHOW_ERRORS;
this.action.showErrors = errorsFilter.checked;
this.focus();
}));
this._register(this.action.onDidChange((event: IMarkersFilterActionChangeEvent) => {
if (event.showErrors) {
errorsFilter.checked = this.action.showErrors;
}
}));

this._register(attachCheckboxStyler(errorsFilter, this.themeService));
container.appendChild(errorsFilter.domNode);
}

private createInfosCheckbox(container: HTMLElement): void {
const infosFilter = this._register(new Checkbox({
actionClassName: 'codicon codicon-info',
title: this.action.showInfos ? Messages.MARKERS_PANEL_ACTION_TOOLTIP_DO_NOT_SHOW_INFOS : Messages.MARKERS_PANEL_ACTION_TOOLTIP_SHOW_INFOS,
isChecked: this.action.showInfos
}));
this._register(infosFilter.onChange(() => {
infosFilter.domNode.title = infosFilter.checked ? Messages.MARKERS_PANEL_ACTION_TOOLTIP_DO_NOT_SHOW_INFOS : Messages.MARKERS_PANEL_ACTION_TOOLTIP_SHOW_INFOS;
this.action.showInfos = infosFilter.checked;
this.focus();
}));
this._register(this.action.onDidChange((event: IMarkersFilterActionChangeEvent) => {
if (event.showInfos) {
infosFilter.checked = this.action.showInfos;
}
}));

this._register(attachCheckboxStyler(infosFilter, this.themeService));
container.appendChild(infosFilter.domNode);
}

private onDidInputChange(inputbox: HistoryInputBox) {
inputbox.addToHistory();
this.action.filterText = inputbox.value;
Expand Down Expand Up @@ -292,9 +394,9 @@ export class MarkersFilterActionViewItem extends BaseActionViewItem {
private reportFilteringUsed(): void {
const filterOptions = this.filterController.getFilterOptions();
const data = {
errors: filterOptions.filterErrors,
warnings: filterOptions.filterWarnings,
infos: filterOptions.filterInfos,
errors: filterOptions._showErrors,
warnings: filterOptions._showWarnings,
infos: filterOptions._showInfos,
};
/* __GDPR__
"problems.filter" : {
Expand Down
17 changes: 11 additions & 6 deletions src/vs/workbench/contrib/markers/browser/markersTreeViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,16 +425,21 @@ export class Filter implements ITreeFilter<TreeElement, FilterData> {
}

private filterMarker(marker: Marker, parentVisibility: TreeVisibility): TreeFilterResult<FilterData> {
if (this.options.filterErrors && MarkerSeverity.Error === marker.marker.severity) {
return true;
let shouldAppear: boolean = false;
if (this.options._showErrors && MarkerSeverity.Error === marker.marker.severity) {
shouldAppear = true;
}

if (this.options.filterWarnings && MarkerSeverity.Warning === marker.marker.severity) {
return true;
if (this.options._showWarnings && MarkerSeverity.Warning === marker.marker.severity) {
shouldAppear = true;
}

if (this.options.filterInfos && MarkerSeverity.Info === marker.marker.severity) {
return true;
if (this.options._showInfos && MarkerSeverity.Info === marker.marker.severity) {
shouldAppear = true;
}

if (!shouldAppear) {
return false;
}

if (!this.options.textFilter) {
Expand Down
6 changes: 6 additions & 0 deletions src/vs/workbench/contrib/markers/browser/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export default class Messages {

public static MARKERS_PANEL_ACTION_TOOLTIP_USE_FILES_EXCLUDE: string = nls.localize('markers.panel.action.useFilesExclude', "Filter using Files Exclude Setting");
public static MARKERS_PANEL_ACTION_TOOLTIP_DO_NOT_USE_FILES_EXCLUDE: string = nls.localize('markers.panel.action.donotUseFilesExclude', "Do not use Files Exclude Setting");
public static MARKERS_PANEL_ACTION_TOOLTIP_DO_NOT_SHOW_WARNINGS: string = nls.localize('markers.panel.action.donotShowWarnings', "Do not show warnings");
public static MARKERS_PANEL_ACTION_TOOLTIP_SHOW_WARNINGS: string = nls.localize('markers.panel.action.showWarnings', "Show warnings");
public static MARKERS_PANEL_ACTION_TOOLTIP_DO_NOT_SHOW_ERRORS: string = nls.localize('markers.panel.action.donotShowErrors', "Do not show errors");
public static MARKERS_PANEL_ACTION_TOOLTIP_SHOW_ERRORS: string = nls.localize('markers.panel.action.showErrors', "Show errors");
public static MARKERS_PANEL_ACTION_TOOLTIP_DO_NOT_SHOW_INFOS: string = nls.localize('markers.panel.action.donotShowInfos', "Do not show infos");
public static MARKERS_PANEL_ACTION_TOOLTIP_SHOW_INFOS: string = nls.localize('markers.panel.action.showInfos', "Show infos");
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");
Expand Down