Comments (18)
@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.
from vscode-intelephense.
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:
- start typing
- accept a completion item (which expands into an fqn)
- invoke the add use command to condense name and add use decl.
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.
from vscode-intelephense.
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.
from vscode-intelephense.
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 My\Type::fn()
. Will resolve this one in next release
from vscode-intelephense.
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 :(
from vscode-intelephense.
In my case the following does work:
- Start typing
new ClassName
, press enter,new \My\Namespace\ClassName
gets completed - Calling
Add Use Declaration
-> use gets added
This does not work as easy when using the class without new
- e.g for static calls:
- Start typing
ClassName
, press enter,\My\Namespace\ClassName
gets completed - Calling
Add Use Declaration
-> Nothing happens...
Workaround:
- Complete the static call, e.g
\My\Namespace\ClassName::myMethod();
- Select
ClassName
(just pointing the cursor is not enough!) - Call
Add Use Declaration
-> nowuse
is added to the head of the file.
I'm on 0.7.2
. Thanks you for this awesome feature. It's extremely helpful, even in this not 100% convenient state.
from vscode-intelephense.
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.
from vscode-intelephense.
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.
from vscode-intelephense.
from vscode-intelephense.
Just to pile on here a bit, perhaps the feature could be expanded to traverse the entire file and pull all the use
statements to the top?
// before
$x = new \Foo\Bar;
$y = new \Hi\There;
// after
use Foo\Bar;
use Hi\There;
$x = new Bar;
$y = new There;
from vscode-intelephense.
use declaration are now added automatically on completion. The manual command remains and has some improvements but has been largely superceeded.
from vscode-intelephense.
@bmewburn: sorry, I'm not following. Suppose I have this:
class Something
{
public function __construct()
{
$this->x = new \Symfony\Component\HttpKernel\Tests\Controller();
}
}
How do you get the use
statement to be added? The "Add Use Declaration" function doesn't seem to work for me. Here's a screen recording: https://cl.ly/0g1Y3c3J2K27
from vscode-intelephense.
Same as for @greggilbert
from vscode-intelephense.
@greggilbert, @jartaud your cursor or selection must be on the fully qualified name of the symbol not the whole statement.
from vscode-intelephense.
@JapSeyz is ClientEntityInterface
namespaced? If so what is it?
from vscode-intelephense.
@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.
from vscode-intelephense.
@bmewburn I've tried to manually add *.php files to the file association block in settings. I'll let you know if it works
from vscode-intelephense.
@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.
@bmewburn This is not working for me aswell.
from vscode-intelephense.
Related Issues (20)
- v1.10.2 not working on macOS HOT 2
- "Expected iterable, found xxx" when splatting
- Latest version of either VSCode (1.85.1) or Intelephense (1.10.2) marks PHP internals as not defined
- Workspace indexing stops after a few files. no errors displayed
- Expected type 'string'. Found 'DefaultKey'.intelephense(P1006)
- Support for Interface/Trait return self type HOT 2
- Syntax error for first class callables HOT 2
- isset() doesn't have a link to the php manual in the tooltip popup
- Missing Wordpress functions
- Initialize readonly property from Trait - P1056
- Project/directory level exclude
- Stop working in WSL HOT 2
- Line break in docs
- Generic type for method in abstract class cause error "Expected type 'X'. Found 'T'"
- Method with generic type in trait used in abstract class does not work.
- Variables first defined in switch statements have no warning when used later HOT 2
- Docs line break problems HOT 1
- Go to method implementations support implement by trait.
- v1.10.x not working on macOS HOT 1
- Is that .phpstorm.meta.php not working in v1.10? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vscode-intelephense.