# Refer to https://microsoft.github.io/language-server-protocol/specification
# for the Language Server Protocol (LSP) specificaiton.
+import lspOptions from './lspoptions.vim'
import {WarnMsg,
ErrMsg,
TraceLog,
# and then setup the below mapping for those buffers.
# map characters that trigger signature help
- if g:LSP_Show_Signature && caps->has_key('signatureHelpProvider')
+ if lspOptions.showSignature && caps->has_key('signatureHelpProvider')
var triggers = caps.signatureHelpProvider.triggerCharacters
for ch in triggers
exe 'inoremap <buffer> <silent> ' .. ch .. ' ' .. ch .. "<C-R>=lsp#showSignature()<CR>"
endfor
endif
- if g:LSP_24x7_Complete && caps->has_key('completionProvider')
+ if lspOptions.autoComplete && caps->has_key('completionProvider')
var triggers = caps.completionProvider.triggerCharacters
lspserver.completionTriggerChars = triggers
endif
+ if lspOptions.autoHighlight && caps->has_key('documentHighlightProvider')
+ && caps.documentHighlightProvider
+ # Highlight all the occurrences of the current keyword
+ augroup LSPBufferAutocmds
+ autocmd CursorMoved <buffer> call lsp#docHighlightClear()
+ | call lsp#docHighlight()
+ augroup END
+ endif
+
# send a "initialized" notification to server
lspserver.sendInitializedNotif()
startcol = text->stridx(label)
endif
endif
- if g:LSP_Echo_Signature
+ if lspOptions.showSignature
echon "\r\r"
echon ''
echon strpart(text, 0, startcol)
completeItems->add(d)
endfor
- if g:LSP_24x7_Complete
+ if lspOptions.autoComplete
if completeItems->empty()
# no matches
return
# Vim9 LSP client
+import lspOptions from './lspoptions.vim'
import NewLspServer from './lspserver.vim'
import {WarnMsg,
ErrMsg,
var lspInitializedOnce = false
+# Set user configurable LSP options
+def lsp#setOptions(lspOpts: dict<any>)
+ for key in lspOpts->keys()
+ lspOptions[key] = lspOpts[key]
+ endfor
+enddef
+
def s:lspInitOnce()
# Signs used for LSP diagnostics
sign_define([{name: 'LspDiagError', text: 'E ', texthl: 'ErrorMsg',
return ''
endif
+ # Display the diagnostic message only if the mouse is over the first two
+ # columns
+ if v:beval_col >= 3
+ return ''
+ endif
+
return diagInfo.message
enddef
endif
lspserver.textdocDidOpen(bnr, ftype)
- # file saved notification handler
- autocmd BufWritePost <buffer> call s:lspSavedFile()
-
# add a listener to track changes to this buffer
listener_add(function('lsp#bufchange_listener'), bnr)
# set options for insert mode completion
- if g:LSP_24x7_Complete
+ if lspOptions.autoComplete
setbufvar(bnr, '&completeopt', 'menuone,popup,noinsert,noselect')
setbufvar(bnr, '&completepopup', 'border:off')
- # autocmd for 24x7 insert mode completion
- autocmd TextChangedI <buffer> call lsp#complete()
# <Enter> in insert mode stops completion and inserts a <Enter>
inoremap <expr> <buffer> <CR> pumvisible() ? "\<C-Y>\<CR>" : "\<CR>"
else
endif
setbufvar(bnr, '&balloonexpr', 'LspDiagExpr()')
- exe 'autocmd InsertLeave <buffer=' .. bnr .. '> call lsp#leftInsertMode()'
# map characters that trigger signature help
- if g:LSP_Show_Signature && lspserver.caps->has_key('signatureHelpProvider')
+ if lspOptions.showSignature &&
+ lspserver.caps->has_key('signatureHelpProvider')
var triggers = lspserver.caps.signatureHelpProvider.triggerCharacters
for ch in triggers
exe 'inoremap <buffer> <silent> ' .. ch .. ' ' .. ch
endfor
endif
+ # Set buffer local autocmds
+ augroup LSPBufferAutocmds
+ # file saved notification handler
+ exe 'autocmd BufWritePost <buffer=' .. bnr .. '> call s:lspSavedFile()'
+
+ if lspOptions.autoComplete
+ # Trigger 24x7 insert mode completion when text is changed
+ exe 'autocmd TextChangedI <buffer=' .. bnr .. '> call lsp#complete()'
+ endif
+
+ # Update the diagnostics when insert mode is stopped
+ exe 'autocmd InsertLeave <buffer=' .. bnr .. '> call lsp#leftInsertMode()'
+
+ if lspOptions.autoHighlight &&
+ lspserver.caps->has_key('documentHighlightProvider')
+ && lspserver.caps.documentHighlightProvider
+ # Highlight all the occurrences of the current keyword
+ exe 'autocmd CursorMoved <buffer=' .. bnr .. '> '
+ .. 'call lsp#docHighlightClear() | call lsp#docHighlight()'
+ endif
+ augroup END
+
bufnrToServer[bnr] = lspserver
enddef
return
endif
- var newName: string = input("Enter new name: ", expand('<cword>'))
+ var newName: string = input("Rename symbol: ", expand('<cword>'))
if newName == ''
return
endif
Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
For Vim version 8.2.2342 and above
-Last change: Feb 24, 2021
+Last change: Nov 13, 2021
==============================================================================
*lsp-license*
License: MIT License
-Copyright (c) 2020 Yegappan Lakshmanan
+Copyright (c) 2020-2021 Yegappan Lakshmanan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
The popup is also automatically displayed in insert
mode after entering a symbol name followed by a
- separator (e.g. a opening parenthesis). Unless if: >
- let g:LSP_Show_Signature = v:false.
+ separator (e.g. a opening parenthesis). To disable
+ this, you can set the showSignature option to false in
+ your .vimrc file: >
+
+ call lsp#setOptions({showSignature: v:false})
<
Default is true.
You can get the function signature echoed in cmdline
rather than displayed in popup if you use >
- let g:LSP_Echo_Signature = v:true
+
+ call lsp#setOptions({echoSignature: v:true})
<
- Default is false
+ Default is false.
*:LspDiagShow*
:LspDiagShow Creates a new location list with the diagnostics
for the symbol under the cursor in an insert-completion popup menu. You can
use the keys described in |popupmenu-keys| with this menu.
-To disable the auto-compeltion, you can set the LSP_24x7_Complete variable
-to v:false in your .vimrc file: >
+To disable the auto-compeltion, you can set the autoComplete option to v:false
+in your .vimrc file: >
- let g:LSP_24x7_Complete = v:false
+ call lsp#setOptions({'autoComplete': v:false})
<
If this variable is set, then the LSP plugin doesn't automatically start
completion in insert mode and instead supports omni-completion (|compl-omni|).
finish
endif
-" Perform completion in insert mode automatically. Otherwise use
-" omni-complete.
-if !exists('g:LSP_24x7_Complete')
- let g:LSP_24x7_Complete = v:true
-endif
-
-if !exists('g:LSP_Show_Signature')
- let g:LSP_Show_Signature = v:true
-endif
-
-if !exists('g:LSP_Echo_Signature')
- let g:LSP_Echo_Signature = v:false
-endif
-
augroup LSPAutoCmds
au!
autocmd BufNewFile,BufReadPost *