vim-php-namespace icon indicating copy to clipboard operation
vim-php-namespace copied to clipboard

Fully qualified namespace not found

Open tonglil opened this issue 9 years ago • 6 comments

Can't seem to insert some use statements for classes.

I have verified that they are indeed in the tags file.

tonglil avatar Jun 11 '15 18:06 tonglil

Hi @tonglil,

Could you provide an example (tag file + the file where the class is declared) ?

arnaud-lb avatar Jun 12 '15 12:06 arnaud-lb

Yes, when it happens again I will provide the directory structure, the file, and the tag file.

I might have to redact some things though but we shall see. If I do, I will say what.

tonglil avatar Jun 23 '15 17:06 tonglil

+1 been getting the same problem for quite a while. I will see if I can recreate the problem.

mikedfunk avatar Jul 15 '15 05:07 mikedfunk

I'm getting this issue in a new Laravel project. I've recorded a screencap to show what exactly is happening in my case. For demonstration purposes, I removed the tags file and regenerated it manually. To demonstrate that the plugin works on certain files, I added the namespace of the class directly in the file. Then I attempted to add the same namespace to a file within tests/Unit, after which I got the "Fully qualified namespace not found":

php-namespace-post

Here's the generated tags:

https://gist.github.com/dstrunk/f56eb483a829fc95d1e2a90eb43465ec

I'm using Universal ctags (ctags.io), version d9d7aa7

dstrunk avatar Oct 20 '17 01:10 dstrunk

Same error message. I am running NVIM v0.4.3 on Ubuntu 18.04 and create my tags file using Universal Ctags which I have built rather than snap installed. While trying to insert a Use Statement I seem to run into two problems inside the PhpFindFqn(name) function:

  1. This try-catch block try wincmd P catch /.*/ return endtry 1 The wincmd P does not seem to work. If I comment that out

  2. These if-statements:

        if search('^\s*\%(/\*.*\*/\s*\)\?\%(\%(abstract\|final\)\_s\+\)*\%(class\|interface\|trait\)\_s\+' . a:name . '\>') > 0
            if search('^\%(<?\%(php\s\+\)\?\)\?\s*namespace\s\+', 'be') > 0
                let start = col('.')
                call search('\([[:blank:]]*[[:alnum:]\\_]\)*', 'ce')
                let end = col('.')
                let ns = strpart(getline(line('.')), start, end-start)
                return ['class', ns . "\\" . a:name]
            else
                return ['class', a:name]
            endif
        elseif search('^\s*function\_s\+' . a:name . '\>') > 0
            if search('^\%(<?\%(php\s\+\)\?\)\?\s*namespace\s\+', 'be') > 0
                let start = col('.')
                call search('\([[:blank:]]*[[:alnum:]\\_]\)*', 'ce')
                let end = col('.')
                let ns = strpart(getline(line('.')), start, end-start)
                return ['function', ns . "\\" . a:name]
            else
                return a:name
            endif

        else
            throw a:name . ": not found!"
        endif

do throw a:name . ": not found!" so I figure the regex does not fit may tags file. I am running this inside a test project trying to insert an import for the HomeService (so I shortend the tags file contents):

430-0	composer.json	/^        {$/;"	o	array:authors
478-HomeHandler	src/Handler/HomeHandler.php	/^class HomeHandler$/;"	c	namespace:WithoutForm\\Test\\Handler
581:HomeService	src/Service/HomeService.php	/^class HomeService$/;"	c	namespace:WithoutForm\\Test\\Service
684-WithoutForm\\\\Test\\\\	composer.json	/^        "WithoutForm\\\\Test\\\\": "src\/"$/;"	s	object:autoload.psr-4
795:__construct	src/Handler/HomeHandler.php	/^    public function __construct(HomeService $homeService)$/;"	f	class:WithoutForm\\Test\\Handler\\HomeHandler
947:__construct	src/Service/HomeService.php	/^    public function __construct()$/;"	f	class:WithoutForm\\Test\\Service\\HomeService
1075-authors	composer.json	/^    "authors": [$/;"	a
1122-autoload	composer.json	/^    "autoload": {$/;"	o

romanhandke avatar Dec 08 '19 09:12 romanhandke

Hi,

The plugin works like this:

  1. Use the tagfile to find where the class is declared
  2. If there are multiple declarations of the same symbol, prompt the user
  3. Open the class in the preview window
  4. Find the namespace of the class in the preview window
  5. Close the preview window

The error fully qualified class name was not found is not displayed when steps 1-3 fail, so they were probably successful here.

Could you provide a php file and a tag file where this can be reproduced ?

arnaud-lb avatar Dec 08 '19 10:12 arnaud-lb