1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 12:50:04 +08:00

feat(lang#c): update lsp key binding for lang#c layer

This commit is contained in:
wsdjeg 2022-04-26 01:45:08 +08:00
parent a5b08d26ca
commit 29dcb31e47
3 changed files with 104 additions and 29 deletions

View File

@ -65,10 +65,12 @@
" `clang_std` layer option.
"
" @subsection Key bindings
"
" >
" Mode Key Function
" ---------------------------------------------
" normal SPC l r run current file
" Key Function
" --------------------------------
" SPC l r run current file
" g d jump to definition
" <
"
" This layer also provides REPL support for c, the key bindings are:
@ -81,6 +83,22 @@
" SPC l s s send selection text
" <
"
" If the lsp layer is enabled for c/c++, the following key bindings can
" be used:
" >
" key binding Description
" --------------------------------
" g D jump to declaration
" SPC l e rename symbol
" SPC l x show references
" SPC l h show line diagnostics
" SPC l d show document
" K show document
" SPC l w l list workspace folder
" SPC l w a add workspace folder
" SPC l w r remove workspace folder
" <
"
" Known issue:
"
" You need to use `flush(stdout)` before `scanf()` when run code in code
@ -301,25 +319,26 @@ function! s:language_specified_mappings() abort
\ 'call SpaceVim#plugins#runner#open()',
\ 'execute current file', 1)
if SpaceVim#layers#lsp#check_filetype('c')
\ || SpaceVim#layers#lsp#check_server('clangd')
nnoremap <silent><buffer> K :call SpaceVim#lsp#show_doc()<CR>
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'd'],
\ 'call SpaceVim#lsp#show_doc()', 'show_document', 1)
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'e'],
\ 'call SpaceVim#lsp#rename()', 'rename symbol', 1)
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'f'],
\ 'call SpaceVim#lsp#references()', 'references', 1)
" these work for now with coc.nvim only
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'x'],
\ 'call SpaceVim#lsp#references()', 'show-references', 1)
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'i'],
\ 'call SpaceVim#lsp#go_to_impl()', 'implementation', 1)
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 't'],
\ 'call SpaceVim#lsp#go_to_typedef()', 'type definition', 1)
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'R'],
\ 'call SpaceVim#lsp#refactor()', 'refactor', 1)
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'D'],
\ 'call SpaceVim#lsp#go_to_declaration()', 'declaration', 1)
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'h'],
\ 'call SpaceVim#lsp#show_line_diagnostics()', 'show-line-diagnostics', 1)
let g:_spacevim_mappings_space.l.w = {'name' : '+Workspace'}
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'w', 'l'],
\ 'call SpaceVim#lsp#list_workspace_folder()', 'list-workspace-folder', 1)
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'w', 'a'],
\ 'call SpaceVim#lsp#add_workspace_folder()', 'add-workspace-folder', 1)
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'w', 'r'],
\ 'call SpaceVim#lsp#remove_workspace_folder()', 'remove-workspace-folder', 1)
endif
let g:_spacevim_mappings_space.l.s = {'name' : '+Send'}
@ -463,6 +482,7 @@ endfunction
" local function: go_to_declaration {{{
function! s:go_to_declaration() abort
if !SpaceVim#layers#lsp#check_filetype(&ft)
\ && !SpaceVim#layers#lsp#check_server('clangd')
try
exe 'ts' expand('<cword>')
catch /^Vim\%((\a\+)\)\=:E426/
@ -479,6 +499,7 @@ endfunction
" local function: go_to_def {{{
function! s:go_to_def() abort
if !SpaceVim#layers#lsp#check_filetype(&ft)
\ && !SpaceVim#layers#lsp#check_server('clangd')
try
exe 'ts' expand('<cword>')
catch /^Vim\%((\a\+)\)\=:E426/

View File

@ -2394,10 +2394,12 @@ Note: If `.clang` file contains std configuration, it will override
KEY BINDINGS
>
Mode Key Function
---------------------------------------------
normal SPC l r run current file
Key Function
--------------------------------
SPC l r run current file
g d jump to definition
<
This layer also provides REPL support for c, the key bindings are:
@ -2410,6 +2412,21 @@ This layer also provides REPL support for c, the key bindings are:
SPC l s s send selection text
<
If the lsp layer is enabled for c/c++, the following key bindings can be used:
>
key binding Description
--------------------------------
g D jump to declaration
SPC l e rename symbol
SPC l x show references
SPC l h show line diagnostics
SPC l d show document
K show document
SPC l w l list workspace folder
SPC l w a add workspace folder
SPC l w r remove workspace folder
<
Known issue:
You need to use `flush(stdout)` before `scanf()` when run code in code runner.

View File

@ -12,6 +12,10 @@ description: "C/C++/Object-C language support for SpaceVim, including code compl
- [Features](#features)
- [Configuration](#configuration)
- [Key bindings](#key-bindings)
- [Jump to definition](#jump-to-definition)
- [Running current script](#running-current-script)
- [Inferior REPL process](#inferior-repl-process)
- [LSP key Bindings](#lsp-key-bindings)
<!-- vim-markdown-toc -->
@ -55,10 +59,10 @@ A dict containing the standards you want to use. The default is:
```json
{
"c": "c11",
"cpp": "c++1z",
"objc": "c11",
"objcpp": "c++1z",
"c": "c11",
"cpp": "c++1z",
"objc": "c11",
"objcpp": "c++1z"
}
```
@ -95,18 +99,51 @@ Note: If `.clang` file contains std configuration, it will override
`format_on_save`: Enable/disable file formatting when saving current file. By default,
it is disabled, to enable it:
```toml
[[layers]]
name = 'lang#c'
format_on_save = true
```
```
## Key bindings
| key bindings | Descriptions |
| ------------ | -------------------------------- |
| `SPC l d` | show documentation |
| `SPC l e` | rename symbol |
| `SPC l f` | references |
| `SPC l r` | compile and run the current file |
| `g d` | defintion preview |
### Jump to definition
| Mode | Key Bindings | Description |
| ------ | ------------ | ------------------------------------------------ |
| normal | `g d` | Jump to the definition position of cursor symbol |
### Running current script
To run current file, you can press `SPC l r` to run the current file without losing focus,
and the result will be shown in a runner buffer.
### Inferior REPL process
Start a `igcc` inferior REPL process with `SPC l s i`.
Send code to inferior process commands:
| Key Bindings | Descriptions |
| ------------ | ------------------------------------------------ |
| `SPC l s b` | send buffer and keep code buffer focused |
| `SPC l s l` | send line and keep code buffer focused |
| `SPC l s s` | send selection text and keep code buffer focused |
### LSP key Bindings
If the lsp layer is enabled for C/C++, the following key bindings can
be used:
| key binding | Description |
| ----------- | ----------------------- |
| `g D` | jump to declaration |
| `SPC l e` | rename symbol |
| `SPC l x` | show references |
| `SPC l s` | show line diagnostics |
| `SPC l d` | show document |
| `K` | show document |
| `SPC l w l` | list workspace folder |
| `SPC l w a` | add workspace folder |
| `SPC l w r` | remove workspace folder |