diff --git a/README.md b/README.md index b868749b..720812c7 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ let g:codeium_disable_bindings = 1 or in Neovim: -```lua +```vim vim.g.codeium_disable_bindings = 1 ``` @@ -91,10 +91,10 @@ use { 'Exafunction/codeium.vim', config = function () -- Change '' here to any keycode you like. - vim.keymap.set('i', '', function () return vim.fn['codeium#Accept']() end, { expr = true, silent = true }) - vim.keymap.set('i', '', function() return vim.fn['codeium#CycleCompletions'](1) end, { expr = true, silent = true }) - vim.keymap.set('i', '', function() return vim.fn['codeium#CycleCompletions'](-1) end, { expr = true, silent = true }) - vim.keymap.set('i', '', function() return vim.fn['codeium#Clear']() end, { expr = true, silent = true }) + vim.keymap.set('i', '', function () return vim.fn['codeium#Accept']() end, { expr = true }) + vim.keymap.set('i', '', function() return vim.fn['codeium#CycleCompletions'](1) end, { expr = true }) + vim.keymap.set('i', '', function() return vim.fn['codeium#CycleCompletions'](-1) end, { expr = true }) + vim.keymap.set('i', '', function() return vim.fn['codeium#Clear']() end, { expr = true }) end } ``` @@ -116,21 +116,27 @@ let g:codeium_filetypes = { Codeium is enabled by default for most filetypes. -You can also _disable_ codeium by default with the `g:codeium_enabled` -variable: +You can also _disable_ codeium by default with the `g:codeium_enabled` variable, +and enable it manually per buffer by running `:CodeiumEnable`: ```vim let g:codeium_enabled = v:false ``` -or in Neovim: +Or you can disable codeium for _all filetypes_ with the `g:codeium_filetypes_disabled_by_default` variable, +and use the `g:codeium_filetypes` variable to selectively enable codeium for specified filetypes: -```lua -vim.g.codeium_enabled = false +```vim +" let g:codeium_enabled = v:true +let g:codeium_filetypes_disabled_by_default = v:true + +let g:codeium_filetypes = { + \ "rust": v:true, + \ "typescript": v:true, + \ } ``` -Instead, if you would like to just disable the automatic triggering of -completions: +If you would like to just disable the automatic triggering of completions: ```vim let g:codeium_manual = v:true @@ -138,9 +144,8 @@ let g:codeium_manual = v:true ### Show Codeium status in statusline -Codeium status can be generated by calling the `codeium#GetStatusString()` function. In -Neovim, you can use `vim.api.nvim_call_function("codeium#GetStatusString", {})` instead. -It produces a 3 char long string with Codeium status: +Codeium status can be generated by calling `codeium#GetStatusString()` function. +It produce 3 char long string with status: - `'3/8'` - third suggestion out of 8 - `'0'` - Codeium returned no suggestions - `'*'` - waiting for Codeium response diff --git a/autoload/.DS_Store b/autoload/.DS_Store new file mode 100644 index 00000000..20413a1d Binary files /dev/null and b/autoload/.DS_Store differ diff --git a/autoload/codeium.vim b/autoload/codeium.vim index 5c268bbe..03138963 100644 --- a/autoload/codeium.vim +++ b/autoload/codeium.vim @@ -21,7 +21,11 @@ function! codeium#Enabled() abort let codeium_filetypes = s:default_codeium_enabled call extend(codeium_filetypes, get(g:, 'codeium_filetypes', {})) - if !get(codeium_filetypes, &filetype, 1) + call extend(codeium_filetypes, {'': 1}) " `''` should be forced to `1`, otherwise codeium may be unable start. + + let codeium_filetypes_disabled_by_default = get(g:, 'codeium_filetypes_disabled_by_default') || get(b:, 'codeium_filetypes_disabled_by_default') + + if !get(codeium_filetypes, &filetype, !codeium_filetypes_disabled_by_default) return v:false endif diff --git a/autoload/codeium/server.vim b/autoload/codeium/server.vim index 49019675..124dd409 100644 --- a/autoload/codeium/server.vim +++ b/autoload/codeium/server.vim @@ -1,5 +1,5 @@ -let s:language_server_version = '1.6.28' -let s:language_server_sha = 'f485965568948013d9f47815917f2f1f3a99089d' +let s:language_server_version = '1.2.104' +let s:language_server_sha = 'ab59278dfa738977096f6bfc2299d9941fcc3252' let s:root = expand(':h:h:h') let s:bin = v:null @@ -31,7 +31,7 @@ function! s:OnExit(result, status, on_complete_cb) abort let did_close = has_key(a:result, 'closed') if did_close call remove(a:result, 'closed') - call a:on_complete_cb(a:result.out, a:result.err, a:status) + call a:on_complete_cb(a:result.out, a:status) else " Wait until we receive OnClose, and call on_complete_cb then. let a:result.exit_status = a:status @@ -41,7 +41,7 @@ endfunction function! s:OnClose(result, on_complete_cb) abort let did_exit = has_key(a:result, 'exit_status') if did_exit - call a:on_complete_cb(a:result.out, a:result.err, a:result.exit_status) + call a:on_complete_cb(a:result.out, a:result.exit_status) else " Wait until we receive OnExit, and call on_complete_cb then. let a:result.closed = v:true @@ -65,7 +65,7 @@ function! codeium#server#Request(type, data, ...) abort if s:server_port is# v:null throw 'Server port has not been properly initialized.' endif - let uri = 'http://127.0.0.1:' . s:server_port . + let uri = 'http://localhost:' . s:server_port . \ '/exa.language_server_pb.LanguageServerService/' . a:type let data = json_encode(a:data) let args = [ @@ -73,13 +73,12 @@ function! codeium#server#Request(type, data, ...) abort \ '--header', 'Content-Type: application/json', \ '-d@-' \ ] - let result = {'out': [], 'err': []} + let result = {'out': []} let ExitCallback = a:0 && !empty(a:1) ? a:1 : function('s:NoopCallback') if has('nvim') let jobid = jobstart(args, { \ 'on_stdout': { channel, data, t -> add(result.out, join(data, "\n")) }, - \ 'on_stderr': { channel, data, t -> add(result.err, join(data, "\n")) }, - \ 'on_exit': { job, status, t -> ExitCallback(result.out, result.err, status) }, + \ 'on_exit': { job, status, t -> ExitCallback(result.out, status) }, \ }) call chansend(jobid, data) call chanclose(jobid, 'stdin') @@ -89,7 +88,6 @@ function! codeium#server#Request(type, data, ...) abort \ 'in_mode': 'raw', \ 'out_mode': 'raw', \ 'out_cb': { channel, data -> add(result.out, data) }, - \ 'err_cb': { channel, data -> add(result.err, data) }, \ 'exit_cb': { job, status -> s:OnExit(result, status, ExitCallback) }, \ 'close_cb': { channel -> s:OnClose(result, ExitCallback) } \ }) @@ -122,14 +120,6 @@ function! s:SendHeartbeat(timer) abort endfunction function! codeium#server#Start(...) abort - let user_defined_codeium_bin = get(g:, 'codeium_bin', '') - - if user_defined_codeium_bin != '' && filereadable(user_defined_codeium_bin) - let s:bin = user_defined_codeium_bin - call s:ActuallyStart() - return - endif - silent let os = substitute(system('uname'), '\n', '', '') silent let arch = substitute(system('uname -m'), '\n', '', '') let is_arm = stridx(arch, 'arm') == 0 || stridx(arch, 'aarch64') == 0 @@ -154,14 +144,7 @@ function! codeium#server#Start(...) abort if !filereadable(s:bin) call delete(s:bin) if sha ==# s:language_server_sha - let config = get(g:, 'codeium_server_config', {}) - if has_key(config, 'portal_url') && !empty(config.portal_url) - let base_url = config.portal_url - else - let base_url = 'https://github.com/Exafunction/codeium/releases/download' - endif - let base_url = substitute(base_url, '/\+$', '', '') - let url = base_url . '/language-server-v' . s:language_server_version . '/language_server_' . bin_suffix . '.gz' + let url = 'https://github.com/Exafunction/codeium/releases/download/language-server-v' . s:language_server_version . '/language_server_' . bin_suffix . '.gz' else let url = 'https://storage.googleapis.com/exafunction-dist/codeium/' . sha . '/language_server_' . bin_suffix . '.gz' endif diff --git a/doc/codeium.txt b/doc/codeium.txt index a738c63d..d786d266 100644 --- a/doc/codeium.txt +++ b/doc/codeium.txt @@ -26,12 +26,6 @@ COMMANDS *:Codeium* :Codeium EnableBuffer Re-enable Codeium completions in the current buffer after running :Codeium DisableBuffer - *:Codeium_Toggle* -:Codeium Toggle Enable Codeium completions if they are disabled. - Disable Codeium completions if they are enabled. Does - NOT enable completions for current buffer, if they are - disabled with :Codeium DisableBuffer. However, still - affects other buffers. OPTIONS *codeium-options* @@ -86,14 +80,6 @@ g:codeium_tab_fallback The fallback key when there is no suggestion display > let g:codeium_tab_fallback = "\t" < - *g:codeium_bin* -g:codeium_bin Manually set the path to the `codeium` language server - binary on your system. - If unset, `codeium.vim` will fetch and download the - binary from the internet. -> - let g:codeium_bin = "~/.local/bin/codeium_language_server" -< MAPS *codeium-maps* diff --git a/plugin/codeium.vim b/plugin/codeium.vim index 251bbadf..54e5fb90 100644 --- a/plugin/codeium.vim +++ b/plugin/codeium.vim @@ -11,9 +11,9 @@ endif function! s:SetStyle() abort if &t_Co == 256 - hi def CodeiumSuggestion guifg=#808080 ctermfg=244 + hi def CodeiumSuggestion guifg=#808080 ctermfg=244 cterm=italic gui=italic else - hi def CodeiumSuggestion guifg=#808080 ctermfg=8 + hi def CodeiumSuggestion guifg=#808080 ctermfg=8 cterm=italic gui=italic endif hi def link CodeiumAnnotation Normal endfunction