vim-php-namespace
vim-php-namespace copied to clipboard
Fully qualified namespace not found
Can't seem to insert some use statements for classes.
I have verified that they are indeed in the tags file.
Hi @tonglil,
Could you provide an example (tag file + the file where the class is declared) ?
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.
+1 been getting the same problem for quite a while. I will see if I can recreate the problem.
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":
Here's the generated tags:
https://gist.github.com/dstrunk/f56eb483a829fc95d1e2a90eb43465ec
I'm using Universal ctags (ctags.io), version d9d7aa7
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:
-
This try-catch block
try wincmd P catch /.*/ return endtry 1
The wincmd P does not seem to work. If I comment that out -
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
Hi,
The plugin works like this:
- Use the tagfile to find where the class is declared
- If there are multiple declarations of the same symbol, prompt the user
- Open the class in the preview window
- Find the namespace of the class in the preview window
- 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 ?