artur-shaik / vim-javacomplete2

DEPRECATED in favor of jc.nvim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Trouble Getting AutoComplete Functionality Working

dnMarc opened this issue · comments

Hi All,
I want to start by apologizing for the newb level of this question. I am new to Vim and am very excited to get the javacomplete2 plugin working. I have attempted to get the plugin working by using a pre-configured Docker image (https://hub.docker.com/r/aghost7/nvim). Docker containers spun up from this image contain 3 vim configuration files: init.vim, post-plugin.vim and plugin.vim. I pasted the contents of these files below. I am able to get some of the plugin's features working, but not autocompletion based on valid java methods for given types, instead when I attempt to autocomplete (using Control + n) I simply get a list of words that have already appeared in the .java file I am editing. I see this issue is similar to issue #46. I attempted Control + x followed by Control + o, but I get the following error

E117: Unknown function: javacomplete#complete

I believe I added the required lines discussed in the Configuration directions on the landing page of this repo as you can see in my init.vim and plugin.vim. The long and short of it is that I am trying to get this plugin setup in a docker image so I can spin up containers from anywhere and have this editing environment available. I am by no means wedded to using this particular docker image, but given my lack of knowledge in this area I thought it was a good place to start.

I performed my trials by spinning up a docker container from the image linked above with: docker run -it aghost7/nvim:latest /bin/bash. Once in the container, I updated apt-get and used apt-get to install openjdk-8-jdk. After this I added the lines enclosed in the "DM added" quotes in init.vim. I then created a HelloWorld java file using nvim, and from within nvim I ran PlugUpdate. After this I closed and re-opened nvim on this file and attempted autocompletion with Control+n with the undesired results discussed above. While I don't think it should impact any of this, in the interest of full transparency, I have done all of this inside a tmux session. I checked, and python 2.7.12 is installed (and is on the PATH) @ /usr/bin/python. I am able to see java compiler errors when editing .java files after adding the configuration entries in init.vim and plugin.vim and installing the javacomplete2 plugin, so it appears the plugin is able to communicate with the java compiler.

I checked the version of both vim and nvim and get the following back

NVIM v0.3.1
Build type: Release
LuaJIT 2.0.4
Compilation: /usr/bin/x86_64-linux-gnu-gcc -g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -DDISABLE_LOG -Wdate-time -D_FORTIFY_SOURCE=2 -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wvla -fstack-protector-strong -fdiagnostics-color=auto -Wno-array-bounds -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_UNIBI_HAS_VAR_FROM -I/build/neovim-_bW52a/neovim-0.3.1/build/config -I/build/neovim-_bW52a/neovim-0.3.1/src -I/usr/include -I/build/neovim-_bW52a/neovim-0.3.1/build/src/nvim/auto -I/build/neovim-_bW52a/neovim-0.3.1/build/include
Compiled by team+vim@tracker.debian.org

Features: +acl +iconv +jemalloc +tui 
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

I also checked the Dockerfile for this Docker image, traced back through its inheritance, and it appears to be built on ubuntu:xenial.

I would really appreciate any guidance folks are willing to provide to help me get this up and running.

Thank you all for your help and patience.
Cheers,
Dan

Pasted details are are below.

When I run env I get the following:

_fzf_orig_completion_tee=complete -F %s tee #_longopt
HOSTNAME=824ccdd9dabf
_fzf_orig_completion_javac=complete -F %s javac #_javac
_fzf_orig_completion_diff=complete -F %s diff #_longopt
SHELL=/bin/bash
TERM=screen-256color
DOCKER_CLI_VERSION=18.09.3
_fzf_orig_completion_mv=complete -F %s mv #_longopt
OLDPWD=/home/aghost-7
_fzf_orig_completion_du=complete -F %s du #_longopt
_fzf_orig_completion_bunzip2=complete -F %s bunzip2 #_filedir_xspec
_fzf_orig_completion_less=complete -F %s less #_longopt
_fzf_orig_completion_tail=complete -F %s tail #_longopt
_fzf_orig_completion_rmdir=complete -F %s rmdir #_longopt
_fzf_orig_completion_head=complete -F %s head #_longopt
TMUX_VERSION=2.7
POWERLINE_COMMAND=powerline
LC_ALL=en_US.UTF-8
_fzf_orig_completion_telnet=complete -F %s telnet #_known_hosts
USER=aghost-7
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:
_fzf_orig_completion_wc=complete -F %s wc #_longopt
UBUNTU_RELEASE=xenial
DOCKER_CLI_SHA256=918372dd8cc56616b32b0f67432e2f6b4b27541728d6f9529543a5d73d955100
_fzf_orig_completion_ftp=complete -F %s ftp #_known_hosts
_fzf_orig_completion_view=complete -F %s view #_filedir_xspec
_fzf_orig_completion_grep=complete -F %s grep #_longopt
FZF_DEFAULT_OPTS=--color=light,hl:12,hl+:15,info:10,bg+:4
TMUX=/tmp//tmux-1000/default,125,0
_fzf_orig_completion_gvim=complete -F %s gvim #_filedir_xspec
_fzf_orig_completion_unzip=complete -F %s unzip #_filedir_xspec
PATH=/home/aghost-7/bin:/home/aghost-7/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/aghost-7/.fzf/bin:/home/aghost-7/.local/bin:/root/.local/bin:/home/aghost-7/.local/bin:/root/.local/bin
PWD=/home/aghost-7/dmTest
_fzf_orig_completion_uniq=complete -F %s uniq #_longopt
_fzf_orig_completion_rm=complete -F %s rm #_longopt
_fzf_orig_completion_ls=complete -F %s ls #_longopt
_fzf_orig_completion_cat=complete -F %s cat #_longopt
EDITOR=nvim
LANG=en_US.UTF-8
_fzf_orig_completion_nvim=complete -F %s nvim #_minimal
TMUX_PANE=%0
_fzf_orig_completion_cd=complete -o nospace -F %s cd #_cd
_fzf_orig_completion_vi=complete -F %s vi #_filedir_xspec
SHLVL=2
HOME=/home/aghost-7
XDG_CONFIG_HOME=/home/aghost-7/.config
LANGUAGE=en_US.UTF-8
_fzf_orig_completion_vim=complete -F %s vim #_filedir_xspec
_fzf_orig_completion_awk=complete -F %s awk #_longopt
_fzf_orig_completion_sort=complete -F %s sort #_longopt
_fzf_orig_completion_ld=complete -F %s ld #_longopt
_fzf_orig_completion_gunzip=complete -F %s gunzip #_filedir_xspec
LESSOPEN=| /usr/bin/lesspipe %s
_fzf_orig_completion_emacs=complete -F %s emacs #_filedir_xspec
_fzf_orig_completion_cp=complete -F %s cp #_longopt
LESSCLOSE=/usr/bin/lesspipe %s %s
_fzf_orig_completion_sed=complete -F %s sed #_longopt
_fzf_orig_completion_ln=complete -F %s ln #_longopt
_=/usr/bin/env

init.vim

" ~ NodeJS-Focused Neovim Configuration ~ "
" ~ By: Jonathan Boudreau               ~ "
" ~                                     ~ "

"
"	~~ Plugin Load ~~
"

call plug#begin("~/.config/nvim/plugged")

source ~/.config/nvim/plugin.vim

call plug#end()

"
"	~~ General Configurations ~~
"

"start DM added
autocmd FileType java setlocal omnifunc=javacomplete#complete
nmap <F4> <Plug>(JavaComplete-Imports-AddSmart)
imap <F4> <Plug>(JavaComplete-Imports-AddSmart)
nmap <F5> <Plug>(JavaComplete-Imports-Add)
imap <F5> <Plug>(JavaComplete-Imports-Add)
nmap <F6> <Plug>(JavaComplete-Imports-AddMissing)
imap <F6> <Plug>(JavaComplete-Imports-AddMissing)
nmap <F7> <Plug>(JavaComplete-Imports-RemoveUnused)
imap <F7> <Plug>(JavaComplete-Imports-RemoveUnused)
"end DM added

" don't convert tabs to spaces
set noexpandtab

" Set tabs to take two character spaces
set tabstop=2

" Set how many characters indentation should be. This will ensure that you're
" using tabs, not spaces.
set shiftwidth=2

" Add the column number
set ruler

" Display the row numbers (line number)
set relativenumber

" Make the line number show up in the gutter instead of just '0'.
set number

" Add a bar on the side which delimits 80 characters.
set colorcolumn=80

" 72 characters makes it easier to read git log output.
autocmd Filetype gitcommit setl colorcolumn=72

" Will search the file as you type your query
set incsearch

set t_Co=256

" This will close the current buffer without closing the window
command Bd bp|bd #

" Enable clipboard. Can use x11 forwarding or socket mounting to
" make host clipboard accessible by the container.
set clipboard+=unnamedplus

" Using the blazing fast ag search tool for lgrep calls instead.
set grepprg=ag\ --nogroup\ --nocolor

" For some reason the mouse isn't enabled by default anymore...
set mouse=a

" Annnd, load the plugin-specific configurations.
source ~/.config/nvim/post-plugin.vim

" Folds start as opened instead of closed
set foldlevelstart=99

" Enable folds that are for the most part placed in the comments.
set foldmethod=marker

" Let the linter / formatter take care of additional line breaks and the end
" of the file.
set nofixendofline

plugin.vim

" This file contains configurations which are specific to the plugins
" loaded. Its in a seperate file since these need to be places after the 
" plug#end call.

" DM added
Plug 'artur-shaik/vim-javacomplete2'

" Download a better colorscheme
Plug 'crusoexia/vim-monokai'

" Better file system browser
Plug 'scrooloose/nerdtree'

" Run tests straight from vim
Plug 'janko-m/vim-test'

" Nerdtree git support!
Plug 'Xuyuanp/nerdtree-git-plugin'

" Allows you to run git commands from vim
Plug 'tpope/vim-fugitive'

" Github integration
Plug 'tpope/vim-rhubarb'

" Fuzzy file name searcher
Plug 'kien/ctrlp.vim'

" Adds the ability to close all except the current buffer
Plug 'vim-scripts/BufOnly.vim'

" Unfortunately, neovim doesn't support bindeval, so I can't use powerline.
Plug 'vim-airline/vim-airline'

" Download powerline theme for the statusbar.
Plug 'vim-airline/vim-airline-themes'

" Async linter!
Plug 'w0rp/ale'

" Minimalist mode.
Plug 'junegunn/goyo.vim'

" Required for sql completion
Plug 'vim-scripts/dbext.vim'

" Autocomplete for github names, links, emoji, etc.
Plug 'AGhost-7/github-complete.vim', { 'branch': 'feature-force-emoji', 'for': 'markdown' }

" Better repl integration (sends selections to repl).
Plug 'jpalardy/vim-slime'

" Allows to diff a visual selection.
Plug 'AndrewRadev/linediff.vim'

" For running unit tests written in vimL
Plug 'junegunn/vader.vim'

" Git commit browser
Plug 'junegunn/gv.vim'

" Terraform is used for infrastructure as code management
Plug 'hashivim/vim-terraform'

" better support for ansible stuff
Plug 'pearofducks/ansible-vim'

" Plugin for terraform configurations
Plug 'hashivim/vim-terraform'

" Plugin for jenkinsfile syntax
Plug 'martinda/Jenkinsfile-vim-syntax'

post-plugin.vim (I didn't modify this file at all)

" Use external executable to handle editorconfig files
let g:EditorConfig_exec_path = '/usr/bin/editorconfig'
let g:EditorConfig_core_mode = 'external_command'

" Buffer delete all others (delete all except current one)
command Bdo BufOnly
cabbrev bdo BuffOnly

" Visual diff command.
command Ldiffthis Linediff
cabbrev ldiffthis Linediff

command Ldiffoff Linediffreset
cabbrev ldiffoff LinediffReset

" Load colors! On the initial install this will error out, so make it silent 
" so it installs without issues.
silent! colorscheme monokai

" Add a mapping for the NERDTree command, so you can just type :T to open
command T NERDTree

" abbreviate T to t
cabbrev t T

" Enable the powerline fonts.
let g:airline_powerline_fonts = 1

" Show the buffers at the top
let g:airline#extensions#tabline#enabled = 1

" Show the buffer numbers so I can `:b 1`, etc
let g:airline#extensions#tabline#buffer_nr_show = 1

" Aside from the buffer number, I literally just need the file name, so
" strip out extraneous info.
let g:airline#extensions#tabline#fnamemod = ':t'

" Set the theme for vim-airline
autocmd VimEnter * AirlineTheme powerlineish

let g:NERDTreeMouseMode = 3

" Use spaces instead just for yaml
autocmd Filetype yaml setl expandtab

" Highlighting on top of the error gutter is a bit overkill...
let g:ale_set_highlights = 0

" I want errors to be styled a bit more like neomake
let g:ale_sign_error = '✖'
highlight ALEErrorSign ctermfg=DarkRed ctermbg=NONE

" Same with warnings
let g:ale_sign_warning = '⚠'
highlight ALEWarningSign ctermfg=Yellow ctermbg=NONE

" Force the emoji to show up in the completion dropdown
let g:github_complete_emoji_force_available = 1

" Rely on tmux for the repl integration to work
let g:slime_target = 'tmux'

" This will ensure that the second panel in the current
" window is used when I tell slime to send code to the
" repl.
if exists("$TMUX")
	let s:socket_name = split($TMUX, ',')[0]

	let g:slime_default_config = {
					\ 'socket_name': s:socket_name,
					\ 'target_pane': ':.1'
					\ }
endif

" I dont like the default mappings of this plugin...
let g:slime_no_mappings = 1

" Ctrl+s will send the paragraph over to the repl.
nmap <c-s> <Plug>SlimeLineSend

" Ctrl+x will send the highlighted section over to the repl.
xmap <c-s> <Plug>SlimeRegionSend

" Make it so that ctrlp ignores files in .gitignore
let g:ctrlp_user_command = '(git status --short | awk "{ print \$2 }"; git ls-files -- %s) | sort -u'

function! g:AnsibleDocs() abort
	let word = expand('<cword>')
	new
	setlocal buftype=nofile
	setlocal noswapfile
	nnoremap <buffer> q :bd<cr>
	exe 'read ! ansible-doc' word
	set ft=man
	setlocal nomodifiable
endfunction

autocmd Filetype yaml.ansible nmap <buffer> <C-K> :call g:AnsibleDocs()<CR>

Hello. Sounds like complex setup. Why not you try to start with clean nvim or vim config file?

autocmd FileType java setlocal omnifunc=javacomplete#complete

complete should be in CamelCase: javacomplete#Complete

You need something like YouCompleteMe or deoplete if you want completion to work automatically, and you do not need to press C-xC-o every time.

Hi @artur-shaik,
Thank you very much for your response. Fixing the camel casing in javacomplete#Complete enabled the functionality for me – my apologies for the simple error, I really appreciate you pointing this out for me. I am not familiar with YouCompleteMe or deoplete, but I will give those a try tomorrow.
Thank you again for your help, I really appreciate it.
Cheers,
Dan