Skip to content

Commit 797f9bf

Browse files
committed
make quick fix be a command and a score
1 parent 0f8b0d7 commit 797f9bf

15 files changed

Lines changed: 91 additions & 98 deletions

File tree

extensions/csharp-o/src/features/codeActionProvider.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,20 @@ export default class OmnisharpCodeActionProvider extends AbstractProvider implem
4747
return {
4848
title: ca.Name,
4949
command: this._commandId,
50-
arguments: [ca.Identifier, document, range]
50+
arguments: [<V2.RunCodeActionRequest>{
51+
Filename: document.fileName,
52+
Selection: OmnisharpCodeActionProvider._asRange(range),
53+
Identifier: ca.Identifier,
54+
WantsTextChanges: true
55+
}]
5156
};
5257
});
5358
}, (error) => {
5459
return Promise.reject('Problem invoking \'GetCodeActions\' on OmniSharp server: ' + error);
5560
});
5661
}
5762

58-
private _runCodeAction(id: string, document: TextDocument, range: Range): Promise<any> {
59-
60-
let req: V2.RunCodeActionRequest = {
61-
Filename: document.fileName,
62-
Selection: OmnisharpCodeActionProvider._asRange(range),
63-
Identifier: id,
64-
WantsTextChanges: true
65-
};
63+
private _runCodeAction(req: V2.RunCodeActionRequest): Promise<any> {
6664

6765
return this._server.makeRequest<V2.RunCodeActionResponse>(V2.RunCodeAction, req).then(response => {
6866

src/vs/editor/common/modes.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,8 @@ export interface ISuggestSupport {
471471
* Interface used to quick fix typing errors while accesing member fields.
472472
*/
473473
export interface IQuickFix {
474-
label: string;
475-
id: any;
474+
command: ICommand;
476475
score: number;
477-
documentation?: string;
478476
}
479477

480478
export interface IQuickFixResult {
@@ -484,7 +482,8 @@ export interface IQuickFixResult {
484482

485483
export interface IQuickFixSupport {
486484
getQuickFixes(resource: URI, range: IMarker | EditorCommon.IRange): TPromise<IQuickFix[]>;
487-
runQuickFixAction(resource: URI, range: EditorCommon.IRange, id: any):TPromise<IQuickFixResult>;
485+
//TODO@joh this should be removed in the furture such that we can trust the command and it's args
486+
runQuickFixAction(resource: URI, range: EditorCommon.IRange, quickFix: IQuickFix):TPromise<IQuickFixResult>;
488487
}
489488

490489
export interface IParameter {

src/vs/editor/contrib/gotoError/browser/gotoError.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,9 @@ class MarkerNavigationWidget extends ZoneWidget.ZoneWidget {
276276
}
277277
container.span({
278278
class: 'quickfixentry',
279-
text: fix.label
279+
text: fix.command.title
280280
}).on(DOM.EventType.CLICK,() => {
281-
mode.quickFixSupport.runQuickFixAction(this.editor.getModel().getAssociatedResource(), marker, fix.id).then(result => {
281+
mode.quickFixSupport.runQuickFixAction(this.editor.getModel().getAssociatedResource(), marker, fix).then(result => {
282282
return bulkEdit(this._eventService, this._editorService, this.editor, result.edits);
283283
});
284284
return true;

src/vs/editor/contrib/quickFix/browser/quickFix.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class QuickFixController implements EditorCommon.IEditorContribution {
7777
return;
7878
}
7979

80-
fix.support.runQuickFixAction(this.editor.getModel().getAssociatedResource(), range, fix.id).then(result => {
80+
fix.support.runQuickFixAction(this.editor.getModel().getAssociatedResource(), range, { command: fix.command, score: fix.score }).then(result => {
8181
if (result) {
8282
if (result.message) {
8383
this.messageService.show(Severity.Info, result.message);

src/vs/editor/contrib/quickFix/browser/quickFixSelectionWidget.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ import {IQuickFix2} from '../common/quickFix';
2424

2525
var $ = dom.emmet;
2626

27-
function isQuickFix(quickfix: any) : boolean {
28-
return quickfix && quickfix.id && quickfix.label;
27+
function isQuickFix(quickfix: any): quickfix is IQuickFix2 {
28+
return quickfix
29+
&& typeof (<IQuickFix2>quickfix).command === 'object'
30+
&& typeof (<IQuickFix2> quickfix).command.title === 'string';
2931
}
3032

3133
// To be used as a tree element when we want to show a message
@@ -119,9 +121,9 @@ class Controller extends TreeDefaults.DefaultController {
119121
function getHeight(tree:Tree.ITree, element:any): number {
120122
var fix = <IQuickFix2>element;
121123

122-
if (!(element instanceof Message) && !!fix.documentation && tree.isFocused(fix)) {
123-
return 35;
124-
}
124+
// if (!(element instanceof Message) && !!fix.documentation && tree.isFocused(fix)) {
125+
// return 35;
126+
// }
125127

126128
return 19;
127129
}
@@ -159,8 +161,8 @@ class Renderer implements Tree.IRenderer {
159161
}
160162

161163
var quickFix = <IQuickFix2> element;
162-
templateData.main.textContent = quickFix.label;
163-
templateData.documentationLabel.textContent = quickFix.documentation || '';
164+
templateData.main.textContent = quickFix.command.title;
165+
templateData.documentationLabel.textContent = /*quickFix.documentation ||*/ '';
164166
}
165167

166168
public disposeTemplate(tree: Tree.ITree, templateId: string, templateData: any): void {

src/vs/editor/contrib/quickFix/common/quickFix.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const QuickFixRegistry = new LanguageFeatureRegistry<IQuickFixSupport>('q
1919

2020
export interface IQuickFix2 extends IQuickFix {
2121
support: IQuickFixSupport;
22+
id: string;
2223
}
2324

2425
export function getQuickFixes(model: IModel, range: IRange): TPromise<IQuickFix2[]> {
@@ -29,12 +30,12 @@ export function getQuickFixes(model: IModel, range: IRange): TPromise<IQuickFix2
2930
if (!Array.isArray(result)) {
3031
return
3132
}
33+
let c = 0;
3234
for (let fix of result) {
3335
quickFixes.push({
34-
id: fix.id,
35-
label: fix.label,
36-
documentation: fix.documentation,
36+
command: fix.command,
3737
score: fix.score,
38+
id: `quickfix_#${c++}`,
3839
support
3940
});
4041
}

src/vs/languages/css/common/cssWorker.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,12 @@ export class CSSWorker extends AbstractModeWorker {
386386
var score = strings.difference(propertyName, p);
387387
if (score >= propertyName.length / 2 /*score_lim*/) {
388388
result.push({
389-
label: nls.localize('css.quickfix.rename', "Rename to '{0}'", p),
390-
id: JSON.stringify({ type: 'rename', name: p }),
391-
score: score
389+
command: {
390+
id: 'css.renameProptery',
391+
title: nls.localize('css.quickfix.rename', "Rename to '{0}'", p),
392+
arguments: [{ type: 'rename', name: p }]
393+
},
394+
score
392395
});
393396
}
394397
}
@@ -426,12 +429,12 @@ export class CSSWorker extends AbstractModeWorker {
426429
});
427430
}
428431

429-
public runQuickFixAction(resource:URI, range:EditorCommon.IRange, id: any):winjs.TPromise<Modes.IQuickFixResult>{
430-
var command = JSON.parse(id);
431-
switch (command.type) {
432+
public runQuickFixAction(resource: URI, range: EditorCommon.IRange, quickFix: Modes.IQuickFix): winjs.TPromise<Modes.IQuickFixResult>{
433+
let [{type, name}] = quickFix.command.arguments;
434+
switch (type) {
432435
case 'rename': {
433436
return winjs.TPromise.as({
434-
edits: [{ resource, range, newText: command.name }]
437+
edits: [{ resource, range, newText: name }]
435438
});
436439
}
437440
}

src/vs/languages/css/test/common/css-worker.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ suite('Validation - CSS', () => {
130130
};
131131

132132
var assertQuickFix= function(fixes: Modes.IQuickFix[], model: mm.MirrorModel, expectedContent:string[]) {
133-
var labels = fixes.map(f => f.label);
133+
var labels = fixes.map(f => f.command.title);
134134

135135
for (var index = 0; index < expectedContent.length; index++) {
136136
assert.ok(labels.indexOf(expectedContent[index]) !== -1, 'Quick fix not found: ' + expectedContent[index]);

src/vs/languages/typescript/common/features/quickFix.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import nls = require('vs/nls');
1515
import arrays = require('vs/base/common/arrays');
1616
import {IMarker} from 'vs/platform/markers/common/markers';
1717

18-
export function evaluate(languageService: ts.LanguageService, resource: URI, range: EditorCommon.IRange, id: any): Modes.IQuickFixResult {
18+
export function evaluate(languageService: ts.LanguageService, resource: URI, range: EditorCommon.IRange, quickFix: Modes.IQuickFix): Modes.IQuickFixResult {
1919

2020
var filename = resource.toString(),
2121
sourceFile = languageService.getSourceFile(filename),
@@ -26,7 +26,7 @@ export function evaluate(languageService: ts.LanguageService, resource: URI, ran
2626
return null;
2727
}
2828

29-
var command = JSON.parse(id);
29+
var [command] = quickFix.command.arguments;
3030
switch (command.type) {
3131
case 'rename': {
3232
var start = sourceFile.getLineAndCharacterOfPosition(token.getStart());
@@ -129,9 +129,12 @@ function computeRenameProposals(languageService:ts.LanguageService, resource:URI
129129
}
130130

131131
fixes.push({
132-
label: nls.localize('typescript.quickfix.rename', "Rename to '{0}'", entry.name),
133-
id: JSON.stringify({ type: 'rename', name: entry.name }),
134-
score: score
132+
command: {
133+
id: 'ts.renameTo',
134+
title: nls.localize('typescript.quickfix.rename', "Rename to '{0}'", entry.name),
135+
arguments: [{ type: 'rename', name: entry.name }]
136+
},
137+
score
135138
});
136139
}
137140
});
@@ -204,19 +207,25 @@ function computeAddTypeDefinitionProposals(languageService: ts.LanguageService,
204207
if (typingsMap.hasOwnProperty(currentWord)) {
205208
var mapping = typingsMap[currentWord];
206209
var dtsRefs: string[] = Array.isArray(mapping) ? <string[]> mapping : [ <string> mapping ];
207-
dtsRefs.forEach((dtsRef) => {
210+
dtsRefs.forEach((dtsRef, idx) => {
208211
result.push({
209-
label: nls.localize('typescript.quickfix.typeDefinitions', "Download type definition {0}", dtsRef.split('/')[1]),
210-
id: JSON.stringify({ type: 'typedefinitions', name: dtsRef }),
211-
score: 1
212+
command: {
213+
id: 'ts.downloadDts',
214+
title: nls.localize('typescript.quickfix.typeDefinitions', "Download type definition {0}", dtsRef.split('/')[1]),
215+
arguments: [{ type: 'typedefinitions', name: dtsRef }]
216+
},
217+
score: idx
212218
});
213219
});
214220
}
215221

216222
if (strings.endsWith(resource.path, '.js')) {
217223
result.push({
218-
label: nls.localize('typescript.quickfix.addAsGlobal', "Mark '{0}' as global", currentWord),
219-
id: JSON.stringify({ type: 'addglobal', name: currentWord }),
224+
command: {
225+
id: 'ts.addAsGlobal',
226+
title: nls.localize('typescript.quickfix.addAsGlobal', "Mark '{0}' as global", currentWord),
227+
arguments: [{ type: 'addglobal', name: currentWord }]
228+
},
220229
score: 1
221230
});
222231
}

src/vs/languages/typescript/common/features/quickFixMainActions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ export class QuickFixMainActions {
3434
this._contextService = contextService;
3535
}
3636

37-
public evaluate(resource: URI, range: EditorCommon.IRange, id: any) : winjs.TPromise<Modes.IQuickFixResult> {
38-
var command = JSON.parse(id);
37+
public evaluate(resource: URI, range: EditorCommon.IRange, quickFix: Modes.IQuickFix) : winjs.TPromise<Modes.IQuickFixResult> {
38+
var [command] = quickFix.command.arguments;
3939
switch (command.type) {
4040
case 'typedefinitions': {
4141
return this.evaluateAddTypeDefinitionProposal(command.name, resource);

0 commit comments

Comments
 (0)