-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add auto import upon class completion #23
Add auto import upon class completion #23
Conversation
|
||
if !empty(get(a:completedItem, "info", "")) | ||
call phpactor#rpc("import_class", { | ||
\ "qualified_name": a:completedItem['info'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think info
is the wrong thing to use? It's not guaranyeed to have the FQN. Instead you can use the class_import
key which is dedicated to this purpose: https://github.com/phpactor/phpactor/blob/develop/plugin/phpactor.vim#L133
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately the class_import
key isn't available to the completedItem
. That said, I might be able to stuff it into the python and have it come back. Let me see.
Edit: I'm unable to get class_import
into the completedItem
by stuffing it into the item
dict or item['user_data']
. I wish I knew more about the ncm2 python <-> vim communication.
Out of curiosity, why isn't it guaranteed to be fully qualified? In all the testing/playing I did, it was.
Looks good :) I will try it out when I'm back home ... @roxma does this look correct to you? |
Oh, maybe @roxma can also tell me of a way to keep the menu closed until another character is typed? I personally don't mind the behavior, but I imagine some people would find it irritating. |
It's something to show in the menu, it doesn't have to be a class name, it just happens that that's what we use currently, but it could f.e. be abbreviated, have more information, or have markup in it etc.
…On 29 July 2019 00:29:27 EEST, James LaChance ***@***.***> wrote:
FatBoyXPC commented on this pull request.
> @@ -45,3 +45,28 @@ func! ncm2_phpactor#on_complete(ctx)
\ ])
endfunc
+function! ncm2_phpactor#_completeImportClassFromNcm2(completedItem)
+
+ if !has_key(a:completedItem, "word") || !has_key(a:completedItem,
"user_data")
+ return
+ endif
+
+ let user_data = json_decode(a:completedItem['user_data'])
+
+ if (user_data['source'] !=# "phpactor")
+ return
+ endif
+
+ if !empty(get(a:completedItem, "info", ""))
+ call phpactor#rpc("import_class", {
+ \ "qualified_name": a:completedItem['info'],
Unfortunately the `class_import` key isn't available to the
`completedItem`. That said, I might be able to stuff it into the python
and have it come back. Let me see.
Out of curiosity, why isn't it guaranteed to be fully qualified? In all
the testing/playing I did, it was.
--
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
#23 (comment)
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and seems good enough to me -- if we add a new configuration option then it's fine if it's not perfect, we can always improve it later :)
Otherthan the comments below, can we also update the doc with the new option somehow?
Thanks for this, looking forward to using it :)
@@ -45,3 +45,28 @@ func! ncm2_phpactor#on_complete(ctx) | |||
\ ]) | |||
endfunc | |||
|
|||
function! ncm2_phpactor#_completeImportClassFromNcm2(completedItem) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
guess we should be using snake case here (for method name and param)? and maybe it's fine to call this ncm2_phpactor#import_class_on_complete
or similar
|
||
endfunction | ||
|
||
if g:phpactorOmniAutoClassImport == v:true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a new configuration option? ncm2_phpactor_auto_import_class
(as in autoload/ncm2_phpactor.vim
)
We don't want to use this info key after all. I'm getting some weird bugs when choosing a variable through autocompletion, and the pum has the info for the fqcn in it. I had some weird bugs with a few functions, too. I think I might need some help in reporting extra keys back to ncm2 from phpactor, maybe @roxma could help? |
I'm closing this as I don't use ncm2 anymore. |
The current behavior of this is that the pop up menu will open back up after the import statement is added. This seems annoying at first, but it's nice in that it allows you to start typing
::
if you'd like to access a static method. I'm not sure if there's a way to keep it closed afterwards as it opens on insert mode automatically. If this is undesired I might need some help in exploring those options, and we could tuck that behavior behind another boolean vimrc variable.Looks like this affects #8 and possibly #17 as well.
Here's a GIF of this in action: