Skip to content

Commit

Permalink
Fix in master #56317
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Aug 16, 2018
1 parent 7dfd49f commit 247d764
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
18 changes: 10 additions & 8 deletions src/vs/workbench/parts/markers/electron-browser/markersModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import { groupBy, isFalsyOrEmpty, flatten } from 'vs/base/common/arrays';
import { values } from 'vs/base/common/map';
import * as glob from 'vs/base/common/glob';
import * as strings from 'vs/base/common/strings';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { CodeAction } from 'vs/editor/common/modes';
import { getCodeActions } from 'vs/editor/contrib/codeAction/codeAction';
import { CodeActionKind } from 'vs/editor/contrib/codeAction/codeActionTrigger';
import { IModelService } from 'vs/editor/common/services/modelService';

function compareUris(a: URI, b: URI) {
if (a.toString() < b.toString()) {
Expand Down Expand Up @@ -48,7 +48,7 @@ export class ResourceMarkers extends NodeWithId {

constructor(
readonly uri: URI,
private textModelService: ITextModelService
private modelService: IModelService
) {
super(uri.toString());
}
Expand All @@ -72,6 +72,10 @@ export class ResourceMarkers extends NodeWithId {
}

public async hasFixes(marker: Marker): Promise<boolean> {
if (!this.modelService.getModel(this.uri)) {
// Return early, If the model is not yet created
return false;
}
if (!this._allFixesPromise) {
this._allFixesPromise = this._getFixes();
}
Expand All @@ -88,11 +92,9 @@ export class ResourceMarkers extends NodeWithId {
}

private async _getFixes(range?: Range): Promise<CodeAction[]> {
const modelReference = await this.textModelService.createModelReference(this.uri);
if (modelReference) {
const model = modelReference.object.textEditorModel;
const model = this.modelService.getModel(this.uri);
if (model) {
const codeActions = await getCodeActions(model, range ? range : model.getFullModelRange(), { type: 'manual', filter: { kind: CodeActionKind.QuickFix } });
modelReference.dispose();
return codeActions;
}
return [];
Expand Down Expand Up @@ -225,7 +227,7 @@ export class MarkersModel {

constructor(
markers: IMarker[] = [],
@ITextModelService private textModelService: ITextModelService
@IModelService private modelService: IModelService
) {
this._markersByResource = new Map<string, ResourceMarkers>();
this._filterOptions = new FilterOptions();
Expand Down Expand Up @@ -311,7 +313,7 @@ export class MarkersModel {
private createResource(uri: URI, rawMarkers: IMarker[]): ResourceMarkers {

const markers: Marker[] = [];
const resource = new ResourceMarkers(uri, this.textModelService);
const resource = new ResourceMarkers(uri, this.modelService);
this.updateResource(resource);

rawMarkers.forEach((rawMarker, index) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
import { attachInputBoxStyler, attachStylerCallback, attachCheckboxStyler } from 'vs/platform/theme/common/styler';
import { IMarkersWorkbenchService } from 'vs/workbench/parts/markers/electron-browser/markers';
import { Event, Emitter } from 'vs/base/common/event';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { BaseActionItem, ActionItem } from 'vs/base/browser/ui/actionbar/actionbar';
import { badgeBackground, contrastBorder } from 'vs/platform/theme/common/colorRegistry';
import { localize } from 'vs/nls';
Expand All @@ -35,6 +35,8 @@ import { applyCodeAction } from 'vs/editor/contrib/codeAction/codeActionCommands
import { IBulkEditService } from 'vs/editor/browser/services/bulkEditService';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IEditorService, ACTIVE_GROUP } from 'vs/workbench/services/editor/common/editorService';
import { IModelService } from 'vs/editor/common/services/modelService';
import { isEqual, hasToIgnoreCase } from 'vs/base/common/resources';

export class ToggleMarkersPanelAction extends TogglePanelAction {

Expand Down Expand Up @@ -280,14 +282,34 @@ export class QuickFixAction extends Action {

public static readonly ID: string = 'workbench.actions.problems.quickfix';

private updated: boolean = false;
private disposables: IDisposable[] = [];

constructor(
readonly marker: Marker,
@IBulkEditService private bulkEditService: IBulkEditService,
@ICommandService private commandService: ICommandService,
@IEditorService private editorService: IEditorService
@IEditorService private editorService: IEditorService,
@IModelService modelService: IModelService
) {
super(QuickFixAction.ID, Messages.MARKERS_PANEL_ACTION_TOOLTIP_QUICKFIX, 'markers-panel-action-quickfix', false);
marker.resourceMarkers.hasFixes(marker).then(hasFixes => this.enabled = hasFixes);
if (modelService.getModel(this.marker.resourceMarkers.uri)) {
this.update();
} else {
modelService.onModelAdded(model => {
if (isEqual(model.uri, marker.resource, hasToIgnoreCase(model.uri))) {
this.update();
}
}, this, this.disposables);
}

}

private update(): void {
if (!this.updated) {
this.marker.resourceMarkers.hasFixes(this.marker).then(hasFixes => this.enabled = hasFixes);
this.updated = true;
}
}

async getQuickFixActions(): Promise<IAction[]> {
Expand Down Expand Up @@ -315,6 +337,11 @@ export class QuickFixAction extends Action {
},
}, ACTIVE_GROUP).then(() => null);
}

dispose(): void {
dispose(this.disposables);
super.dispose();
}
}

export class QuickFixActionItem extends ActionItem {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ export class Renderer implements IRenderer {
} else if (templateId === Renderer.MARKER_TEMPLATE_ID) {
(<IMarkerTemplateData>templateData).description.dispose();
(<IMarkerTemplateData>templateData).source.dispose();
(<IMarkerTemplateData>templateData).actionBar.dispose();
} else if (templateId === Renderer.RELATED_INFO_TEMPLATE_ID) {
(<IRelatedInformationTemplateData>templateData).description.dispose();
(<IRelatedInformationTemplateData>templateData).resourceLabel.dispose();
Expand Down

0 comments on commit 247d764

Please sign in to comment.