saccarosium / yegappan-lsp-settings

Quickstart configs for yeggapan lsp client
MIT License
5 stars 1 forks source link

filetype specific loading of LSs with sensible maps #1

Closed Konfekt closed 2 weeks ago

Konfekt commented 2 weeks ago

Maybe this repo could make the whole setup more filetype specific and add sensible default mappings for these?

A list of LSs is given in the wiki and the setup usually only prescribes a name, filetype and exe path, sporadically with some args such as --stdio, say

if executable('neocmakelsp')
  g:lspServers->add({
    name: 'cmake',
    filetype: ['cmake'],
    path: 'neocmakelsp',
    args: ['--stdio'],
})

As one can end up on a computer without the LS, an initial check for each file type

if !exists('g:lspFiletypes') | finish | endif
if index(g:lspFiletypes, &filetype) == -1 | finish | endif

can avoid setting options and mappings such as, let's take ftplugin/c.vim,

setlocal keywordprg=:LspHover
setlocal formatexpr=lsp#lsp#FormatExpr()
setlocal tagfunc=lsp#lsp#TagFunc

inoremap <buffer>        <c-s>  <cmd>LspShowSignature<CR>
nnoremap <buffer>       <c-s>  <cmd>LspShowSignature<CR>
nnoremap <buffer>       gd     <cmd>LspPeekDeclaration<CR>
nnoremap <buffer>       gD     <cmd>LspGotoDeclaration<CR>
nnoremap <buffer>       g]       <cmd>LspPeekDefinition<CR>

nnoremap <buffer>       m,       <cmd>LspDiag show<cr>
nnoremap <buffer>       m.       <cmd>LspDiag current<cr>
nnoremap <buffer>       m[       <cmd>LspDiag prev<cr>
nnoremap <buffer>       m]       <cmd>LspDiag next<cr>
nnoremap <buffer>       m{       <cmd>LspDiag first<cr>
nnoremap <buffer>       m}       <cmd>LspDiag last<cr>

nnoremap <buffer>       g6       <cmd>LspSwitchSourceHeader<CR>

nnoremap <buffer>       <F2>     <cmd>LspRename<CR>

nnoremap <buffer><expr> do   &l:diff ? 'do' : '<cmd>LspCodeLens<CR>'
nnoremap <buffer>       dO         <cmd>LspCodeAction<cr>

xnoremap <buffer>       gw <cmd>LspFormat<cr>
nnoremap <buffer>       gw <plug>(LspFormat)
onoremap <buffer>       <SID>(underline) _
nmap     <buffer><expr> gww  'gw' . v:count1 . '<SID>(underline)'

nnoremap <buffer>       z*      <cmd>LspSymbolSearch<CR>
nnoremap <buffer>       m*    <cmd>LspHighlight<CR>
nnoremap <buffer>       cod   <cmd>LspDiag highlight toggle<cr>
nnoremap <buffer>       coh    :<c-u>LspInlayHints toggle<cr>

xnoremap <buffer> V  <cmd>LspSelectionExpand<cr>
xnoremap <buffer> v  <cmd>LspSelectionShrink<cr>

in this case.

saccarosium commented 2 weeks ago

In https://github.com/saccarosium/yegappan-lsp-settings/commit/2c71d1f7b9f86fbb401195feb8fc27b82c6de06e I've made it so this plugin will set the appropriate options and mapping depending on the server capabilities. So I think this is what you were looking for.

I wouldn't go filetype specific. That is the job for the user config or a language specific plugin. This plugin tries to be a thin abstraction for setting lsps. I like the approach of Neovim's lspconfig on having separate functions to setup a particular lsp server and pick and choose what server you want.

As one can end up on a computer without the LS, an initial check for each file type

This is more appropriate to have directly in yegappan/lsp as an option, let's say silentMissingLspError