Open
Description
Would be nice to have a shortcut to create test when we have one of those popup:
A bonus would be that if the class is a widget it create a template for widget test, if not unit test.
That a functionality we have already on Android:
It's very useful because it create a template test file directly in same place/package as the class.
For our case if we have a class in lib/catalog/bloc/mybloc.dart
it will create a test file in test/catalog/bloc/mybloc_test.dart
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
jaumard commentedon Jan 5, 2019
Hey @pq I'm trying to familiarize myself with the project by implementing this feature, can you tell me where I can find the code for this actions please ?
because I don't find how I can add my action here :/ thanks !
jaumard commentedon Jan 5, 2019
From what I've understand it's an IntentAction that I need, but I need to know if I'm in the a context of a class or not :/ finding the code that do those actions will help me a lot to do that
pq commentedon Jan 6, 2019
@jaumard: awesome that you're looking at this!
As a general rule if you're trying to figure out how something works in IDEA, it's best to grab the source and search around. (Their docs aren't great.) These instructions for setting up the Dart Plugin for development may be handy:
https://github.com/JetBrains/intellij-plugins/blob/master/Dart/README.md
I'll take a look myself and see if I find anything promising and report back...
pq commentedon Jan 6, 2019
OK. After some poking around I have a few ideas.
Once you have the source, I'd start by looking for contributors to the
testCreator
extension point. Look at this for example:I'm guessing you could model a
FlutterTestCreator
after this?Once you've got a test creator stubbed out, I'd look in the Flutter IntelliJ sources for places that reference
PsiElement
. (io.flutter.FlutterUtils#isFlutteryFile
may come in handy too.)Have fun!
jaumard commentedon Jan 7, 2019
@pq thanks ! Yeah basically that's what I did, I retrieved Dart plugin and this plugin and was trying to dig into those ^^ but even like that I find it really difficult to do things lol (for example I still don't know how convert to statefulWidget work as I didn't find the code for that...) it take my one day just to be able to have
Create Test
when I do alt+enter on the class name loolNow I'll check the JavaTestCreator and try to make a FlutterTestCreator ^^
At least work in progress :)
pq commentedon Jan 7, 2019
Great progress!
One reason you may not have found anything close to what you want to do is that everything with deep Dart language model knowledge (e.g., code generation, fixes and refactoring) is implemented in the (Dart) analysis server. The more I think about this task, the more I think that the test code generation part should happen there. Could you give some details about the logic you want to implement?
FYI @scheglov @bwilkerson
jaumard commentedon Jan 7, 2019
Ho that might explain it ! :) but even the text of the action I wasn't able to find it lool because from there I would have been able to follow the white rabbit in the correct class to see its all in analysis server.
What I want to implement in short term is :
In long term I want :
pq commentedon Jan 7, 2019
OK. On second thought this might be more easily done on the client-side.
In the Dart plugin sources,
com.jetbrains.lang.dart.ide.generation.BaseDartGenerateHandler
may be a good place to start looking. Also, maybecom.jetbrains.lang.dart.ide.actions.CreateDartFileAction
.@alexander-doroshko might have ideas too (but may not chime in for a while since he's on vacation)
bwilkerson commentedon Jan 7, 2019
I would strongly urge us to support this via server so that we don't have to do the same work in multiple clients. I believe that this would align nicely with the LSP Code Lens Request, and we could add something similar to the server's protocol.
jaumard commentedon Jan 8, 2019
So bottom line :) better if I wait a bit right ? ^^
pq commentedon Jan 8, 2019
If it's something you'd really like to see happen, I'd suggest opening a bug in the SDK issue tracker (https://github.com/dart-lang/sdk/issues/new) and reference back to this issue so we can track it.
Thanks!
6 remaining items