-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
How do you use the "Add Use Declaration" command? #15
Comments
Unfortunately there's no docs. It may differ a little from sublime. The approach I took was that the add use command can be invoked on any name that is a fully qualified name or can be resolved to an fqn. If the cursor is not on or immediately after the name, or if the symbol corresponding to the fqn can not be found or is ambiguous, then nothing happens. The idea was that it would fit into the following flow:
There's a few edge cases that are not handled yet for example if a use decl already exists it will use the existing decl. even if you have entered a different alias. If you're still having trouble with it, send a short example, it may be a bug that needs resolving. |
Your flow actually makes perfect sense. But I've tried it to no avail. I don't really have a simple code example, but I've done a screen recording within a Laravel project showing how I'm using it and what actually happens. http://g.recordit.co/mq6tzRV4v5.gif It may be worth noting that I'm using amVim as a Vim emulator within VSCode, but I did try disabling it and had the same results. Let me know if you need anything else to resolve it. |
Thanks for the example. Looks like theres a bug where it treats incomplete expressions as constants and therefore can't find the actual symbol. It should still work where the expression is complete eg |
I just tried it again with a "complete" expression, but with the same results. It doesn't seem to matter if I just have a namespace, or \My\Namespace::method(). I've tried invoking the command at the end of the method, putting the cursor on the namespace, with/without semicolons at the end of the statement, highlighting the namespace and the entire expression - all yield the same result. It's worth noting that I just updated to Intelephense 0.7.2 and tried these - so I'm not sure if the fix was in that version, but, for whatever reason, it just refuses to work for me. Is there a way I can provide some sort of debug output to help resolve the issue? If I had more time, I'd just contribute to the codebase myself, but time is always an issue :( |
In my case the following does work:
This does not work as easy when using the class without
Workaround:
I'm on |
Thanks for the clarification jbbr. It indeed does work when used that way. I agree it is pretty wonky the way it currently works, and it is a little bit more convenient than the way I was adding use statements before, but it will be a huge time saver once it's working well. I would even go as far as saying that if there were a hotkey for selecting a namespace when the list pops up (e.g. hitting command/super enter instead of enter to add the use declaration instead of just inserting the entire name), that would make the need for having a separate hotkey unnecessary 99% of the time. The other 1% is the usefulness of the popup for specifying an alias. Most of the time, I find that I will just use the class name as-is. |
Thanks for the further analysis, I'll give this a cleanup in v0.8.0 and put a setting in to enable the use declarations to happen automatically when a completion item is selected. |
Nice.
FYI, I just came across this plugin, and it does *exactly* what I was
looking for (including the extra features, like sorting the imports).
https://marketplace.visualstudio.com/items?itemName=MehediDracula.php-namespace-resolver
Would be nice to have one less plugin to install though :)
…On Wed, Jul 12, 2017 at 7:48 PM, Ben Mewburn ***@***.***> wrote:
Thanks for the further analysis, I'll give this a cleanup in v0.8.0 and
put a setting in to enable the use declarations to happen automatically
when a completion item is selected.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#15 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA-9TjNgSiYKyDDU7DmCE0sqKp0TtpdIks5sNVtlgaJpZM4OJTPJ>
.
|
Just to pile on here a bit, perhaps the feature could be expanded to traverse the entire file and pull all the
|
use declaration are now added automatically on completion. The manual command remains and has some improvements but has been largely superceeded. |
@bmewburn: sorry, I'm not following. Suppose I have this:
How do you get the |
Same as for @greggilbert |
@greggilbert, @jartaud your cursor or selection must be on the fully qualified name of the symbol not the whole statement. |
@bmewburn The "Add use declaration" function is also completely broken for me. https://gfycat.com/gifs/detail/MindlessEmotionalHypacrosaurus The "alias" bar shows up, but nothing ever happens when I press enter, regardless of an alias being entered or not. |
@JapSeyz is |
@bmewburn The correct path is: use League\OAuth2\Server\Entities\ClientEntityInterface; I just bound it to alt+enter, but right-clicking or selecting it, or ctrl+shift+p yields no result either. |
@bmewburn I've tried to manually add *.php files to the file association block in settings. I'll let you know if it works |
@bmewburn This is not working for me aswell. |
I originally wrote a review of this plugin and in it, I mentioned a Sublime PHP Companion feature that I would love to see in this plugin. It has been added (thanks!), but I'm either not using it correctly, or it doesn't seem to work.
I have the new command bound to a key. I've tried starting to type a class name and hitting the hotkey for Add Use Declaration. It does pop up a dialog to enter an alias for the class (a nice feature that isn't available with Sublime PHP Companion as far as I know), but nothing happens.
I've also tried expanding the class name and hitting the hotkey. highlighting it and doing the same - all with the same result.
Is there some documentation on how to use the Add Use Declaration feature? What is the correct way to use it?
The text was updated successfully, but these errors were encountered: