endif
enddef
+# Show the diagnostic message for the current line without linebreak
+export def ShowCurrentDiagInStatusLine(lspserver: dict<any>)
+ var bnr: number = bufnr()
+ var lnum: number = line('.')
+ var diag: dict<any> = lspserver.getDiagByLine(bnr, lnum)
+ if !diag->empty()
+ # 15 is a enough length not to cause line break
+ var max_width = &columns - 15
+ var code = ""
+ if has_key(diag, 'code')
+ code = "[" .. diag.code .. "] "
+ endif
+ var msgNoLineBreak = code .. substitute(substitute(diag.message, "\n", " ", ""), "\\n", " ", "")
+ echo msgNoLineBreak[ : max_width]
+ else
+ echo ""
+ endif
+enddef
+
# Get the diagnostic from the LSP server for a particular line in a file
export def GetDiagByLine(lspserver: dict<any>, bnr: number, lnum: number): dict<any>
if lspserver.diagsMap->has_key(bnr) &&
diag.DiagsGetErrorCount = diag_import.DiagsGetErrorCount
diag.ShowAllDiags = diag_import.ShowAllDiags
diag.ShowCurrentDiag = diag_import.ShowCurrentDiag
+ diag.ShowCurrentDiagInStatusLine = diag_import.ShowCurrentDiagInStatusLine
diag.LspDiagsJump = diag_import.LspDiagsJump
diag.DiagRemoveFile = diag_import.DiagRemoveFile
symbol.ShowSymbolMenu = symbolsearch_import.ShowSymbolMenu
DiagsGetErrorCount,
ShowAllDiags,
ShowCurrentDiag,
+ ShowCurrentDiagInStatusLine,
LspDiagsJump} from './diag.vim'
import ShowSymbolMenu from './symbolsearch.vim'
import {OpenOutlineWindow, SkipOutlineRefresh} from './outline.vim'
diag.DiagsGetErrorCount = DiagsGetErrorCount
diag.ShowAllDiags = ShowAllDiags
diag.ShowCurrentDiag = ShowCurrentDiag
+ diag.ShowCurrentDiagInStatusLine = ShowCurrentDiagInStatusLine
diag.LspDiagsJump = LspDiagsJump
symbol.ShowSymbolMenu = ShowSymbolMenu
outline.OpenOutlineWindow = OpenOutlineWindow
# Display the diagnostic message only if the mouse is over the first two
# columns
- if v:beval_col >= 3
- return ''
+ if opt.lspOptions.noDiagHoverOnLine
+ if v:beval_col >= 3
+ return ''
+ endif
endif
return diagInfo.message
setbufvar(bnr, '&completeopt', 'menuone,popup,noinsert,noselect')
setbufvar(bnr, '&completepopup', 'border:off')
# <Enter> in insert mode stops completion and inserts a <Enter>
- inoremap <expr> <buffer> <CR> pumvisible() ? "\<C-Y>\<CR>" : "\<CR>"
+ if !opt.lspOptions.noNewlineInCompletion
+ inoremap <expr> <buffer> <CR> pumvisible() ? "\<C-Y>\<CR>" : "\<CR>"
+ endif
else
if s:lspOmniComplEnabled(ftype)
setbufvar(bnr, '&omnifunc', 'lsp#omniFunc')
diag.ShowCurrentDiag(lspserver)
enddef
+def lsp#showCurrentDiagInStatusLine()
+ var ftype = &filetype
+ if ftype == '' || @% == ''
+ return
+ endif
+
+ var lspserver: dict<any> = s:lspGetServer(ftype)
+ if lspserver->empty() || !lspserver.running
+ return
+ endif
+
+ diag.ShowCurrentDiagInStatusLine(lspserver)
+enddef
+
# get the count of error in the current buffer
def lsp#errorCount(): dict<number>
var res = {'Error': 0, 'Warn': 0, 'Info': 0, 'Hint': 0}
hoverInPreview: false,
# Focus on the location list window after LspShowReferences
keepFocusInReferences: false,
+ # Suppress adding a new line on completion selection with <CR>
+ noNewlineInCompletion: false,
+ # Outline window size
+ outlineWinSize: 20,
+ # Open outline window on right side
+ outlineOnRight: false,
+ # Suppress diagnostic hover from appearing when the mouse is over the line instead of the signature
+ noDiagHoverOnLine: true,
+ # Show a diagnostic message on a status line
+ showDiagOnStatusLine: false,
}
# set LSP options from user provided options
vim9script
var util = {}
+var opt = {}
if has('patch-8.2.4019')
import './util.vim' as util_import
+ import './lspoptions.vim' as opt_import
util.GetLineByteFromPos = util_import.GetLineByteFromPos
+ opt.lspOptions = opt_import.lspOptions
else
import GetLineByteFromPos from './util.vim'
+ import lspOptions from './lspoptions.vim'
util.GetLineByteFromPos = GetLineByteFromPos
+ opt.lspOptions = lspOptions
endif
# jump to a symbol selected in the outline window
var prevWinID: number = win_getid()
- :topleft :20vnew LSP-Outline
+ if opt.lspOptions.outlineOnRight
+ execute ':botright :' .. opt.lspOptions.outlineWinSize .. 'vnew LSP-Outline'
+ else
+ execute ':topleft :' .. opt.lspOptions.outlineWinSize .. 'vnew LSP-Outline'
+ endif
:setlocal modifiable
:setlocal noreadonly
:silent! :%d _
lsp#setOptions() function. This function accepts a dictionary argument with the
following optional items:
- autoComplete In insert mode, automatically complete the current
+autoComplete In insert mode, automatically complete the current
symbol. Otherwise use omni-completion. By default this
is set to true.
- autoHighlight In normal mode, automatically highlight all the
+autoHighlight In normal mode, automatically highlight all the
occurrences of the symbol under the cursor. By default
this is set to false.
- showSignature In insert mode, automatically show the current symbol
+showSignature In insert mode, automatically show the current symbol
signature in a popup. By default this is set to true.
- echoSignature In insert mode, echo the current symbol signature
+echoSignature In insert mode, echo the current symbol signature
instead of showing it in a popup. By default this is
set to false.
- autoHighlightDiags Automatically place signs on the lines with a
+autoHighlightDiags Automatically place signs on the lines with a
diagnostic message from the LSP server. By default
this is set to true.
- keepFocusInReferences Focus on the location list window after LspShowReferences
+keepFocusInReferences Focus on the location list window after LspShowReferences.
+ By default this is set to false.
+noNewlineInCompletion Suppress adding a new line on completion selection with <CR>.
+ By default this is set to false.
+outlineWinSize Outline window size, by default this is 20.
+outlineOnRight Open the outline window on the right side, by default
+ this is false.
+noDiagHoverOnLine Suppress diagnostic hover from appearing when
+ the mouse is over the line instead of the signature.
+ By default this is set to true
+showDiagOnStatusLine Show a diagnostic message on a status line.
+ By default this is set to false
For example, to disable the automatic placement of signs for the LSP
diagnostic messages, you can add the following line to your .vimrc file:
-" LSP plugin for vim9
-
-" Needs Vim 8.2.2342 and higher
if v:version < 802 || !has('patch-8.2.2342')
finish
endif
+vim9script
+# LSP plugin for vim9
+
+var opt = {}
+if has('patch-8.2.4019')
+ import '../autoload/lspoptions.vim' as opt_import
+ opt.lspOptions = opt_import.lspOptions
+else
+ import lspOptions from '../autoload/lspoptions.vim'
+ opt.lspOptions = lspOptions
+endif
+
augroup LSPAutoCmds
au!
- autocmd BufNewFile,BufReadPost *
- \ call lsp#addFile(expand('<abuf>') + 0)
- autocmd BufWipeOut *
- \ call lsp#removeFile(expand('<abuf>') + 0)
+ autocmd BufNewFile,BufReadPost * lsp#addFile(bufnr('%'))
+ autocmd BufWipeOut * lsp#removeFile(bufnr('%'))
+ if opt.lspOptions.showDiagOnStatusLine
+ autocmd CursorMoved * lsp#showCurrentDiagInStatusLine()
+ endif
augroup END
-" TODO: Is it needed to shutdown all the LSP servers when exiting Vim?
-" This takes some time.
-" autocmd VimLeavePre * call lsp#stopAllServers()
+# TODO: Is it needed to shutdown all the LSP servers when exiting Vim?
+# This takes some time.
+# autocmd VimLeavePre * call lsp#stopAllServers()
-" LSP commands
+# LSP commands
command! -nargs=0 -bar LspShowServers call lsp#showServers()
command! -nargs=1 -bar LspSetTrace call lsp#setTraceServer(<q-args>)
command! -nargs=0 -bar LspGotoDefinition call lsp#gotoDefinition(v:false)
command! -nargs=1 -bar -complete=dir LspWorkspaceAddFolder call lsp#addWorkspaceFolder(<q-args>)
command! -nargs=1 -bar -complete=dir LspWorkspaceRemoveFolder call lsp#removeWorkspaceFolder(<q-args>)
-" Add the GUI menu entries
+# Add the GUI menu entries
if has('gui_running')
anoremenu <silent> L&sp.Goto.Definition :call lsp#gotoDefinition(v:false)<CR>
anoremenu <silent> L&sp.Goto.Declaration :call lsp#gotoDeclaration(v:false)<CR>
anoremenu <silent> L&sp.Highlight\ Symbol :call lsp#docHighlight()<CR>
anoremenu <silent> L&sp.Highlight\ Clear :call lsp#docHighlightClear()<CR>
- " Diagnostics
+ # Diagnostics
anoremenu <silent> L&sp.Diagnostics.Current :call lsp#showCurrentDiag<CR>
anoremenu <silent> L&sp.Diagnostics.Show\ All :call lsp#showDiagnostics()<CR>
anoremenu <silent> L&sp.Diagnostics.First :call lsp#jumpToDiag('first')<CR>
endif
endif
-" vim: shiftwidth=2 softtabstop=2
+# vim: shiftwidth=2 softtabstop=2