Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pvb/discover code actions #9304

Closed
wants to merge 123 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
49ac6e4
Initial work to get CodeFixes and make them work in fourslash
May 25, 2016
a985041
Initial work to get CodeFixes and make them work in fourslash
May 25, 2016
5b0b310
Move things around
Jun 1, 2016
617b819
Code changes to update references of the Identifiers
sarangan12 May 24, 2016
a8bc8b4
Added code for handling function, method and coonstructor level local…
sarangan12 May 26, 2016
01966ba
Rebased with origin master
sarangan12 May 26, 2016
1e5ca92
Code changes to handle unused private variables, private methods and …
sarangan12 May 27, 2016
890d178
Code changes to handle namespace level elements
sarangan12 Jun 1, 2016
69dbeea
Code changes to handle unimplemented interfaces
sarangan12 Jun 1, 2016
c78d0e2
Code to optimize the d.ts check
sarangan12 Jun 1, 2016
107b369
Correct Code change to handle the parameters for methods inside inter…
sarangan12 Jun 1, 2016
481baa3
Fix for lint error
sarangan12 Jun 2, 2016
cd1ce0f
Remove Trailing whitespace
sarangan12 Jun 2, 2016
4e36add
Support multiple errorcodes per fix
Jun 2, 2016
3994bfc
Implement making making super call the first call fix.
Jun 2, 2016
a38149d
Code changes to handle interface implementations
sarangan12 Jun 3, 2016
0571c19
Changes to display the error position correctly
sarangan12 Jun 3, 2016
e17ed58
Compiler Test Cases
sarangan12 Jun 3, 2016
2b7f3a7
Merge remote-tracking branch 'origin' into UpdateReferences
sarangan12 Jun 6, 2016
efa1543
Merge remote-tracking branch 'origin' into pvb/discoverCodeActions
sarangan12 Jun 6, 2016
d2ff079
Code change that was missed in merge
sarangan12 Jun 6, 2016
ee083ef
Merge branch 'pvb/discoverCodeActions' into UpdateReferences
sarangan12 Jun 6, 2016
a3818ba
stash
Jun 7, 2016
c619cab
First Commit for API Changes for Tracking Unused Identifiers
sarangan12 Jun 8, 2016
0a592c8
Removed unnecessary change in superfix and add one more test case
sarangan12 Jun 8, 2016
adfb73d
Additional Fourslash test cases
sarangan12 Jun 9, 2016
c102c3a
Added error message
sarangan12 Jun 9, 2016
eb7fa70
Fix tests
Jun 10, 2016
a1fa10d
Quick fix for implementing interfaces
sarangan12 Jun 13, 2016
37e25df
Changes the signature and error message
sarangan12 Jun 13, 2016
2e48281
Modified the test case and expected results
sarangan12 Jun 13, 2016
3d25daf
Additional scenarios for handling the Interface Implementation
sarangan12 Jun 15, 2016
5a34352
Adding condition to ignore constructor parameters
sarangan12 Jun 15, 2016
93b7490
Removing unnecessary tests
sarangan12 Jun 15, 2016
7aba626
Additional changes for compiler code
sarangan12 Jun 15, 2016
ed5052d
Additional changes to handle constructor scenario
sarangan12 Jun 15, 2016
f5cdc9c
Fixing the consolidated case
sarangan12 Jun 15, 2016
8c3c7b1
Changed logic to search for private instead of public
sarangan12 Jun 15, 2016
dfad7cc
Response to PR Comments
sarangan12 Jun 15, 2016
c325625
Merge remote-tracking branch 'origin' into UnusedIdentifiersCompilerCode
sarangan12 Jun 15, 2016
6a711bc
Changed the error code in test cases as result of merge with master
sarangan12 Jun 15, 2016
d62a43f
Adding the missing file
sarangan12 Jun 16, 2016
043a625
Adding the missing file II
sarangan12 Jun 16, 2016
6d4020b
Rename QuickFix to CodeFix
Jun 16, 2016
7792e18
Bunch of renames
Jun 16, 2016
e57e628
Make provider work with multiple fixes
Jun 17, 2016
32e5787
Adding code for handling classes implemented by other classes
sarangan12 Jun 17, 2016
394a4d1
Optimizing code Part I
sarangan12 Jun 17, 2016
dca1263
Optimizing code Part II
sarangan12 Jun 17, 2016
03e2037
Verify the code changes result in the expected new code.
Jun 18, 2016
8f9d4ae
Response to PR comments
sarangan12 Jun 20, 2016
f15448a
Merge remote-tracking branch 'origin' into UnusedIdentifiersCompilerCode
sarangan12 Jun 20, 2016
972ed40
Merge branch 'UnusedIdentifiersCompilerCode' into UnusedIdentifiersApi
sarangan12 Jun 20, 2016
1d3a888
Fixing the error code
sarangan12 Jun 20, 2016
c82453f
Code changes for checking unused imports
sarangan12 Jun 20, 2016
bcd6fc4
Test Cases for Unused Imports
sarangan12 Jun 20, 2016
49385f4
Response to PR comments
sarangan12 Jun 21, 2016
0a30933
Merge branch 'pvb/discoverCodeActions' of https://github.com/Microsof…
sarangan12 Jun 21, 2016
b198d69
Merge branch 'pvb/discoverCodeActions', remote-tracking branch 'origi…
sarangan12 Jun 21, 2016
f58e8ca
Modified the test code based on the changes in DiscoverActions branch
sarangan12 Jun 21, 2016
d08f1b1
Merge branch 'UnusedIdentifiersCompilerCode' into UnusedIdentifiersApi
sarangan12 Jun 21, 2016
bdf444c
Add fix for moving the super call to be the first call in the constru…
Jun 21, 2016
b807487
Merge branch 'master' into pvb/discoverCodeActions
Jun 21, 2016
e077dde
Code changes for unused imports - Part I
sarangan12 Jun 21, 2016
5993015
Code change specific to position of Import Declaration
sarangan12 Jun 21, 2016
5c656a7
Merge branch 'UnusedIdentifiersCompilerCode' into UnusedIdentifiersApi
sarangan12 Jun 21, 2016
45d449f
Additional code changes for unused imports
sarangan12 Jun 21, 2016
f464f92
Code change for handling the position for unused import
sarangan12 Jun 21, 2016
e096d39
Merge branch 'UnusedIdentifiersCompilerCode' into UnusedIdentifiersApi
sarangan12 Jun 21, 2016
817091c
Code changes to handle For statements
sarangan12 Jun 22, 2016
5b32e91
Merge branch 'pvb/discoverCodeActions' of https://github.com/Microsof…
sarangan12 Jun 22, 2016
3f559ae
Merge branch 'pvb/discoverCodeActions' into UnusedIdentifiersApi
sarangan12 Jun 22, 2016
3b5f8d2
New scenarios for handling parameters in lambda function, type parame…
sarangan12 Jun 22, 2016
ed282d7
Additional scenarios based on PR comments
sarangan12 Jun 22, 2016
e502ba0
Removing a redundant check
sarangan12 Jun 22, 2016
7dda03e
Merge branch 'UnusedIdentifiersCompilerCode' into UnusedIdentifiersApi
sarangan12 Jun 22, 2016
082c6de
Additional scenarios added
sarangan12 Jun 23, 2016
0e2e43d
Added ambient check to imports and typeparatmeter reporting
sarangan12 Jun 23, 2016
dd04af5
Merge branch 'UnusedIdentifiersCompilerCode' into UnusedIdentifiersApi
sarangan12 Jun 23, 2016
73375c0
Code changes and test cases to handle enums
sarangan12 Jun 23, 2016
754034d
Added Debug Statement instead of throwing error.
sarangan12 Jun 23, 2016
d6c2bcd
Merge remote-tracking branch 'origin' into UnusedIdentifiersCompilerCode
sarangan12 Jun 23, 2016
33f4a6b
CR feedback, and add the ability to have fixes which span files.
Jun 23, 2016
42bc9c5
fix typo
Jun 23, 2016
0516e91
Don't throw
Jun 23, 2016
37cb001
More typo fixes
Jun 23, 2016
f93c6c8
Added one more scenario to handle type parameters
sarangan12 Jun 24, 2016
5d61c43
Merge branch 'UnusedIdentifiersCompilerCode' into UnusedIdentifiersApi
sarangan12 Jun 24, 2016
97a3d90
Added test for another scenario involving type parameters
sarangan12 Jun 24, 2016
4521058
Added new scenario for TypeParameter on Interface
sarangan12 Jun 24, 2016
5b861eb
Merge branch 'UnusedIdentifiersCompilerCode' into UnusedIdentifiersApi
sarangan12 Jun 24, 2016
ab0fdd4
Additional test cases
sarangan12 Jun 24, 2016
5eb7153
Refactoring the code
sarangan12 Jun 24, 2016
1401506
Merge remote-tracking branch 'origin' into UnusedIdentifiersCompilerCode
sarangan12 Jun 24, 2016
5361e5f
Added scenario to handle private class elements declared in constructor.
sarangan12 Jun 24, 2016
7fc4616
Minor change to erro reporting
sarangan12 Jun 24, 2016
9753d09
Merge remote-tracking branch 'origin' into UnusedIdentifiersCompilerCode
sarangan12 Jun 24, 2016
4c8d399
Merge branch 'UnusedIdentifiersCompilerCode' into UnusedIdentifiersApi
sarangan12 Jun 24, 2016
00d84d4
Merge branch 'master' into pvb/discoverCodeActions
Jun 24, 2016
7238991
Additional scenarios
sarangan12 Jun 27, 2016
537e065
Code changes for abstract class extends
sarangan12 Jun 27, 2016
2dd1361
Merge remote-tracking branch 'origin' into UnusedIdentifiersApi
sarangan12 Jun 27, 2016
db4838f
Code changes for changing extends keyword to implements keyword
sarangan12 Jun 27, 2016
f0a5a6b
Merge branch 'master' into pvb/discoverCodeActions
Jun 28, 2016
bf6e045
Change to use CodeActionContext instead of a bunch of arguments, so it's
Jun 28, 2016
23ea06b
CR Feedback. Turn CodeActionContext into interface
Jun 28, 2016
15d71eb
Improve Fourslash support
Jul 1, 2016
aacb834
Merge remote-tracking branch 'sarangan/UnusedIdentifiersApi' into pvb…
Jul 1, 2016
d6e81c3
Merge remote-tracking branch 'sarangan/ImplementInterfacesQUickFix' i…
Jul 1, 2016
0260fca
Merge remote-tracking branch 'sarangan/ChangeExtendsToImplementsFix' …
Jul 1, 2016
d9f9baa
linter fixes
Jul 1, 2016
7397f6d
Add codefixes to tsconfig and jake
Jul 1, 2016
8e2cdac
Each 'CodeFix' can now return more than one action which implements a…
Jul 1, 2016
81a5901
code cleanup
Jul 2, 2016
49c0965
Merge branch 'master' into pvb/discoverCodeActions
Jul 2, 2016
35fcbb8
Code clean up after renaming
Jul 2, 2016
8871c18
Merge branch 'master' into pvb/discoverCodeActions
Jul 6, 2016
02fcf9f
Change API and fix FourSlash
Jul 7, 2016
d4f0e13
Change FourSlash API
Jul 9, 2016
79375f8
Merge branch 'master' into pvb/discoverCodeActions
Jul 9, 2016
62c4bad
Linter fixes
Jul 9, 2016
5bd7458
Fixes due to API Changes
sarangan12 Jul 11, 2016
79fb29e
Merge branch 'master' into pvb/discoverCodeActions
Aug 5, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/harness/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2958,7 +2958,7 @@ namespace FourSlashInterface {
}

