From 1739130078d4d10f2a79b0534bb30f24adda1759 Mon Sep 17 00:00:00 2001 From: Sean Sullivan Date: Wed, 18 Jan 2023 12:54:36 -0800 Subject: [PATCH 01/91] feat: make suggestion text italic --- plugin/codeium.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/codeium.vim b/plugin/codeium.vim index 7265a145..81cf733d 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 From 1dbc2048c99e2802526531c00cae8ead996f776a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alvar=20Hyv=C3=B6nen?= Date: Mon, 16 Oct 2023 14:36:28 +0300 Subject: [PATCH 02/91] Add new variable: `g:codeium_filetypes_disabled_by_default`. Enables finer control of when to enable codeium. --- README.md | 20 ++++++++++++++++---- autoload/codeium.vim | 6 +++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9ea62a24..720812c7 100644 --- a/README.md +++ b/README.md @@ -116,15 +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 ``` -Instead, if you would like to just disable the automatic triggering of -completions: +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: + +```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, + \ } +``` + +If you would like to just disable the automatic triggering of completions: ```vim let g:codeium_manual = v:true diff --git a/autoload/codeium.vim b/autoload/codeium.vim index 5d9dbba7..d1a41a49 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 From 7956a9ddf5dafd1c336c20b70d08b1790b219afc Mon Sep 17 00:00:00 2001 From: AnthonyUtt Date: Thu, 19 Jan 2023 12:53:36 -0500 Subject: [PATCH 03/91] add flag for disabling default tab mapping --- doc/codeium.txt | 48 ++---------------------------------------------- 1 file changed, 2 insertions(+), 46 deletions(-) diff --git a/doc/codeium.txt b/doc/codeium.txt index a738c63d..1f86144b 100644 --- a/doc/codeium.txt +++ b/doc/codeium.txt @@ -23,15 +23,9 @@ COMMANDS *:Codeium* :Codeium DisableBuffer Disable Codeium completions in the current buffer only. *:Codeium_EnableBuffer* -:Codeium EnableBuffer Re-enable Codeium completions in the current +:Codeium EnableBuffer Re-eisable 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* @@ -53,13 +47,6 @@ g:codeium_enabled A global boolean flag that controls whether codeium let g:codeium_enabled = v:true < - *g:codeium_manual* -g:codeium_manual If true, codeium completions will never automatically - trigger. -> - let g:codeium_manual = v:true -< - *g:codeium_no_map_tab* g:codeium_no_map_tab A global boolean flag that controls whether codeium uses for the mapping codeium#Accept @@ -67,57 +54,26 @@ g:codeium_no_map_tab A global boolean flag that controls whether codeium let g:codeium_no_map_tab = v:true < - *g:codeium_idle_delay* -g:codeium_idle_delay Delay in milliseconds before autocompletions are - shown (limited by language server to a minimum of 75). -> - let g:codeium_idle_delay = 500 -< - *g:codeium_render* -g:codeium_render A global boolean flag that controls whether codeium - renders are enabled or disabled. -> - let g:codeium_render = v:false -< - - *g:codeium_tab_fallback* -g:codeium_tab_fallback The fallback key when there is no suggestion display - in `codeium#Accept()`. -> - 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* *codeium-i_* Codeium.vim defaults to using the key to insert the current suggestion. If there is no suggestion display, the key will fallback -to any existing mapping you have. This is bound to `codeium#Accept()` +to any existing mapping you have. Other Maps ~ *codeium-i_CTRL-]* Dismiss the current suggestion. (codeium-dismiss) -call codeium#Clear() *codeium-i_ALT-]* Cycle to the next suggestion. (codeium-next) -call codeium#CycleCompletions(1) *codeium-i_ALT-[* Cycle to the previous suggestion. (codeium-previous) -call codeium#CycleCompletions(-1) SYNTAX HIGHLIGHTING *codeium-highlighting* From 9fb5530824560a6164221ea1a8c690f12e3b8d8b Mon Sep 17 00:00:00 2001 From: Prem Nair Date: Sun, 22 Jan 2023 23:34:27 -0800 Subject: [PATCH 04/91] Project import generated by Copybara. (#34) GitOrigin-RevId: c545ff5822e46131599b661ab213e4b4b7094270 Co-authored-by: Copybara Bot --- autoload/codeium/server.vim | 139 ++++++++---------------------------- 1 file changed, 31 insertions(+), 108 deletions(-) diff --git a/autoload/codeium/server.vim b/autoload/codeium/server.vim index 49019675..e98596b4 100644 --- a/autoload/codeium/server.vim +++ b/autoload/codeium/server.vim @@ -1,11 +1,9 @@ -let s:language_server_version = '1.6.28' -let s:language_server_sha = 'f485965568948013d9f47815917f2f1f3a99089d' -let s:root = expand(':h:h:h') -let s:bin = v:null +let s:language_server_version = '1.1.22' +let s:language_server_sha = '0a0cf69c54bd02be577e1240463b85d782fa5475' if has('nvim') let s:ide = 'neovim' -else +else let s:ide = 'vim' endif @@ -25,13 +23,13 @@ if !exists('s:editor_version') endif let s:server_port = v:null -let g:codeium_server_job = v:null +let s:server_job = v:null 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 +39,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 @@ -56,7 +54,6 @@ function! codeium#server#RequestMetadata() abort \ 'api_key': codeium#command#ApiKey(), \ 'ide_name': s:ide, \ 'ide_version': s:ide_version, - \ 'extension_name': 'vim', \ 'extension_version': s:language_server_version, \ } endfunction @@ -65,38 +62,27 @@ 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 = [ \ 'curl', uri, \ '--header', 'Content-Type: application/json', - \ '-d@-' + \ '--data', json_encode(a:data) \ ] - 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, { + return 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') - return jobid else - let job = job_start(args, { - \ 'in_mode': 'raw', + return job_start(args, { \ '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) } \ }) - let channel = job_getchannel(job) - call ch_sendraw(channel, data) - call ch_close_in(channel) - return job endif endfunction @@ -121,17 +107,9 @@ function! s:SendHeartbeat(timer) abort endtry 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', '', '') +function! codeium#server#Start(timer) abort + let os = substitute(system('uname'), '\n', '', '') + let arch = substitute(system('uname -m'), '\n', '', '') let is_arm = stridx(arch, 'arm') == 0 || stridx(arch, 'aarch64') == 0 if os ==# 'Linux' && is_arm @@ -146,96 +124,41 @@ function! codeium#server#Start(...) abort let bin_suffix = 'windows_x64.exe' endif - let sha = get(codeium#command#LoadConfig(codeium#command#XdgConfigDir()), 'sha', s:language_server_sha) - let bin_dir = codeium#command#HomeDir() . '/bin/' . sha - let s:bin = bin_dir . '/language_server_' . bin_suffix + let bin_dir = codeium#command#ConfigDir() . '/bin/' . s:language_server_sha + let bin = bin_dir . '/language_server_' . bin_suffix call mkdir(bin_dir, 'p') - 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' - else - let url = 'https://storage.googleapis.com/exafunction-dist/codeium/' . sha . '/language_server_' . bin_suffix . '.gz' - endif - let args = ['curl', '-Lo', s:bin . '.gz', url] - if has('nvim') - let s:download_job = jobstart(args, {'on_exit': { job, status, t -> s:UnzipAndStart(status) }}) - else - let s:download_job = job_start(args, {'exit_cb': { job, status -> s:UnzipAndStart(status) }}) - endif - else - call s:ActuallyStart() - endif -endfunction - -function! s:UnzipAndStart(status) abort - if has('win32') - " Save old settings. - let old_shell = &shell - let old_shellquote = &shellquote - let old_shellpipe = &shellpipe - let old_shellxquote = &shellxquote - let old_shellcmdflag = &shellcmdflag - let old_shellredir = &shellredir - " Switch to powershell. - let &shell = 'powershell' - set shellquote= shellpipe=\| shellxquote= - set shellcmdflag=-NoLogo\ -NoProfile\ -ExecutionPolicy\ RemoteSigned\ -Command - set shellredir=\|\ Out-File\ -Encoding\ UTF8 - call system('& { . ' . shellescape(s:root . '/powershell/gzip.ps1') . '; Expand-File ' . shellescape(s:bin . '.gz') . ' }') - " Restore old settings. - let &shell = old_shell - let &shellquote = old_shellquote - let &shellpipe = old_shellpipe - let &shellxquote = old_shellxquote - let &shellcmdflag = old_shellcmdflag - let &shellredir = old_shellredir - else - if !executable('gzip') - call codeium#log#Error('Failed to extract language server binary: missing `gzip`.') + if empty(glob(bin)) + let url = 'https://github.com/Exafunction/codeium/releases/download/language-server-v' . s:language_server_version . '/language_server_' . bin_suffix . '.gz' + call system('curl -Lo ' . bin . '.gz' . ' ' . url) + call system('gzip -d ' . bin . '.gz') + call system('chmod +x ' . bin) + if empty(glob(bin)) + call codeium#log#Error('Failed to download language server binary.') return '' endif - call system('gzip -d ' . s:bin . '.gz') - call system('chmod +x ' . s:bin) endif - if !filereadable(s:bin) - call codeium#log#Error('Failed to download language server binary.') - return '' - endif - call s:ActuallyStart() -endfunction -function! s:ActuallyStart() abort let config = get(g:, 'codeium_server_config', {}) let manager_dir = tempname() . '/codeium/manager' call mkdir(manager_dir, 'p') let args = [ - \ s:bin, - \ '--api_server_url', get(config, 'api_url', 'https://server.codeium.com'), + \ bin, + \ '--api_server_host', get(config, 'api_host', 'server.codeium.com'), + \ '--api_server_port', get(config, 'api_port', '443'), \ '--manager_dir', manager_dir \ ] - if has_key(config, 'api_url') && !empty(config.api_url) - let args += ['--enterprise_mode'] - endif call codeium#log#Info('Launching server with manager_dir ' . manager_dir) if has('nvim') - let g:codeium_server_job = jobstart(args, { - \ 'on_stderr': { channel, data, t -> codeium#log#Info('[SERVER] ' . join(data, "\n")) }, + let s:server_job = jobstart(args, { + \ 'on_stderr': { channel, data, t -> codeium#log#Info("[SERVER] " . join(data, "\n")) }, \ }) else - let g:codeium_server_job = job_start(args, { + let s:server_job = job_start(args, { \ 'out_mode': 'raw', - \ 'err_cb': { channel, data -> codeium#log#Info('[SERVER] ' . data) }, + \ 'err_cb': { channel, data -> codeium#log#Info("[SERVER] " . data) }, \ }) endif call timer_start(500, function('s:FindPort', [manager_dir]), {'repeat': -1}) From 2703787640db0d8c5f68dd03c306293356d2c496 Mon Sep 17 00:00:00 2001 From: Sean Sullivan Date: Sun, 22 Jan 2023 23:19:41 -0800 Subject: [PATCH 05/91] add better keybinding configuration/documentation --- README.md | 64 +++++++------------------------------------------ doc/codeium.txt | 5 +++- 2 files changed, 13 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index b868749b..65aa2d21 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,8 @@ [![Discord](https://img.shields.io/discord/1027685395649015980?label=community&color=5865F2&logo=discord&logoColor=FFFFFF)](https://discord.gg/3XFf78nAx5) [![Twitter Follow](https://img.shields.io/badge/style--blue?style=social&logo=twitter&label=Follow%20%40codeiumdev)](https://twitter.com/intent/follow?screen_name=codeiumdev) ![License](https://img.shields.io/github/license/Exafunction/codeium.vim) -[![built with Codeium](https://codeium.com/badges/main)](https://codeium.com?repo_name=exafunction%2Fcodeium.vim) -[![Visual Studio](https://img.shields.io/visual-studio-marketplace/i/Codeium.codeium?label=Visual%20Studio&logo=visualstudio)](https://marketplace.visualstudio.com/items?itemName=Codeium.codeium) +[![Visual Studio](https://img.shields.io/visual-studio-marketplace/d/Codeium.codeium?label=Visual%20Studio&logo=visualstudio)](https://marketplace.visualstudio.com/items?itemName=Codeium.codeium) [![JetBrains](https://img.shields.io/jetbrains/plugin/d/20540?label=JetBrains)](https://plugins.jetbrains.com/plugin/20540-codeium/) [![Open VSX](https://img.shields.io/open-vsx/dt/Codeium/codeium?label=Open%20VSX)](https://open-vsx.org/extension/Codeium/codeium) [![Google Chrome](https://img.shields.io/chrome-web-store/users/hobjkcpmjhlegmobgonaagepfckjkceh?label=Google%20Chrome&logo=googlechrome&logoColor=FFFFFF)](https://chrome.google.com/webstore/detail/codeium/hobjkcpmjhlegmobgonaagepfckjkceh) @@ -46,7 +45,7 @@ options, or see [this guide](https://www.codeium.com/vim_tutorial) for a quick t For a full list of configuration options you can run `:help codeium`. A few of the most popular options are highlighted below. -### ⌨️ Keybindings +### ⌨️ Keybindings Codeium provides the following functions to control suggestions: @@ -66,7 +65,7 @@ let g:codeium_disable_bindings = 1 or in Neovim: -```lua +```vim vim.g.codeium_disable_bindings = 1 ``` @@ -77,7 +76,7 @@ If you'd like to bind the actions above to different keys, this might look somet ```vim -imap