-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #488 - LanguageService - getSuggestionDiagnostics, getEditsForR…
…efactor, getCodeFixesAtPosition
- Loading branch information
1 parent
c026a16
commit 9e42b10
Showing
9 changed files
with
284 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { ts } from "../../../typescript"; | ||
import {FileTextChanges} from "./FileTextChanges"; | ||
|
||
/** | ||
* Represents a code action. | ||
*/ | ||
export class CodeAction<TCompilerObject extends ts.CodeAction = ts.CodeAction> { | ||
/** @internal */ | ||
private readonly _compilerObject: TCompilerObject; | ||
|
||
/** @private */ | ||
constructor(compilerObject: TCompilerObject) { | ||
this._compilerObject = compilerObject; | ||
} | ||
|
||
/** Gets the compiler text change. */ | ||
get compilerObject() { | ||
return this._compilerObject; | ||
} | ||
|
||
/** Description of the code action. */ | ||
getDescription() { | ||
return this.compilerObject.description; | ||
} | ||
|
||
/** Text changes to apply to each file as part of the code action. */ | ||
getChanges() { | ||
return this.compilerObject.changes.map(change => new FileTextChanges(change)); | ||
} | ||
|
||
// TODO: commands property | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { ts } from "../../../typescript"; | ||
import { CodeAction } from "./CodeAction"; | ||
|
||
/** | ||
* Represents a code fix action. | ||
*/ | ||
export class CodeFixAction extends CodeAction<ts.CodeFixAction> { | ||
/** | ||
* Short name to identify the fix, for use by telemetry. | ||
*/ | ||
getFixName() { | ||
return this.compilerObject.fixName; | ||
} | ||
|
||
/** | ||
* If present, one may call 'getCombinedCodeFix' with this fixId. | ||
* This may be omitted to indicate that the code fix can't be applied in a group. | ||
*/ | ||
getFixId() { | ||
return this.compilerObject.fixId; | ||
} | ||
|
||
/** | ||
* Gets the description of the code fix when fixing everything. | ||
*/ | ||
getFixAllDescription() { | ||
return this.compilerObject.fixAllDescription; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { ts } from "../../../typescript"; | ||
import { Memoize } from "../../../utils"; | ||
import { FileTextChanges } from "./FileTextChanges"; | ||
|
||
/** | ||
* Set of edits to make in response to a refactor action, plus an optional location where renaming should be invoked from. | ||
*/ | ||
export class RefactorEditInfo { | ||
/** @internal */ | ||
private readonly _compilerObject: ts.RefactorEditInfo; | ||
|
||
/** @private */ | ||
constructor(compilerObject: ts.RefactorEditInfo) { | ||
this._compilerObject = compilerObject; | ||
} | ||
|
||
/** Gets the compiler refactor edit info. */ | ||
get compilerObject() { | ||
return this._compilerObject; | ||
} | ||
|
||
/** | ||
* Gets refactor file text changes | ||
*/ | ||
@Memoize | ||
getEdits() { | ||
return this.compilerObject.edits.map(edit => new FileTextChanges(edit)); | ||
} | ||
|
||
/** | ||
* Gets the file path for a rename refactor. | ||
*/ | ||
getRenameFilePath() { | ||
return this.compilerObject.renameFilename; | ||
} | ||
|
||
/** | ||
* Location where renaming should be invoked from. | ||
*/ | ||
getRenameLocation() { | ||
return this.compilerObject.renameLocation; | ||
} | ||
|
||
// TODO: getCommands | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
import { expect } from "chai"; | ||
import { Statement } from "../../../compiler"; | ||
import { getInfoFromText } from "../testHelpers"; | ||
|
||
describe(nameof(Statement), () => { | ||
// todo: tests | ||
describe(nameof<Statement>(n => n.remove), () => { | ||
it("should remove the statement from its sourcefile", () => { | ||
const { sourceFile } = getInfoFromText(`const foo = 1; const bar = 2;`); | ||
const statement = sourceFile.getVariableDeclarationOrThrow("foo"); | ||
statement.remove(); | ||
expect(sourceFile.getText()).to.equals(`const bar = 2;`); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.