Permalink
Browse files

When in global namespace, use the detected namespace instead of curre…

…nt one

When completing in global namespace, the plugin should use the completed
symbol's own namespace as a starting point instead of the current (global)
one.

Fixes #87
  • Loading branch information...
1 parent 9a0c44f commit 01f6f60f282b902c1e871920894e57e51a53ef9a @complex857 complex857 committed May 5, 2016
@@ -1946,9 +1946,10 @@ function! phpcomplete#GetClassName(start_line, context, current_namespace, impor
let sub_methodstack = phpcomplete#GetMethodStack(matchstr(line, '^\s*'.object.'\s*=&\?\s*\s\+\zs.*'))
let [classname_candidate, class_candidate_namespace] = phpcomplete#GetCallChainReturnType(
\ classname,
- \ a:current_namespace,
+ \ namespace_for_class,
\ a:imports,
\ sub_methodstack)
+
return (class_candidate_namespace == '\' || class_candidate_namespace == '') ? classname_candidate : class_candidate_namespace.'\'.classname_candidate
endif
endif
@@ -390,7 +390,7 @@ endf
fun! TestCase_returns_static_function_calls_retun_type_with_namespaces()
call SetUp()
- let imports = {'P':{'name': 'Foo\Page', 'builtin': 0, 'kind': 'c'}, 'RenamedFoo':{'name': 'Foo', 'kind': 'n', 'builtin': 0, }}
+ let imports = {'P': {'name': 'Page', 'namespace': 'Foo', 'kind': 'c', 'builtin': 0}, 'RenamedFoo': {'name': 'Foo', 'kind': 'n', 'builtin': 0}}
exe 'set tags='.expand('%:p:h').'/'.'fixtures/GetClassName/static_docblock_return_tags'
let path = expand('%:p:h').'/'.'fixtures/GetClassName/static_docblock_namespaced.php'
below 1new
@@ -427,6 +427,22 @@ fun! TestCase_returns_static_function_calls_retun_type_with_namespaces()
silent! bw! %
endf
+fun! TestCase_returns_static_function_calls_retun_type_with_namespaces_from_the_global_scope()
+ call SetUp()
+
+ let imports = {'Page': {'name': 'Page', 'namespace': 'Foo', 'kind': 'c', 'builtin': 0}}
+ exe 'set tags='.expand('%:p:h').'/'.'fixtures/GetClassName/static_docblock_namespaced_tags'
+ let path = expand('%:p:h').'/'.'fixtures/GetClassName/static_docblock_namespaced_imported.php'
+ below 1new
+ exe ":silent! edit ".path
+
+ exe ':5'
+ let classname = phpcomplete#GetClassName(5, '$p->', '', imports)
+ call VUAssertEquals('Foo\Page', classname)
+
+ silent! bw! %
+endf
+
fun! TestCase_resolves_call_chains_return_type_with_this()
call SetUp()
@@ -0,0 +1,5 @@
+<?php
+use Foo\Page;
+
+$p = Page::getPage();
+$p->
@@ -0,0 +1,19 @@
+!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
+!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
+!_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/
+!_TAG_PROGRAM_NAME Exuberant Ctags //
+!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
+!_TAG_PROGRAM_VERSION Development //
+Foo static_docblock_namespaced.php /^namespace Foo;$/;" n
+Page static_docblock_namespaced.php /^class Page {$/;" c namespace:Foo
+getPage static_docblock_namespaced.php /^ public static function getPage(){$/;" f class:Foo::Page access:public signature:()
+getPage2 static_docblock_namespaced.php /^ public static function getPage2(){$/;" f class:Foo::Page access:public signature:()
+getRenamedPage static_docblock_namespaced.php /^ public static function getRenamedPage(){$/;" f class:Foo::Page access:public signature:()
+getRenamedPage2 static_docblock_namespaced.php /^ public static function getRenamedPage2(){$/;" f class:Foo::Page access:public signature:()
+p static_docblock_namespaced.php /^$p = P::getPage();$/;" v namespace:Foo
+p static_docblock_namespaced.php /^$p = Page::getPage();$/;" v namespace:Foo
+p static_docblock_namespaced.php /^$p = Page::getPage2();$/;" v namespace:Foo
+p static_docblock_namespaced.php /^$p = Page::getRenamedPage();$/;" v namespace:Foo
+p static_docblock_namespaced.php /^$p = Page::getRenamedPage2();$/;" v namespace:Foo
+p static_docblock_namespaced.php /^$p = RenamedFoo\\Page::getPage();$/;" v namespace:Foo
+p static_docblock_namespaced.php /^$p = \\Foo\\Page::getPage();$/;" v namespace:Foo

0 comments on commit 01f6f60

Please sign in to comment.