Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

filetype specific loading of LSs with sensible maps #1

Closed
Konfekt opened this issue Oct 29, 2024 · 1 comment
Closed

filetype specific loading of LSs with sensible maps #1

Konfekt opened this issue Oct 29, 2024 · 1 comment

Comments

@Konfekt
Copy link

Konfekt commented Oct 29, 2024

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
Copy link
Owner

saccarosium commented Oct 29, 2024

In 2c71d1f 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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants