Fix in master #56317

This commit is contained in:
Sandeep Somavarapu 2018-08-16 12:03:12 +02:00
parent b00ab5288f
commit 130a2918c2
3 changed files with 41 additions and 11 deletions

View file

@ -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()) {
@ -48,7 +48,7 @@ export class ResourceMarkers extends NodeWithId {
constructor(
readonly uri: URI,
private textModelService: ITextModelService
private modelService: IModelService
) {
super(uri.toString());
}
@ -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();
}
@ -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 [];
@ -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();
@ -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) => {

View file

@ -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';
@ -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 {
@ -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[]> {
@ -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 {

View file

@ -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();