Skip to content

Commit 8c01979

Browse files
authored
Make it easier to open chat url when using vim/nvim remotely (#468)
Make url clearer when chat ports are configured
1 parent 452fcfa commit 8c01979

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

autoload/codeium.vim

+20-7
Original file line numberDiff line numberDiff line change
@@ -419,20 +419,25 @@ function! codeium#CycleOrComplete() abort
419419
endif
420420
endfunction
421421

422-
function! s:LaunchChat(out, err, status) abort
423-
let l:metadata = codeium#server#RequestMetadata()
424-
let l:processes = json_decode(join(a:out, ''))
425-
let l:chat_port = l:processes['chatClientPort']
426-
let l:ws_port = l:processes['chatWebServerPort']
427-
422+
function BuildChatUrl(metadata, chat_port, ws_port) abort
428423
let config = get(g:, 'codeium_server_config', {})
429424
let l:has_enterprise_extension = 'false'
430425
if has_key(config, 'api_url') && !empty(config.api_url)
431426
let l:has_enterprise_extension = 'true'
432427
endif
433428

434429
" Hard-coded to English locale and allowed telemetry.
435-
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'
430+
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'
431+
return l:url
432+
endfunction
433+
434+
function! s:LaunchChat(out, err, status) abort
435+
let l:metadata = codeium#server#RequestMetadata()
436+
let l:processes = json_decode(join(a:out, ''))
437+
let l:chat_port = l:processes['chatClientPort']
438+
let l:ws_port = l:processes['chatWebServerPort']
439+
440+
let l:url = BuildChatUrl(l:metadata, l:chat_port, l:ws_port)
436441
let l:browser = codeium#command#BrowserCommand()
437442
let opened_browser = v:false
438443
if !empty(browser)
@@ -501,6 +506,14 @@ function! codeium#Chat() abort
501506
call codeium#RefreshContext()
502507
call codeium#server#Request('GetProcesses', codeium#server#RequestMetadata(), function('s:LaunchChat', []))
503508
call codeium#AddTrackedWorkspace()
509+
" If user has chat_ports set, they are probably using vim remotely and trying to use chat via port forwarding.
510+
" In that case display the url here so that it is easier to copy, as the browser will fail to open automatically.
511+
let chat_ports = get(g:, 'codeium_port_config', {})
512+
if has_key(chat_ports, 'chat_client') && !empty(chat_ports.chat_client) && has_key(chat_ports, 'web_server') && !empty(chat_ports.web_server)
513+
let l:metadata = codeium#server#RequestMetadata()
514+
let l:url = BuildChatUrl(l:metadata, chat_ports.chat_client, chat_ports.web_server)
515+
echomsg l:url
516+
endif
504517
catch
505518
call codeium#log#Exception()
506519
endtry

doc/codeium.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ g:codeium_arch Manually set the host architecture, accepted values
115115
g:codeium_port_config
116116
Set the ports the chat client and web server use.
117117
Pass in web_server and chat_client fields to the mapping to set.
118-
Please note that if either of the ports are specified, only one
118+
Please note that if this option is set, only one
119119
window will work with codeium.
120+
It is recommended to set both the web_server and chat_client options
121+
if using this.
120122
That window can have as many buffers within it, but any other
121123
opened windows will not be able to use Codeium's features.
122124
>

0 commit comments

Comments
 (0)