public isValidBraceCompletionAtPosition(openingBrace: string) {
this.state.verifyBraceCompletionAtPostion(this.negative, openingBrace);
this.state.verifyBraceCompletionAtPosition(this.negative, openingBrace);
}
}

Expand Down
15 changes: 10 additions & 5 deletions src/services/codefixes/codeFixProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ namespace ts {
export interface CodeAction {
name: string;
errorCodes: string[];
getTextChanges(sourceFile: SourceFile, start: number, end: number): FileTextChanges[];
getTextChanges(context: CodeActionContext): FileTextChanges[];
}

export class CodeActionContext {
constructor(public errorCode: string, public sourceFile: SourceFile, public span: TextSpan, public checker: TypeChecker) {
}
}

export namespace codeFix {
var codeActions: Map<CodeAction[]> = {};

export function registerCodeFix(fix: CodeAction) {
forEach( fix.errorCodes, error => {
forEach(fix.errorCodes, error => {
let fixes = codeActions[error];
if (!fixes) {
fixes = [];
Expand All @@ -26,14 +31,14 @@ namespace ts {
return getKeys(codeActions);
}

public getFixes(errorCode: string, sourceFile: SourceFile, start: number, end: number): CodeFix[] {
const actions = codeActions[errorCode];
public getFixes(context: CodeActionContext): CodeFix[] {
const actions = codeActions[context.errorCode];
const fixes: CodeFix[] = [];

Debug.assert(actions && actions.length > 0, "No fixes found for error: '${errorCode}'.");

forEach(actions, a => {
const textChanges = a.getTextChanges(sourceFile, start, end);
const textChanges = a.getTextChanges(context);
if (textChanges && textChanges.length > 0) {
fixes.push({ description: a.name, changes: textChanges });
}
Expand Down
11 changes: 7 additions & 4 deletions src/services/codefixes/superFixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ namespace ts.codeFix {
registerCodeFix({
name: getLocaleSpecificMessage(Diagnostics.Add_missing_super_call),
errorCodes: ["TS2377"],
getTextChanges: (sourceFile: SourceFile, start: number, end: number) => {
const token = getTokenAtPosition(sourceFile, start);
getTextChanges: (context: CodeActionContext) => {
const sourceFile = context.sourceFile;
const token = getTokenAtPosition(sourceFile, context.span.start);
Debug.assert(token.kind === SyntaxKind.ConstructorKeyword, "Failed to find the constructor.");

const newPosition = getOpenBraceEnd(<ConstructorDeclaration>token.parent, sourceFile);
Expand All @@ -21,8 +22,10 @@ namespace ts.codeFix {
registerCodeFix({
name: getLocaleSpecificMessage(Diagnostics.Make_super_call_the_first_statement_in_the_constructor),
errorCodes: ["TS17009"],
getTextChanges: (sourceFile: SourceFile, start: number, end: number) => {
const token = getTokenAtPosition(sourceFile, start);
getTextChanges: (context: CodeActionContext) => {
const sourceFile = context.sourceFile;

const token = getTokenAtPosition(sourceFile, context.span.start);
const constructor = getContainingFunction(token);
Debug.assert(constructor.kind === SyntaxKind.Constructor, "Failed to find the constructor.");

Expand Down
6 changes: 4 additions & 2 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7708,11 +7708,13 @@ namespace ts {
function getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: string[]): CodeFix[] {
synchronizeHostData();
const sourceFile = getValidSourceFile(fileName);

const checker = program.getTypeChecker();
let allFixes: CodeFix[] = [];

forEach(errorCodes, error => {
const fixes = codeFixProvider.getFixes(error, sourceFile, start, end);
const context = new CodeActionContext(error, sourceFile, { start, length: end - start }, checker);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems more Javascripty to use an interface instead of a class for CodeActionContext and say

const context = { error, sourceFile, spec: { start, length: end - start }, checker };

since CodeActionContext doesn't use any class features except the constructor.


const fixes = codeFixProvider.getFixes(context);
if (fixes) {
allFixes = allFixes.concat(fixes);
}
Expand Down