Coder Social home page Coder Social logo

Comments (18)

JapSeyz avatar JapSeyz commented on May 18, 2024 2

@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.

bmewburn avatar bmewburn commented on May 18, 2024

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:

  1. start typing
  2. accept a completion item (which expands into an fqn)
  3. 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.

nerdo avatar nerdo commented on May 18, 2024

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.

bmewburn avatar bmewburn commented on May 18, 2024

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.

nerdo avatar nerdo commented on May 18, 2024

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.

jthomaschewski avatar jthomaschewski commented on May 18, 2024

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 -> now use 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.

nerdo avatar nerdo commented on May 18, 2024

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.

bmewburn avatar bmewburn commented on May 18, 2024

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.

nerdo avatar nerdo commented on May 18, 2024

from vscode-intelephense.

greggilbert avatar greggilbert commented on May 18, 2024

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.

bmewburn avatar bmewburn commented on May 18, 2024

use declaration are now added automatically on completion. The manual command remains and has some improvements but has been largely superceeded.

from vscode-intelephense.

greggilbert avatar greggilbert commented on May 18, 2024

@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.

jartaud avatar jartaud commented on May 18, 2024

Same as for @greggilbert

from vscode-intelephense.

bmewburn avatar bmewburn commented on May 18, 2024

@greggilbert, @jartaud your cursor or selection must be on the fully qualified name of the symbol not the whole statement.

from vscode-intelephense.

bmewburn avatar bmewburn commented on May 18, 2024

@JapSeyz is ClientEntityInterface namespaced? If so what is it?

from vscode-intelephense.

JapSeyz avatar JapSeyz commented on May 18, 2024

@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.

JapSeyz avatar JapSeyz commented on May 18, 2024

@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.

sefaYavuz avatar sefaYavuz commented on May 18, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.