Skip to content
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

Closed

Conversation

FatBoyXPC
Copy link

@FatBoyXPC FatBoyXPC commented Jul 28, 2019

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:

2019-07-28_06:43:19_fatboyxpc


if !empty(get(a:completedItem, "info", ""))
call phpactor#rpc("import_class", {
\ "qualified_name": a:completedItem['info'],
Copy link
Collaborator

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

Copy link
Author

@FatBoyXPC FatBoyXPC Jul 28, 2019

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.

@dantleech
Copy link
Collaborator

dantleech commented Jul 28, 2019

Looks good :) I will try it out when I'm back home ... @roxma does this look correct to you?

@FatBoyXPC
Copy link
Author

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.

@dantleech
Copy link
Collaborator

dantleech commented Jul 29, 2019 via email

Copy link
Collaborator

@dantleech dantleech left a 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)
Copy link
Collaborator

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
Copy link
Collaborator

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)

@FatBoyXPC
Copy link
Author

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?

@FatBoyXPC
Copy link
Author

I'm closing this as I don't use ncm2 anymore.

@FatBoyXPC FatBoyXPC closed this May 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants