kiteco / issue-tracker

User-reported issues for Kite
https://Kite.com
1.75k stars 136 forks source link

Start kite daemon for specific filetypes only [vim-plugin] #609

Closed cybardev closed 2 years ago

cybardev commented 3 years ago

I would like to start kite as a daemon process with nvim and terminate the kited process when I exit nvim.

I couldn't find anything online on how to do this (mostly because I probably don't know how to go about looking for it).

It'd be great if someone could help me with achieving this effect.

Currently I have the following function in my .zshrc, but it starts the kite GUI alongside nvim, which I don't want. image

PS: Ideally I'd like this to happen only for Python and Java files, since I want auto completion there. I don't want kite to start when I edit other filetypes (configs, shell scripts, plaintext, etc.)

tonycheang commented 3 years ago

We don't currently support this natively. There are a few things you could try:

cybardev commented 3 years ago

image

Ok, sorry, I just read this. The request for Java was invalid then. I'll use something else for Java.

To terminate the kited process when you exit nvim, try killing the kited process on VimLeave (:h VimLeave)

I've tried the following, but the kited process isn't started automatically now:

image

I can confirm the second command works correctly. If I start kited separately and then edit a python file in nvim, the kite process is automatically terminated on nvim exit.

airblade commented 3 years ago

@cybarspace Try executing the launch command manually, and without suppressing messages, and see if there are any errors:

:execute '!/home/sage/.local/share/kite/kited --plugin-launch &'
cybardev commented 3 years ago

:execute '!/home/sage/.local/share/kite/kited --plugin-launch &'

That started kited but I don't get kite completions by doing this. I tried doing it in same window + same tab, same window + other tab, different window + different tab. Still nothing. pidof kited does confirm that kited process starts.

airblade commented 3 years ago

Going back to your original comment, you can enable support for Java and Python (only) with:

let g:kite_supported_languages = ['java', 'python']

See :help kite-g:kite_supported_languages.

airblade commented 3 years ago

I don't get kite completions by doing this.

Is the BufEnter autocommand present? :au Kite BufEnter

cybardev commented 3 years ago

Is the BufEnter autocommand present? :au Kite BufEnter

It actually wasn't. Thanks. That works. Now, could you please tell me what exactly I need to add to my init.vim config? I'm newb so I'll just copy what you say to the letter.

airblade commented 3 years ago

Launching for specific filetypes is harder since you have to hook into autocmds like BufWinEnter/BufEnter and check if kited is running. vim-plugin doesn't look like it already does this.

@tonycheang The plugin does in fact run on BufEnter. It first checks whether the buffer's language is one it should activate for, and if so launches kited if it's not already running before configuring various things.

... please tell me what exactly I need to add to my init.vim config?

@cybarspace I'm puzzled that the BufEnter autocommand was missing. Please could you check your plugin version with :echo kite#utils#plugin_version()? The current version is 1.0.88.

You should only need this in init.vim:

let g:kite_supported_languages = ['java', 'python']
autocmd VimLeave * call system('kill -TERM $(pidof kited)')

And then open nvim normally.

This will start kited the first time you edit a Java or Python file, leave it running but not doing anything if you edit non-Java, non-Python files, and stop kited when you exit nvim.

cybardev commented 3 years ago

I'm puzzled that the BufEnter autocommand was missing. Please could you check your plugin version with :echo kite#utils#plugin_version()? The current version is 1.0.88.

Mine is 1.0.84

You should only need this in init.vim:

let g:kite_supported_languages = ['java', 'python']
autocmd VimLeave * call system('kill -TERM $(pidof kited)')

This will start kited the first time you edit a Java or Python file, leave it running but not doing anything if you edit non-Java, non-Python files, and stop kited when you exit nvim.

I might be asking for too much but is there any way to prevent kite from running at all on unsupported languages? It's fine if that's not available yet. The main issue is, even if I put those two in init.vim and open a python file, there's no word completion. Should I put autocmd BufEnter * call kite#bufenter() in there manually?

airblade commented 3 years ago

Mine is 1.0.84

It should get updated automatically by Kite but you can always update it manually yourself via git pull.

...is there any way to prevent kite from running at all on unsupported languages?

Not at the moment; nobody has asked for this before ;)

Just to clarify, you would like the background kite process to be launched and killed as you switch between Java/Python and non-Java/Python buffers?

The BufEnter autocommand is put there by the plugin; you don't need to do it yourself. If it's missing, something has gone wrong.

... there's no word completion.

What does :echo g:kite_auto_complete say? Hopefully 1.

Does it work with <C-X><C-U> (ctrl-x ctrl-u) in insert mode?

cybardev commented 3 years ago

It should get updated automatically by Kite but you can always update it manually yourself via git pull.

Mine was installed from the AUR (I'm on Manjaro testing, XFCE + i3wm). There are no updates currently. I'm not sure where I should do git pull

Not at the moment; nobody has asked for this before ;)

Ah, ok. No probs. It's not extremely important. Just feels inefficient to have Kite start even when I'm editing a few bytes of plaintext.

Just to clarify, you would like the background kite process to be launched and killed as you switch between Java/Python and non-Java/Python buffers?

No, that would be heavy on resources, which I'm trying to avoid. Though it wouldn't matter much to me since I'm not a vim power user. I rarely even use tabs, let alone multiple buffers. I just edit one file at a time.

The BufEnter autocommand is put there by the plugin; you don't need to do it yourself. If it's missing, something has gone wrong.

Could it be because Kite is turned off from system startup?

What does :echo g:kite_auto_complete say? Hopefully 1.

It does output 1

Does it work with <C-X><C-U> (ctrl-x ctrl-u) in insert mode?

This shows an error: E764: Option 'completefunc' not set

airblade commented 3 years ago

Mine was installed from the AUR...

Sorry, I don't know what that is. But if you do :filter kite scriptnames you'll see where the plugin is installed; you should be able to go into that directory and git pull.

Just feels inefficient to have Kite start even when I'm editing a few bytes of plaintext.

I agree, but it won't start if the plaintext is neither Python nor Java (or whatever you have configured in g:kite_supported_languages).

Could it be because Kite is turned off from system startup?

No, that wouldn't affect the plugin itself (there's the (neo)vim plugin and also a separate kited process).

The E764 error is caused by the plugin's BufEnter autocommand being missing. Something must be clearing it.

Is your nvim config online somewhere?

cybardev commented 3 years ago

Sorry, I don't know what that is. But if you do :filter kite scriptnames you'll see where the plugin is installed; you should be able to go into that directory and git pull.

AUR is the Arch User Repository. And, that filter command outputs a path but I tried to go to the vim-plugin directory and it seems it isn't installed as a git repo.

I agree, but it won't start if the plaintext is neither Python nor Java (or whatever you have configured in g:kite_supported_languages).

Oh, I didn't know that. That's probably what I wanted anyway. Thanks a lot.

Is your nvim config online somewhere?

