vimrc

My Vim configuration
git clone git://pcardenasb.com/vimrc
Log | Files | Refs | Submodules

lsp.vim (1700B)


      1 vim9script
      2 
      3 def LspOutCallback(ch: channel, msg: dict<any>)
      4 	echomsg msg
      5 enddef
      6 
      7 const job = job_start(['clangd'], {
      8 	in_mode: 'lsp',
      9 	out_mode: 'lsp',
     10 	out_cb: LspOutCallback,
     11 	# err_mode: "raw",
     12 	# err_io: "file",
     13 	# err_name: "khe.log",
     14 })
     15 
     16 const response_init = ch_evalexpr(
     17 	job,
     18 	{
     19 		method: 'initialize',
     20 		params: {
     21 			rootUri: 'file://' .. getcwd(),
     22 			rootPath: getcwd(),
     23 		},
     24 	},
     25 	{
     26 		timeout: 10000,
     27 	}
     28 )
     29 
     30 if response_init->empty()
     31 	echomsg "keeee"
     32 endif
     33 
     34 ch_sendexpr(job, {method: 'initialized'})
     35 
     36 var req_version = 1
     37 def LspTagFunction(
     38 		pattern: string,
     39 		flags: string,
     40 		info: dict<string>
     41 		): list<dict<string>>
     42 
     43 	const [bufnum, lnum, col, off, curswant] = getcurpos()
     44 
     45 	# Send notification 'textDocument/didOpen'
     46 	ch_sendexpr(
     47 		job,
     48 		{
     49 			method: 'textDocument/didOpen',
     50 			params: {
     51 				textDocument: {
     52 					uri: 'file://' .. expand("%:p"),
     53 					version: req_version,
     54 					languageId: 'cpp',
     55 					text: join(getline(1, '$'), "\n"),
     56 				},
     57 			},
     58 		},
     59 		{
     60 			timeout: 10000,
     61 		}
     62 	)
     63 	req_version += 1
     64 
     65 	# Send request 'textDocument/definition'
     66 	const response_defs = ch_evalexpr(
     67 		job,
     68 		{
     69 			method: 'textDocument/definition',
     70 			params: {
     71 				textDocument: {
     72 					uri: 'file://' .. expand("%:p"),
     73 				},
     74 				position: {
     75 					line: lnum - 1,
     76 					character: col - 1
     77 				}
     78 			},
     79 		},
     80 		{
     81 			timeout: 10000,
     82 		}
     83 	)
     84 
     85 	const res: list<dict<any>> = copy(response_defs.result)
     86 	return mapnew(res,  (_, val): dict<string> => ({
     87 		name: 'lsp',
     88 		filename: val.uri[7 :],
     89 		cmd: 'call cursor('
     90 			.. (val.range.start.line + 1)
     91 			.. ','
     92 			.. (val.range.start.character + 1)
     93 			.. ')',
     94 	}))
     95 enddef
     96 
     97 #nnoremap <leader>gd :call <SID>LspGoToDefinition()<CR>
     98 set tagfunc=<SID>LspTagFunction