Conversation
src/compiler/core.ts
Outdated
| return -1; | ||
| } | ||
|
|
||
| export function firstOrUndefined<T>(array: T[], predicate: (x: T) => boolean): T { |
There was a problem hiding this comment.
forEach is slightly different. Also this is usually called find.
| const fixes = codeFixes[context.errorCode]; | ||
| let allActions: CodeAction[] = []; | ||
|
|
||
| Debug.assert(fixes && fixes.length > 0, "No fixes found for error: '${errorCode}'."); |
| const superCall = findSuperCall((<ConstructorDeclaration>constructor).body); | ||
| Debug.assert(!!superCall, "Failed to find super call."); | ||
|
|
||
| const newPosition = getOpenBraceEnd(<ConstructorDeclaration>constructor, sourceFile); |
There was a problem hiding this comment.
can you add a test for the case where this is an argument to super
super(this.x);|
Please add this to the tsserver, you will need to define a new request and response kinds in server\protocol.d.ts, and add a handler for it in server\session.ts |
src/services/codefixes/references.ts
Outdated
| @@ -0,0 +1,3 @@ | |||
| ///<reference path='..\services.ts' /> | |||
There was a problem hiding this comment.
we stoped using references for a while. they should be picked up by the tsconfig.json in this folder any ways. so please remove this.
# Conflicts: # src/compiler/diagnosticMessages.json # src/services/services.ts
…eScript into pvb/codeaction/api
# Conflicts: # src/services/types.ts
| position?: number; | ||
| } | ||
|
|
||
| /** |
There was a problem hiding this comment.
nit Code Fixes instead of codefixed
src/server/protocol.d.ts
Outdated
| textChanges: CodeEdit[]; | ||
| } | ||
|
|
||
| export interface CodeActionResponse extends Response { |
| /** Description of the code action to display in the UI of the editor */ | ||
| description: string; | ||
| /** Text changes to apply to each file as part of the code action */ | ||
| changes: FileCodeEdits[]; |
src/server/protocol.d.ts
Outdated
| /** | ||
| * Changes to apply to each file as part of the code action. | ||
| */ | ||
| changes: FileTextChanges[]; |
There was a problem hiding this comment.
see formatting for example.
src/server/protocol.d.ts
Outdated
| textChanges: TextChange[]; | ||
| } | ||
|
|
||
| export class TextChange { |
src/server/session.ts
Outdated
| description: source.description, | ||
| changes: source.changes.map(change => ({ | ||
| fileName: change.fileName, | ||
| textChanges: change.textChanges.map(textChange => ({ |
There was a problem hiding this comment.
extract the common part between here and getFormattingEditsForRange in convertTextChangeToCodeEdit
src/server/client.ts
Outdated
| } | ||
|
|
||
| getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: number[]): ts.CodeAction[] { | ||
| throw new Error("Not Implemented Yet."); |
There was a problem hiding this comment.
why? add implementation here, and add a test in tests\cases\fourslash\server
src/services/shims.ts
Outdated
| */ | ||
| isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): string; | ||
|
|
||
| getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: string): string; |
There was a problem hiding this comment.
we do not need to update the shims, since we moved to tsserver
| newLineCharacter: newLineChar | ||
| }; | ||
|
|
||
| const fixes = codefix.getFixes(context); |
There was a problem hiding this comment.
check the cancellation token for every iteration.
| namespace ts { | ||
| export interface CodeFix { | ||
| errorCodes: number[]; | ||
| getCodeActions(context: CodeFixContext): CodeAction[]; |
There was a problem hiding this comment.
getCodeActions(context: CodeFixContext): CodeAction[] | undefined to allow strictNullChecks to work for users implementing it
src/server/protocol.d.ts
Outdated
| body?: NavigationBarItem[]; | ||
| } | ||
|
|
||
| export interface CodeAction { |
There was a problem hiding this comment.
this is already defined above.
| export const CompilerOptionsForInferredProjects = "compilerOptionsForInferredProjects"; | ||
| export const GetCodeFixes = "getCodeFixes"; | ||
| export const GetCodeFixesFull = "getCodeFixes-full"; | ||
| export const GetSupportedCodeFixes = "getSupportedCodeFixes"; |
There was a problem hiding this comment.
i do not see the definition of the request for this command in protocol.d.ts
There was a problem hiding this comment.
can you also add a test for it.
There was a problem hiding this comment.
There are no arguments for the command so no need for a request
| }); | ||
| } | ||
|
|
||
| export function getSupportedErrorCodes() { |
There was a problem hiding this comment.
Any reason this returns a string[] and not a number[]? Error codes are always numbers, so you could map this with Number.parseInt.
There was a problem hiding this comment.
Yes, while we currently only return numbers for errorcodes, in the future e.g. a linter extension could prepend the errorcodes they return with a string. That way they can be differentiated and handled by separate 'fixers', even when they have the same error number.
There was a problem hiding this comment.
Maybe the definitions of errorCode and errorCodes above (in CodeFixContent and CodeFix) should use string then?
There was a problem hiding this comment.
You make a good point, I'll update that.
Add CodeAction API