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

Expose rename provider's prepareRename functionality for testing #48840

Closed
DanTup opened this issue Apr 27, 2018 · 7 comments
Closed

Expose rename provider's prepareRename functionality for testing #48840

DanTup opened this issue Apr 27, 2018 · 7 comments
Assignees
Labels
*dev-question VS Code Extension Development Question info-needed Issue requires more information from poster

Comments

@DanTup
Copy link
Contributor

DanTup commented Apr 27, 2018

In #7340 new functionality was added to resolve renames to ranges with placeholder text, however it doesn't seem to be available in tests (unless you have a reference to the provider). vscode.executeDocumentRenameProvider calls the provideRenameEdits method but not the prepareRename method.

@jrieken
Copy link
Member

jrieken commented Apr 27, 2018

unless you have a reference to the provider)

What's so bad about that? The information from prepare isn't fed into the provideRenameEdits anyways so I might be missing what the problem is?

@DanTup
Copy link
Contributor Author

DanTup commented Apr 27, 2018

I can't easily get a reference to my rename provider without exporting it in my extension (and it feels weird to just start exporting everything in my extensions "API"). I thought the expected way to test providers was through the commands (though I may be mistaken).

@jrieken
Copy link
Member

jrieken commented Apr 30, 2018

I thought the expected way to test providers was through the commands (though I may be mistaken).

Well, that might work but that isn't the design goal. Not quite sure why you would need to export the provider via your API? Can't you simply create a new/different instance of the provider in your unit test?

@DanTup
Copy link
Contributor Author

DanTup commented Apr 30, 2018

@jrieken I'm trying to write full end-to-end tests; it'd be really easy to write passing unit tests and have broken functionality (because the interesting things are generally the interactions between Code and my code of my code and the language server... or for example if I didn't register my provider correctly!). My tests are often like:

  1. Write a known set of code into the editor
  2. Invoke some command at a specific location
  3. Check the new code in the editor

This makes sure my understanding of both Code and the language server's APIs are sound (there are many complications that'd be hard to unit test, like 0-based and 1-based offsets, multi-cursor edits, document being modified during an async operation, etc.).

I understand if you don't think adding commands for everything is the right thing to do, but I do think supporting end-to-end testing like this is really valuable.

@jrieken
Copy link
Member

jrieken commented Apr 30, 2018

Yes, I understand the concept of higher-level tests but I don't agree that because of that everything should be exposed/accessible via the API. So, for this specific example, please use a unit-test.

@jrieken jrieken added the *dev-question VS Code Extension Development Question label Apr 30, 2018
@vscodebot
Copy link

vscodebot bot commented Apr 30, 2018

We have a great developer community over on slack where extension authors help each other. This is a great place for you to ask questions and find support.

Happy Coding!

@vscodebot vscodebot bot closed this as completed Apr 30, 2018
@DanTup
Copy link
Contributor Author

DanTup commented Apr 30, 2018

Understood. For now I think exposing the provider in my exports would be better; creating unit tests doesn't feel all that worthwhile (I'd have to mock the language server, and then I wouldn't actually be testing the thing I care about - the interaction with the language server).

@vscodebot vscodebot bot locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*dev-question VS Code Extension Development Question info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

2 participants