vimrc

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules

commit 0d31790bee3d394dac2217662d64b0e9431c0dcf
parent 4251918a55ec708fba1cda478f85f9b5a9395897
Author: Pablo Cárdenas <pablo.cardenas@imca.edu.pe>
Date:   Sat, 22 Feb 2025 20:41:25 -0300

Updated lsp and multiplayer packages

Diffstat:
Mpack/pablo/opt/lsp/plugin/lsp.vim | 174++++++++++++++++++++++++++++++++++++++++++++-----------------------------------
Apack/pablo/opt/multiplayer/plugin/multiplayer.vim | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mvimrc | 2++
3 files changed, 182 insertions(+), 76 deletions(-)

diff --git a/pack/pablo/opt/lsp/plugin/lsp.vim b/pack/pablo/opt/lsp/plugin/lsp.vim @@ -1,76 +1,98 @@ -"function! LspOutCallback(ch, msg) abort -" " echomsg a:msg -"endfunction -" -"let opts = #{ -"\ in_mode: 'lsp', -"\ out_mode: 'lsp', -"\ out_cb: function('LspOutCallback'), -"\} -"let s:job = job_start(['clangd'], opts) -" -"let s:req = #{ -"\ method: 'initialize', -"\ params: #{ -"\ rootUri: 'file://' .. getcwd() , -"\ rootPath: getcwd(), -"\ trace: "off", -"\ }, -"\} -"let s:defs = ch_evalexpr(s:job, s:req, #{timeout: 100}) -"if s:defs->empty() -" echomsg "keeee" -"endif -" -"call ch_sendexpr(s:job, #{method: 'initialized'}) -" -" -"let s:version = 1 -"function! s:LspTagFunction(pattern, flags, info) abort -" let [s:bufnum, s:lnum, s:col, s:off] = getpos('.') -" -" " Send notification 'textDocument/didOpen' -" let s:req = #{ -" \ method: 'textDocument/didOpen', -" \ params: #{ -" \ textDocument: #{ -" \ uri: 'file://' .. expand("%:p"), -" \ version: s:version, -" \ languageId: 'cpp', -" \ text: join(getline(1, '$'), "\n"), -" \ }, -" \ }, -" \} -" call ch_sendexpr(s:job, s:req) -" -" " Send request 'textDocument/definition' -" let s:req = #{ -" \ method: 'textDocument/definition', -" \ params: #{ -" \ textDocument: #{ -" \ uri: 'file://' .. expand("%:p"), -" \ }, -" \ position: #{ -" \ line: s:lnum - 1, -" \ character: s:col - 1 -" \ } -" \ }, -" \} -" -" function! ResponseToTaglist(key, val) abort -" return #{ -" \ name: 'lsp', -" \ filename: a:val.uri, -" \ cmd: 'norm! ' .. (a:val.range.start.line + 1) .. 'G0' .. (a:val.range.start.character) .. 'l', -" \} -" endfunction -" -" let s:defs = ch_evalexpr(s:job, s:req) -" let s:res = copy(s:defs.result) -" call map(s:res, function("ResponseToTaglist")) -" let s:version += 1 -" return s:res -"endfunction -" -""nnoremap <leader>gd :call <SID>LspGoToDefinition()<CR> -"set tagfunc=<SID>LspTagFunction +vim9script + +def LspOutCallback(ch: channel, msg: dict<any>) + echomsg msg +enddef + +const job = job_start(['clangd'], { + in_mode: 'lsp', + out_mode: 'lsp', + out_cb: LspOutCallback, + # err_mode: "raw", + # err_io: "file", + # err_name: "khe.log", +}) + +const response_init = ch_evalexpr( + job, + { + method: 'initialize', + params: { + rootUri: 'file://' .. getcwd(), + rootPath: getcwd(), + }, + }, + { + timeout: 10000, + } +) + +if response_init->empty() + echomsg "keeee" +endif + +ch_sendexpr(job, {method: 'initialized'}) + +var req_version = 1 +def LspTagFunction( + pattern: string, + flags: string, + info: dict<string> + ): list<dict<string>> + + const [bufnum, lnum, col, off, curswant] = getcurpos() + + # Send notification 'textDocument/didOpen' + ch_sendexpr( + job, + { + method: 'textDocument/didOpen', + params: { + textDocument: { + uri: 'file://' .. expand("%:p"), + version: req_version, + languageId: 'cpp', + text: join(getline(1, '$'), "\n"), + }, + }, + }, + { + timeout: 10000, + } + ) + req_version += 1 + + # Send request 'textDocument/definition' + const response_defs = ch_evalexpr( + job, + { + method: 'textDocument/definition', + params: { + textDocument: { + uri: 'file://' .. expand("%:p"), + }, + position: { + line: lnum - 1, + character: col - 1 + } + }, + }, + { + timeout: 10000, + } + ) + + const res: list<dict<any>> = copy(response_defs.result) + return mapnew(res, (_, val): dict<string> => ({ + name: 'lsp', + filename: val.uri[7 :], + cmd: 'call cursor(' + .. (val.range.start.line + 1) + .. ',' + .. (val.range.start.character + 1) + .. ')', + })) +enddef + +#nnoremap <leader>gd :call <SID>LspGoToDefinition()<CR> +set tagfunc=<SID>LspTagFunction diff --git a/pack/pablo/opt/multiplayer/plugin/multiplayer.vim b/pack/pablo/opt/multiplayer/plugin/multiplayer.vim @@ -0,0 +1,82 @@ +vim9script + +# # Create a channel log so we can see what happens. +# ch_logfile('logfile', 'w') + +# var shell_job: job + +# # Function handling a line of text that has been typed. +# def TextEntered(text: string) + # # Send the text to a shell with Enter appended. + # ch_sendraw(shell_job, text .. "\n") +# enddef + +# # Function handling output from the shell: Add it above the prompt. +# def GotOutput(channel: channel, msg: string) + # append(line("$") - 1, "- " .. msg) +# enddef + +# # Function handling the shell exits: close the window. +# def JobExit(job: job, status: number) + # quit! +# enddef + +# # Start a shell in the background. +# shell_job = job_start(["/bin/sh"], { + # out_cb: GotOutput, + # err_cb: GotOutput, + # exit_cb: JobExit, + # }) + +# new +# set buftype=prompt +# var buf = bufnr('') +# prompt_setcallback(buf, TextEntered) +# prompt_setprompt(buf, "shell command: ") + +# # start accepting shell commands +# startinsert + +# function! multiplayer#Connect() +# let s:buf_file = expand('%:p') +# call system('mkfifo /tmp/vim_shared_pipe_' . getpid()) +# let s:shared_job = job_start('tail -f /tmp/vim_shared_pipe_' . getpid(), {"out_cb": function("s:HandlerOut"), "out_mode": "json"}) +# autocmd! TextChanged,TextChangedI * call <SID>TextChanged() +# autocmd VimLeave * call <SID>Disconnect() +# endfunction + +# function! s:TextChanged() +# let content = getline(1, '$') +# echomsg "TextChanged: " content +# sleep 1 +# echomsg "" +# call writefile(content, expand('%:p')) +# call <SID>Broadcast(join(content, "\n")) +# endfunction + +# function! s:Broadcast(data) +# let all_pipes = split(globpath('/tmp', 'vim_shared_pipe_*'), '\n') +# for pipe in all_pipes +# let mtch = matchlist(pipe, '.*vim_shared_pipe_\(.*\)') +# if len(mtch) >= 2 && mtch[1] != getpid() +# echomsg "mandando: " shellescape(a:data) +# sleep 1 +# echomsg "" +# call system('echo ' . shellescape(a:data) . ' >' . pipe) +# endif +# endfor +# endfunction + +# function! s:HandlerOut(channel, msg) +# echomsg "HandlerOut: " a:msg +# sleep 1 +# echomsg "" +# call setline(1, split(a:msg, "\n")) +# endfunction + +# function! s:Disconnect() +# call job_stop(s:shared_job) +# call delete('/tmp/vim_shared_pipe_' . getpid()) +# endfunction + +# command! -nargs=0 MultiplayerConnect call multiplayer#Connect() diff --git a/vimrc b/vimrc @@ -65,6 +65,7 @@ runtime! plugin/redact_pass.vim " packadd! editorconfig " packadd! matchit +" packadd copilot.vim " packadd emmet-vim " packadd ultisnips " packadd vim-gitgutter @@ -78,5 +79,6 @@ runtime! plugin/redact_pass.vim packadd hardmode packadd tmux packadd lsp +packadd multiplayer "filetype plugin indent on