Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Implement textDocument/codeAction #252

Merged
merged 2 commits into from
May 15, 2017
Merged

Implement textDocument/codeAction #252

merged 2 commits into from
May 15, 2017

Conversation

felixfbecker
Copy link
Contributor

#251 to be merged first

@tomv564

@felixfbecker felixfbecker force-pushed the code-actions branch 2 times, most recently from 207cb20 to 3ed3f6c Compare May 15, 2017 11:33
@codecov
Copy link

codecov bot commented May 15, 2017

Codecov Report

Merging #252 into master will increase coverage by 0.08%.
The diff coverage is 63.04%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #252      +/-   ##
==========================================
+ Coverage   58.16%   58.25%   +0.08%     
==========================================
  Files          13       13              
  Lines        2087     2132      +45     
  Branches      345      352       +7     
==========================================
+ Hits         1214     1242      +28     
- Misses        734      744      +10     
- Partials      139      146       +7
Impacted Files Coverage Δ
src/lang-handler.ts 11.36% <0%> (-0.55%) ⬇️
src/project-manager.ts 78.63% <100%> (+0.06%) ⬆️
src/typescript-service.ts 69.49% <65.11%> (-0.46%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6436c74...53be558. Read the comment docs.

@felixfbecker felixfbecker changed the title Implement Code Actions Implement textDocument/codeAction May 15, 2017
@felixfbecker felixfbecker mentioned this pull request May 15, 2017
3 tasks
@felixfbecker
Copy link
Contributor Author

Rebased, @tomv564 does this work for you?

});
} as any);
} as any);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, nice to drop these 👍

* execution on the server. In most cases the server creates a WorkspaceEdit structure and
* applies the changes to the workspace using the request workspace/applyEdit which is sent from
* the server to the client.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Great to see some documentation on how this works!

end: ts.getLineAndCharacterOfPosition(sourceFile, span.start + span.length)
},
newText
}));
Copy link
Contributor

Choose a reason for hiding this comment

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

So that's where all of convertTextChange went. Nice :)

if (!params.arguments || params.arguments.length < 1) {
return Observable.throw(new Error(`Command ${params.command} requires arguments`));
}
return this.executeCodeFixCommand(params.arguments, span);
Copy link
Contributor

Choose a reason for hiding this comment

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

I forgot to highlight this earlier in the PR, but throwing all of arguments into this.executeCodeFixCommand(... feels a bit dirty. Perhaps the "proper" way is to make sure the FileTextChanges array itself is in params.arguments[0]. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why do you think it's dirty?

Copy link
Contributor

Choose a reason for hiding this comment

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

What if in the future - besides the array of FileTextChanges - we also need to pass some Context c from the CodeAction to executeCodeFixCommand.

If the FileTextChanges live in params.arguments[0], then params.arguments[1] would be the logical place to put this Context parameter.

If we keep the FileTextChanges in all of params.arguments, then where would this extra Context parameter go?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would prefer the first parameter to be an object { context, fileTextChanges } then.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that sounds good!
I guess you are free to modify codeFix's use of Command arguments at any time without compatibility issues, so there is no need to change anything now.

@tomv564
Copy link
Contributor

tomv564 commented May 15, 2017

I just checked out and built this branch and verified both Rename and the codeFix Code Action work

@felixfbecker felixfbecker merged commit 8e7d2fa into master May 15, 2017
@felixfbecker felixfbecker deleted the code-actions branch May 15, 2017 17:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants