vim-lsp


Ⅰ. 插件描述

async language server protocol plugin for vim and neovim

Ⅱ. 基本信息

创建日期:  2016-11-06
使用用户:  407
Github星:  1410
插件作者:  Prabir Shrestha

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'prabirshrestha/vim-lsp'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'prabirshrestha/vim-lsp'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'prabirshrestha/vim-lsp'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/prabirshrestha/vim-lsp

Ⅳ. 文档说明

# vim-lsp Gitter

Async Language Server Protocol plugin for vim8 and neovim.

Installing

Plug 'prabirshrestha/async.vim'
Plug 'prabirshrestha/vim-lsp'

Note: async.vim is required and is used to normalize jobs between vim8 and neovim.

Registering servers

if executable('pyls')
    " pip install python-language-server
    au User lsp_setup call lsp#register_server({
        \ 'name': 'pyls',
        \ 'cmd': {server_info->['pyls']},
        \ 'whitelist': ['python'],
        \ })
endif

function! s:on_lsp_buffer_enabled() abort
    setlocal omnifunc=lsp#complete
    setlocal signcolumn=yes
    nmap <buffer> gd <plug>(lsp-definition)
    nmap <buffer> <f2> <plug>(lsp-rename)
    " refer to doc to add more commands
endfunction

augroup lsp_install
    au!
    " call s:on_lsp_buffer_enabled only for languages that has the server registered.
    autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
augroup END

Refer to vim-lsp-settings on how to easily setup language servers using vim-lsp automatically.

Plug 'prabirshrestha/async.vim'
Plug 'prabirshrestha/vim-lsp'
Plug 'mattn/vim-lsp-settings'

auto-complete

Refer to docs on configuring omnifunc or asyncomplete.vim.

Snippets

vim-lsp does not support snippets by default. If you want snippet integration, you will first have to install a third-party snippet plugin and a plugin that integrates it in vim-lsp.
At the moment, you have following options:

  1. vim-vsnip together with vim-vsnip-integ
  2. UltiSnips together with vim-lsp-ultisnips
  3. neosnippet.vim together with vim-lsp-neosnippet

For more information, refer to the readme and documentation of the respective plugins.

Folding

You can let the language server automatically handle folding for you. To enable this, you have to set 'foldmethod', 'foldexpr' and (optionally) 'foldtext':

set foldmethod=expr
  \ foldexpr=lsp#ui#vim#folding#foldexpr()
  \ foldtext=lsp#ui#vim#folding#foldtext()

If you would like to disable folding globally, you can add this to your configuration:

let g:lsp_fold_enabled = 0

Also see :h vim-lsp-folding.

Semantic highlighting

vim-lsp supports the unofficial extension to the LSP protocol for semantic highlighting (https://github.com/microsoft/vscode-languageserver-node/pull/367).
This feature requires Neovim highlights, or Vim with the textprop feature enabled.
You will also need to link language server semantic scopes to Vim highlight groups.
Refer to :h vim-lsp-semantic for more info.

Supported commands

Note:

  • Some servers may only support partial commands.
  • While it is possible to register multiple servers for the same filetype, some commands will pick only the first server that supports it. For example, it doesn't make sense for rename and format commands to be sent to multiple servers.
CommandDescription
:LspCodeActionGets a list of possible commands that can be applied to a file so it can be fixed (quick fix)
:LspDeclarationGo to the declaration of the word under the cursor, and open in the current window
:LspDefinitionGo to the definition of the word under the cursor, and open in the current window
:LspDocumentDiagnosticsGet current document diagnostics information
:LspDocumentFormatFormat entire document
:LspDocumentRangeFormatFormat document selection
:LspDocumentSymbolShow document symbols
:LspHoverShow hover information
:LspImplementationShow implementation of interface in the current window
:LspNextDiagnosticjump to next diagnostic (all of error, warning, information, hint)
:LspNextErrorjump to next error
:LspNextReferencejump to next reference to the symbol under cursor
:LspNextWarningjump to next warning
:LspPeekDeclarationGo to the declaration of the word under the cursor, but open in preview window
:LspPeekDefinitionGo to the definition of the word under the cursor, but open in preview window
:LspPeekImplementationGo to the implementation of an interface, but open in preview window
:LspPeekTypeDefinitionGo to the type definition of the word under the cursor, but open in preview window
:LspPreviousDiagnosticjump to previous diagnostic (all of error, warning, information, hint)
:LspPreviousErrorjump to previous error
:LspPreviousReferencejump to previous reference to the symbol under cursor
:LspPreviousWarningjump to previous warning
:LspReferencesFind references
:LspRenameRename symbol
:LspStatusShow the status of the language server
:LspTypeDefinitionGo to the type definition of the word under the cursor, and open in the current window
:LspTypeHierarchyView type hierarchy of the symbol under the cursor
:LspWorkspaceSymbolSearch/Show workspace symbol

Diagnostics

Document diagnostics (e.g. warnings, errors) are enabled by default, but if you
preferred to turn them off and use other plugins instead (like
Neomake or
ALE, set g:lsp_diagnostics_enabled to
0:

let g:lsp_diagnostics_enabled = 0         " disable diagnostics support

Signs

let g:lsp_signs_enabled = 1         " enable signs
let g:lsp_diagnostics_echo_cursor = 1 " enable echo under cursor when in normal mode

Four groups of signs are defined and used: LspError, LspWarning, LspInformation, LspHint. It is possible to set custom text or icon that will be used for each sign (note that icons are only available in GUI). To do this, set some of the following globals: g:lsp_signs_error, g:lsp_signs_warning, g:lsp_signs_information, g:lsp_signs_hint. They should be set to a dict, that contains either text that will be used as sign in terminal, or icon that will be used for GUI, or both. For example:

let g:lsp_signs_error = {'text': '✗'}
let g:lsp_signs_warning = {'text': '‼', 'icon': '/path/to/some/icon'} " icons require GUI
let g:lsp_signs_hint = {'icon': '/path/to/some/other/icon'} " icons require GUI

Also two highlight groups for every sign group are defined (for example for LspError these are LspErrorText and LspErrorLine). By default, LspError text is highlighted using Error group, LspWarning is highlighted as Todo, others use Normal group. Line highlighting is not set by default. If your colorscheme of choise does not provide any of these, it is possible to clear them or link to some other group, like so:

highlight link LspErrorText GruvboxRedSign " requires gruvbox
highlight clear LspWarningLine

Highlights

Highlighting diagnostics requires either NeoVim 0.3+ or Vim with patch 8.1.0579.
They are enabled by default when supported, but can be turned off respectively by

let g:lsp_highlights_enabled = 0
let g:lsp_textprop_enabled = 0

Can be customized by setting or linking LspErrorHighlight, LspWarningHighlight,
LspInformationHighlight and LspHintHighlight highlight groups.

Virtual text

In NeoVim 0.3 or newer you can use virtual text feature (enabled by default).
You can disable it by adding

let g:lsp_virtual_text_enabled = 0

To your configuration.

Virtual text will use the same highlight groups as signs feature.

Highlight references

Highlight references to the symbol under the cursor. To enable, set in your
configuration:

let g:lsp_highlight_references_enabled = 1

To change the style of the highlighting, you can set or link the lspReference
highlight group, e.g.:

highlight lspReference ctermfg=red guifg=red ctermbg=green guibg=green

Debugging

In order to enable file logging set g:lsp_log_file.

let g:lsp_log_verbose = 1
let g:lsp_log_file = expand('~/vim-lsp.log')

" for asyncomplete.vim log
let g:asyncomplete_log_file = expand('~/asyncomplete.log')

添加新评论