Skip to content

Commit

Permalink
Make it easier to open chat url when using vim/nvim remotely (#468)
Browse files Browse the repository at this point in the history
Make url clearer when chat ports are configured
  • Loading branch information
saranshsaini authored Oct 14, 2024
1 parent 452fcfa commit 8c01979
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
27 changes: 20 additions & 7 deletions autoload/codeium.vim
Original file line number Diff line number Diff line change
Expand Up @@ -419,20 +419,25 @@ function! codeium#CycleOrComplete() abort
endif
endfunction

function! s:LaunchChat(out, err, status) abort
let l:metadata = codeium#server#RequestMetadata()
let l:processes = json_decode(join(a:out, ''))
let l:chat_port = l:processes['chatClientPort']
let l:ws_port = l:processes['chatWebServerPort']

function BuildChatUrl(metadata, chat_port, ws_port) abort
let config = get(g:, 'codeium_server_config', {})
let l:has_enterprise_extension = 'false'
if has_key(config, 'api_url') && !empty(config.api_url)
let l:has_enterprise_extension = 'true'
endif

" Hard-coded to English locale and allowed telemetry.
let l:url = 'http://127.0.0.1:' . l:chat_port . '/?' . 'api_key=' . l:metadata.api_key . '&ide_name=' . l:metadata.ide_name . '&ide_version=' . l:metadata.ide_version . '&extension_name=' . l:metadata.extension_name . '&extension_version=' . l:metadata.extension_version . '&web_server_url=ws://127.0.0.1:' . l:ws_port . '&has_enterprise_extension=' . l:has_enterprise_extension . '&app_name=Vim&locale=en&ide_telemetry_enabled=true&has_index_service=true'
let l:url = 'http://127.0.0.1:' . a:chat_port . '/?' . 'api_key=' . a:metadata.api_key . '&ide_name=' . a:metadata.ide_name . '&ide_version=' . a:metadata.ide_version . '&extension_name=' . a:metadata.extension_name . '&extension_version=' . a:metadata.extension_version . '&web_server_url=ws://127.0.0.1:' . a:ws_port . '&has_enterprise_extension=' . l:has_enterprise_extension . '&app_name=Vim&locale=en&ide_telemetry_enabled=true&has_index_service=true'
return l:url
endfunction

function! s:LaunchChat(out, err, status) abort
let l:metadata = codeium#server#RequestMetadata()
let l:processes = json_decode(join(a:out, ''))
let l:chat_port = l:processes['chatClientPort']
let l:ws_port = l:processes['chatWebServerPort']

let l:url = BuildChatUrl(l:metadata, l:chat_port, l:ws_port)
let l:browser = codeium#command#BrowserCommand()
let opened_browser = v:false
if !empty(browser)
Expand Down Expand Up @@ -501,6 +506,14 @@ function! codeium#Chat() abort
call codeium#RefreshContext()
call codeium#server#Request('GetProcesses', codeium#server#RequestMetadata(), function('s:LaunchChat', []))
call codeium#AddTrackedWorkspace()
" If user has chat_ports set, they are probably using vim remotely and trying to use chat via port forwarding.
" In that case display the url here so that it is easier to copy, as the browser will fail to open automatically.
let chat_ports = get(g:, 'codeium_port_config', {})
if has_key(chat_ports, 'chat_client') && !empty(chat_ports.chat_client) && has_key(chat_ports, 'web_server') && !empty(chat_ports.web_server)
let l:metadata = codeium#server#RequestMetadata()
let l:url = BuildChatUrl(l:metadata, chat_ports.chat_client, chat_ports.web_server)
echomsg l:url
endif
catch
call codeium#log#Exception()
endtry
Expand Down
4 changes: 3 additions & 1 deletion doc/codeium.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ g:codeium_arch Manually set the host architecture, accepted values
g:codeium_port_config
Set the ports the chat client and web server use.
Pass in web_server and chat_client fields to the mapping to set.
Please note that if either of the ports are specified, only one
Please note that if this option is set, only one
window will work with codeium.
It is recommended to set both the web_server and chat_client options
if using this.
That window can have as many buffers within it, but any other
opened windows will not be able to use Codeium's features.
>
Expand Down

0 comments on commit 8c01979

Please sign in to comment.