Here's my init.vim (click to expand): ```viml set nocompatible | filetype indent plugin on | syn on fun! SetupVAM() let c = get(g:, 'vim_addon_manager', {}) let g:vim_addon_manager = c let c.plugin_root_dir = expand('$HOME', 1) . '/.vim/bundle' " Force your ~/.vim/after directory to be last in &rtp always: " let g:vim_addon_manager.rtp_list_hook = 'vam#ForceUsersAfterDirectoriesToBeLast' " most used options you may want to use: " let c.log_to_buf = 1 " let c.auto_install = 0 let &rtp.=(empty(&rtp)?'':',').c.plugin_root_dir.'/vim-addon-manager' if !isdirectory(c.plugin_root_dir.'/vim-addon-manager/autoload') execute '!git clone --depth=1 git://github.com/MarcWeber/vim-addon-manager ' \ shellescape(c.plugin_root_dir.'/vim-addon-manager', 1) endif " This provides the VAMActivate command, you could be passing plugin names, too call vam#ActivateAddons([], {}) endfun call SetupVAM() call system('wmctrl -i -b add,maximized_vert,maximized_horz -r '.v:windowid) " ACTIVATING PLUGINS "ActivateAddons lh-brackets call plug#begin('~/.vim/bundle') Plug 'joshdick/onedark.vim' let g:onedark_termcolors=16 Plug 'psf/black', { 'branch': 'stable' } "Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' } "Plug 'wfxr/minimap.vim' "Plug 'inkarkat/vim-DeleteTrailingWhitespace' Plug 'artur-shaik/vim-javacomplete2', { 'for': 'java'} Plug 'majutsushi/tagbar', { 'on': ['TagbarToggle'] } Plug 'SirVer/ultisnips' "Plug 'prabirshrestha/asyncomplete.vim' Plug 'scrooloose/nerdtree', { 'on': ['NERDTreeToggle', 'NERDTreeFind'] } "Plug 'w0rp/ale' Plug 'ctrlpvim/ctrlp.vim' "Plug 'neoclide/coc.nvim', {'branch': 'release'} "Plug 'timburgess/extempore.vim' Plug 'dermusikman/sonicpi.vim' "Plug 'congma/vim-cython' Plug 'cybarspace/cython.vim' Plug 'tpope/vim-fireplace' Plug 'tpope/vim-salve' call plug#end() "Use 24-bit (true-color) mode in Vim/Neovim when outside tmux. "If you're using tmux version 2.2 or later, you can remove the outermost $TMUX check and use tmux's 24-bit color support "(see < http://sunaku.github.io/tmux-24bit-color.html#usage > for more information.) if (empty($TMUX)) if (has("nvim")) "For Neovim 0.1.3 and 0.1.4 < https://github.com/neovim/neovim/pull/2198 > let $NVIM_TUI_ENABLE_TRUE_COLOR=1 endif "For Neovim > 0.1.5 and Vim > patch 7.4.1799 < https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162 > "Based on Vim patch 7.4.1770 (`guicolors` option) < https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd > " < https://github.com/neovim/neovim/wiki/Following-HEAD#20160511 > if (has("termguicolors")) set termguicolors endif endif "Minimap settings {{{ "let g:minimap_auto_start = 1 "let g:minimap_block_filetypes = ['fugitive', 'nerdtree', 'tagbar'] "let g:minimap_block_buftypes = ['nofile', 'nowrite', 'quickfix', 'terminal', 'prompt'] "}}} " Don't forget to start deoplete "let g:deoplete#enable_at_startup = 1 " Less spam "let g:deoplete#auto_complete_start_length = 2 " Use smartcase "let g:deoplete#enable_smart_case = 1 " Setup completion sources "let g:deoplete#sources = {} " IMPORTANT: PLEASE INSTALL JAVACOMPLETE2 AND ULTISNIPS OR DONT ADD THIS LINE! " ===================================== "let g:deoplete#sources.java = ['jc', 'javacomplete2', 'file', 'buffer', 'ultisnips'] " ===================================== "use TAB as the mapping "inoremap " \ pumvisible() ? "\" : " \ check_back_space() ? "\" : " \ deoplete#mappings#manual_complete() "function! s:check_back_space() abort "" {{{ " let col = col('.') - 1 " return !col || getline('.')[col - 1] =~ '\s' "endfunction "" }}} " Ctrl-b to open Tagbar map :TagbarToggle "Ctrlp Settings {{{ let g:ctrlp_map = '' let g:ctrlp_cmd = 'ctrlp' let g:ctrlp_dont_split = 'nerd' let g:ctrlp_working_path_mode = 'rw' set wildignore+=*/.git/*,*/tmp/*,*.swp/*,*/node_modules/*,*/temp/*,*/Builds/*,*/ProjectSettings/* " Set no max file limit let g:ctrlp_max_files = 0 " Search from current directory instead of project root function! CtrlPCommand() let c = 0 let wincount = winnr('$') " Don't open it here if current buffer is not writable (e.g. NERDTree) while !empty(getbufvar(+expand(""), "&buftype")) && c < wincount exec 'wincmd w' let c = c + 1 endwhile exec 'CtrlP' endfunction let g:ctrlp_cmd = 'call CtrlPCommand()' " }}} "RipGrep if executable('rg') set grepprg=rg\ --color=never let g:ctrlp_user_command = 'rg %s --files --color=never --glob ""' let g:ctrlp_use_caching = 0 endif let g:ctrlp_custom_ignore = { \ 'dir': '', \ 'file': '\.so$\|\.dat$|\.DS_Store$|\.meta|\.zip|\.rar|\.ipa|\.apk', \ } " }}} "Ale Settings {{{ "let g:ale_echo_msg_error_str = 'E' "let g:ale_echo_msg_warning_str = 'W' "let g:ale_sign_error = '✘' "let g:ale_sign_warning = '⚠' "let g:ale_open_list = 0 "let g:ale_loclist = 0 "let g:ale_javascript_eslint_use_global = 1 "let g:ale_linters = { " \ 'cs':['syntax', 'semantic', 'issues'], " \ 'python': ['black'], " \ 'java': ['javac'] " \ } " }}} autocmd BufWritePre,TextChanged,InsertLeave *.py Black " UltiSnips {{{ " Trigger configuration. Do not use if you use https://github.com/Valloric/YouCompleteMe. let g:UltiSnipsExpandTrigger="" let g:UltiSnipsJumpForwardTrigger="" let g:UltiSnipsJumpBackwardTrigger="" " If you want :UltiSnipsEdit to split your window. "let g:UltiSnipsEditSplit="vertical" let g:UltiSnipsSnippetDirectories = ['~/.vim/UltiSnips', 'UltiSnips'] let g:UltiSnipsSnippetsDir="~/.vim/UltiSnips" " }}} " Java {{{ " Easy compile java in vim autocmd FileType java set makeprg=javac\ % set errorformat=%A%f:%l:\ %m,%-Z%p^,%-C.%# " Java completion autocmd FileType java setlocal omnifunc=javacomplete#Complete autocmd FileType java JCEnable " }}} command Muse execute "!sh -c $HOME/.local/bin/extempore" " switch colon and semi-colon nnoremap ; : nnoremap : ; " navigate wrapped lines nnoremap g nnoremap g nnoremap g nnoremap g vnoremap g vnoremap g vnoremap g vnoremap g " block insert bracket vnoremap ( s()P vnoremap [ s[]P vnoremap { s{}P vnoremap " s""P vnoremap ' s''P " auto complete (), [], {}, "", '' inoremap ( () "inoremap (( ( inoremap () () inoremap [ [] "inoremap [[ [ inoremap [] [] inoremap { {} "inoremap {{ { inoremap {} {} inoremap " "" inoremap "" " inoremap ' '' inoremap '' ' " autocomplete "fun! CleverComplete() " if pumvisible() " return "\" " endif " if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$' " return "\" " elseif exists('&omnifunc') && &omnifunc != '' " return "\\\" " else " return "\\" " endif "endfun "inoremap CleverComplete() "inoremap pumvisible() ? "\a\" : "\" "inoremap pumvisible() ? asyncomplete#close_popup() : "\" " vim stuff set lazyredraw set noswapfile set number set wrap linebreak set tabstop=4 set shiftwidth=4 set mouse=a set expandtab set clipboard+=unnamedplus set omnifunc=syntaxcomplete#Complete set completeopt=longest,noinsert,menuone set colorcolumn=80 highlight ColorColumn ctermbg=7 " kited config let g:kite_supported_languages = ['java', 'python'] autocmd VimLeave * call system('kill -TERM $(pidof kited)') " eclimd config "autocmd FileType java silent execute '!eclimd&' "autocmd VimLeave * call system('kill -TERM $(pidof eclimd)') " sonic-pi let g:sonicpi_enabled = 1 let g:sonicpi_command = 'sonic-pi-tool' let g:sonicpi_send = 'eval-stdin' let g:sonicpi_stop = 'stop' " vim stuff let g:vim_redraw = 1 let g:black_linelength=80 let g:onedark_hide_endofbuffer=1 let g:airline_theme='onedark' syntax on colorscheme onedark ```

PS: I should clean that up, it's a complete mess. Sorry...

airblade commented 3 years ago

I can't see anything in your init.vim that would clear Kite's BufEnter autocmd. So either the plugin isn't being loaded (but it must be because options like g:kite_auto_complete are available) or something else is clearing the autocmd.

You could grep your installed plugins and any other nvim config you have for au! or autocmd!. Or you could start up neovim with nvim -V20log, and grep the log file for BufEnter.

cybardev commented 3 years ago

I actually switched to a different Linux distro and I haven't set up neovim or Kite yet. I will do that soon with a fresh new init.vim from scratch, and post updates here if the issue persists or if it's all fine and was just something wrong with my config.

cybardev commented 2 years ago

Closing because I'm not using Kite anymore. Nothing wrong with it; just not using it.