Auto-import after code completion

88 views
Skip to first unread message

Paul Schyska

unread,
May 15, 2012, 6:21:37 AM5/15/12
to eclim-user
Hey,

I have a minor but annoying Problem with auto-completion in vim. When
I auto-complete a class name it is not auto-imported and that breaks
my workflow. Consider this:

SomeFac|<C-x><C-u>
SomeFactory.<C-x><C-u>

it will not show any completions after the . because the class is not
imported yet. I have to move back and issue a JavaImport and then move
forward again to get completion.
I'm doing this regularly, because I work with an API that makes heavy
use of static methods (Liferay :-p)

Is there a vim-only way to issue a JavaImport after completion?
JavaImportMissing doesn't seem to work because in that state there is
a syntax error in the file.

Thanks & Cheers,

Paul

JSelk

unread,
May 16, 2012, 11:32:40 AM5/16/12
to eclim-user
I'd also like to see a solution to this as I think it's a pretty
useful piece of functionality.

Eric Van Dewoestine

unread,
May 16, 2012, 11:34:37 AM5/16/12
to eclim...@googlegroups.com
After playing around with this some yesterday and again this morning,
I was all set to send a response that this can't be done with vim's
completion mechanism, until I thought of a somewhat hacky way to make
it work. I implemented a proof of concept, hard coding what needed to
be imported, and got it working nicely. So now I need need to go back
and update the code to find the proper type to import.

What I'm doing is that when you attempt any code completion, I'll have
the eclim command check if the variable's type, or in your case the
type you're attempting to complete static members from, is imported or
not. If not, I'll have the command send back the type that needs to be
imported to the vim completefunc which will then handle the import
just like :JavaImport, and then resend the completion request.

It's going to take me some time to get this all working properly, but
I'll let you know when I have something worth testing.

--
eric

Eric Van Dewoestine

unread,
May 17, 2012, 10:07:35 PM5/17/12
to eclim...@googlegroups.com
I just checked in a change[1] to add support for importing an
unresolved type during code completion.

[1] https://github.com/ervandew/eclim/commit/d98a2726c49570d5e72fb826ca5c7f011c46b167

--
eric
Reply all
Reply to author
Forward
0 new messages