diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2021-02-05 05:53:02 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-05 05:53:02 +1100 |
commit | b77fcbc518428429e39f5ba94e41fcd0418ee7a0 (patch) | |
tree | 0051cc7e5ac0c8f83278de093a2be7209cf9fcfc /cli/tsc | |
parent | 644a7ff2d70cbd8bfba4c87b75a047e79830c4b6 (diff) |
feat(lsp): add TS quick fix code actions (#9396)
Diffstat (limited to 'cli/tsc')
-rw-r--r-- | cli/tsc/99_main_compiler.js | 45 | ||||
-rw-r--r-- | cli/tsc/compiler.d.ts | 24 |
2 files changed, 68 insertions, 1 deletions
diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js index fa25b207f..50631e83f 100644 --- a/cli/tsc/99_main_compiler.js +++ b/cli/tsc/99_main_compiler.js @@ -555,6 +555,45 @@ delete Object.prototype.__proto__; ); return respond(id, sourceFile && sourceFile.text); } + case "getCodeFixes": { + return respond( + id, + languageService.getCodeFixesAtPosition( + request.specifier, + request.startPosition, + request.endPosition, + request.errorCodes.map((v) => Number(v)), + { + indentSize: 2, + indentStyle: ts.IndentStyle.Block, + semicolons: ts.SemicolonPreference.Insert, + }, + { + quotePreference: "double", + }, + ), + ); + } + case "getCombinedCodeFix": { + return respond( + id, + languageService.getCombinedCodeFix( + { + type: "file", + fileName: request.specifier, + }, + request.fixId, + { + indentSize: 2, + indentStyle: ts.IndentStyle.Block, + semicolons: ts.SemicolonPreference.Insert, + }, + { + quotePreference: "double", + }, + ), + ); + } case "getCompletions": { return respond( id, @@ -638,6 +677,12 @@ delete Object.prototype.__proto__; ), ); } + case "getSupportedCodeFixes": { + return respond( + id, + ts.getSupportedCodeFixes(), + ); + } default: throw new TypeError( // @ts-ignore exhausted case statement sets type to never diff --git a/cli/tsc/compiler.d.ts b/cli/tsc/compiler.d.ts index 17d6ddb38..4e5dcdb96 100644 --- a/cli/tsc/compiler.d.ts +++ b/cli/tsc/compiler.d.ts @@ -44,6 +44,8 @@ declare global { | ConfigureRequest | FindRenameLocationsRequest | GetAsset + | GetCodeFixes + | GetCombinedCodeFix | GetCompletionsRequest | GetDefinitionRequest | GetDiagnosticsRequest @@ -51,7 +53,8 @@ declare global { | GetImplementationRequest | GetNavigationTree | GetQuickInfoRequest - | GetReferencesRequest; + | GetReferencesRequest + | GetSupportedCodeFixes; interface BaseLanguageServerRequest { id: number; @@ -78,6 +81,21 @@ declare global { specifier: string; } + interface GetCodeFixes extends BaseLanguageServerRequest { + method: "getCodeFixes"; + specifier: string; + startPosition: number; + endPosition: number; + errorCodes: string[]; + } + + interface GetCombinedCodeFix extends BaseLanguageServerRequest { + method: "getCombinedCodeFix"; + specifier: string; + // deno-lint-ignore ban-types + fixId: {}; + } + interface GetCompletionsRequest extends BaseLanguageServerRequest { method: "getCompletions"; specifier: string; @@ -125,4 +143,8 @@ declare global { specifier: string; position: number; } + + interface GetSupportedCodeFixes extends BaseLanguageServerRequest { + method: "getSupportedCodeFixes"; + } } |