PhpStorm plugin for autocompletions
From https://github.com/artspb/phpstorm-library-plugin I gather it's possibe to create a super simple plugin for autocompletions. No JDK needed, just text files in a ZIP.
But I can't get it to work. That demo plugin doesn't work, nor with any changes I make to it. Always the same error:
> Fail to load plugin descriptor from file my-plugin.zip
This demo plugin does work: https://plugins.jetbrains.com/plugin/8136-navmine-demo but it's set up completely different. I don't want to write Java classes. I don't need logic, just some PHP classes that PS will read.
I'm using PhpStorm 2017.4
Nothing in the logs when it fails to install.
Please sign in to leave a comment.
I've found an even easier way, by including a custom External Library. I don't think it needs an XML with metadata etc. Just a PHP file with all my classes.
Actually, an External Library isn't perfect, because now all my classes exist twice, and I get the "Multiple implementations" notice a lot. I can ignore that notice, but clicking through doesn't know which class to open: the real class or the library.
So I'd still love to know how to make an actual plugin from this.
First of all, the plugin extension should be .jar, not .zip. Also please check that the archive doesn't contain the plugin directory itself but only its content. If it doesn't help please provide the step by step description of what you've done to build your plugin.
Renaming it to .jar works... Huh. I'm pretty sure I started with that. My bad!
This solution is as imperfect as the External Library though, because it defines every class twice. I'm not really using an external library, I just want a huge collection of class properties. They can be extracted from project code, but I've no idea how PhpStorm would do that dynamically, on the fly, without external library.
Are there are plugin demos that define/expose magic class properties and methods? (In Java I assume.) I could only find https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata but I don't think that's advanced enough, or too advanced. I don't see how I define class properties with that syntax.
Sorry, I don't get what you're trying to achieve. Could you please describe it a bit more detailed maybe using an example.
Sorry. What I'm trying to do is give my project classes automatic `@property Type $name`, but not as actual comments. They come from magic getters (`protected function get_name()`) and relationships (`protected static $relationships = array('name' => ....)`) (also via magic getters). For example:
class User {
static protected $relationships = array(
'memberships' => array(self::MANY, Membership::class, 'user_id'),
);
/** @return Membership */
protected function get_active_membership() {
foreach ($this->memberships as $ms) {
if ($ms->active) return $ms;
}
}
}
Those are both types of magic getters. What I've done now, with decent result, is create a compiler in PHP that extracts all those properties ('memberships' and 'active_membership') and adds them to an external library class:
class User {
/** @var Membership[] */
public $memberships;
/** @var Membership */
public $active_membership;
}
The problems with that:
1. I have to recompile when I change magic getters, which is not too bad
2. Every class exists twice, so when I click on User in my project, it asks me where I want to go, because "Multiple implementations exist".
Is there a way PhpStorm takes properties from my fake classes, but only go to the real class for logic and methods.
Unfortunately, it's not possible for now. Please vote for the issue to track its state https://youtrack.jetbrains.com/issue/WI-29909
"You have no permissions to view this page" =( I am very curious now.
This must be possible with a real Java plugin. Right? Some plugins do some amazing magic. That's fine too. Where can I get some info on real plugin dev?
Issue page is available to everyone, please try again.
So far there is no easy way to modify existing class definition, neither with "metadata" or java code, but we're planning to make this possible with metadata soon.
Please vote/comment/watch the issue.
WI-29909 is exactly what I want. 18 months old and no comments though...
The External Library solution doesn't even work in PhpStorm 2017.2 anymore... (Some files don't even have any inspections, but that seems like another bug.) All my class properties in the External Library aren't detected anymore, so there's zero useful autocomplete now =(
The log is full of:
java.lang.StackOverflowError
at gnu.trove.TObjectHash.insertionIndex(TObjectHash.java:224)
at gnu.trove.THashSet.add(THashSet.java:137)
at com.jetbrains.php.PhpIndexImpl.completeType(PhpIndexImpl.java:120)
at com.jetbrains.php.lang.psi.resolve.types.PhpType.global(PhpType.java:441)
at com.jetbrains.php.PhpIndexImpl.completeThis(PhpIndexImpl.java:85)
at com.jetbrains.php.PhpIndexImpl.completeThis(PhpIndexImpl.java:92)
at com.jetbrains.php.PhpIndexImpl.completeThis(PhpIndexImpl.java:86)
at com.jetbrains.php.PhpIndexImpl.completeThis(PhpIndexImpl.java:92)
at com.jetbrains.php.PhpIndexImpl.completeThis(PhpIndexImpl.java:86)
at com.jetbrains.php.PhpIndexImpl.completeThis(PhpIndexImpl.java:92)
... ~3000 more lines like this, and then another StackOverflowError
This SOE is already fixed, should be available in this week's EAP.
SOE? When is it in stable? EAP doesn't sound very safe...
SOE = StackOverflowError
Currently EAP is basically what you will get in 2017.2.1 couple of weeks later. You can try or wait.
Where do I opt in EAP? I've tried https://www.jetbrains.com/toolbox/app/ but there isn't any EAP in there... Can't find anything else. I really don't know what https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Early+Access+Program is...
EAP's are published each Wednesday so you have to wait until tomorrow noon. Should be visible in toolbox.