Skip to content

Commit

Permalink
Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Hanson committed Dec 7, 2017
1 parent 41c5710 commit 87d30c0
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/harness/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2435,6 +2435,7 @@ Actual: ${stringify(fullActual)}`);
ts.Debug.assert(ts.contains(fixIds, fixId), "No available code fix has that group id.", () => `Expected '${fixId}'. Available action ids: ${fixIds}`);
const { changes, commands } = this.languageService.getCombinedCodeFix({ type: "file", fileName: this.activeFile.fileName }, fixId, this.formatCodeSettings);
assert.deepEqual(commands, options.commands);
assert(changes.every(c => c.fileName === this.activeFile.fileName), "TODO: support testing codefixes that touch multiple files");
this.applyChanges(changes);
this.verifyCurrentFileContent(newFileContent);
}
Expand Down
4 changes: 2 additions & 2 deletions src/server/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,14 +553,14 @@ namespace ts.server {
return notImplemented();
}

getCodeFixesAtPosition(file: string, start: number, end: number, errorCodes: number[]): CodeFixAction[] {
getCodeFixesAtPosition(file: string, start: number, end: number, errorCodes: ReadonlyArray<number>): ReadonlyArray<CodeFixAction> {
const args: protocol.CodeFixRequestArgs = { ...this.createFileRangeRequestArgs(file, start, end), errorCodes };

const request = this.processRequest<protocol.CodeFixRequest>(CommandNames.GetCodeFixes, args);
const response = this.processResponse<protocol.CodeFixResponse>(request);

// TODO: GH#20538 shouldn't need cast
return (response.body as protocol.CodeFixAction[]).map(({ description, changes, fixId }) => ({ description, changes: this.convertChanges(changes, file), fixId }));
return (response.body as ReadonlyArray<protocol.CodeFixAction>).map(({ description, changes, fixId }) => ({ description, changes: this.convertChanges(changes, file), fixId }));
}

getCombinedCodeFix = notImplemented;
Expand Down
6 changes: 3 additions & 3 deletions src/server/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ namespace ts.server.protocol {
/**
* Errorcodes we want to get the fixes for.
*/
errorCodes?: number[];
errorCodes?: ReadonlyArray<number>;
}

// TODO: GH#20538
Expand Down Expand Up @@ -1634,8 +1634,8 @@ namespace ts.server.protocol {
// TODO: GH#20538
/* @internal */
export interface CombinedCodeActions {
changes: FileCodeEdits[];
commands?: {}[];
changes: ReadonlyArray<FileCodeEdits>;
commands?: ReadonlyArray<{}>;
}

// TODO: GH#20538
Expand Down
4 changes: 2 additions & 2 deletions src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@ namespace ts.server {
}
}

private getCodeFixes(args: protocol.CodeFixRequestArgs, simplifiedResult: boolean): protocol.CodeAction[] | CodeAction[] {
private getCodeFixes(args: protocol.CodeFixRequestArgs, simplifiedResult: boolean): ReadonlyArray<protocol.CodeAction> | ReadonlyArray<CodeAction> {
if (args.errorCodes.length === 0) {
return undefined;
}
Expand Down Expand Up @@ -1618,7 +1618,7 @@ namespace ts.server {
return { description, changes, commands };
}

private mapTextChangesToCodeEdits(project: Project, textChanges: FileTextChanges[]): protocol.FileCodeEdits[] {
private mapTextChangesToCodeEdits(project: Project, textChanges: ReadonlyArray<FileTextChanges>): protocol.FileCodeEdits[] {
return textChanges.map(change => this.mapTextChangesToCodeEditsUsingScriptinfo(change, project.getScriptInfoForNormalizedPath(toNormalizedPath(change.fileName))));
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1883,7 +1883,7 @@ namespace ts {
return [];
}

function getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: number[], formatOptions: FormatCodeSettings): CodeFixAction[] {
function getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: ReadonlyArray<number>, formatOptions: FormatCodeSettings): ReadonlyArray<CodeFixAction> {
synchronizeHostData();
const sourceFile = getValidSourceFile(fileName);
const span = createTextSpanFromBounds(start, end);
Expand Down
8 changes: 4 additions & 4 deletions src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ namespace ts {

getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): TextSpan;

// TODO: GH#20538 return `CodeFixAction[]`
getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: number[], formatOptions: FormatCodeSettings): CodeAction[];
// TODO: GH#20538 return `ReadonlyArray<CodeFixAction>`
getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: ReadonlyArray<number>, formatOptions: FormatCodeSettings): ReadonlyArray<CodeAction>;
// TODO: GH#20538
/* @internal */
getCombinedCodeFix(scope: CombinedCodeFixScope, fixId: {}, formatOptions: FormatCodeSettings): CombinedCodeActions;
Expand Down Expand Up @@ -428,8 +428,8 @@ namespace ts {
// TODO: GH#20538
/* @internal */
export interface CombinedCodeActions {
changes: FileTextChanges[];
commands: CodeActionCommand[] | undefined;
changes: ReadonlyArray<FileTextChanges>;
commands: ReadonlyArray<CodeActionCommand> | undefined;
}

// Publicly, this type is just `{}`. Internally it is a union of all the actions we use.
Expand Down

0 comments on commit 87d30c0

Please sign in to comment.