]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Move all the user configurable options to a dictionary and add a function to set...
authorYegappan Lakshmanan <yegappan@yahoo.com>
Sat, 13 Nov 2021 17:44:00 +0000 (09:44 -0800)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Sat, 13 Nov 2021 17:44:00 +0000 (09:44 -0800)
autoload/handlers.vim
autoload/lsp.vim
doc/lsp.txt
plugin/lsp.vim

index e895a79b9c2224bf90f4b66ad8dafa22e3f3eb0c..5cf9d12a9688023847c75b4687c8794bfc27a510 100644 (file)
@@ -4,6 +4,7 @@ vim9script
 # 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,
@@ -25,18 +26,27 @@ def s:processInitializeReply(lspserver: dict<any>, req: dict<any>, reply: dict<a
   # 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()
 
@@ -130,7 +140,7 @@ def s:processSignaturehelpReply(lspserver: dict<any>, req: dict<any>, reply: dic
       startcol = text->stridx(label)
     endif
   endif
-  if g:LSP_Echo_Signature
+  if lspOptions.showSignature
     echon "\r\r"
     echon ''
     echon strpart(text, 0, startcol)
@@ -227,7 +237,7 @@ def s:processCompletionReply(lspserver: dict<any>, req: dict<any>, reply: dict<a
     completeItems->add(d)
   endfor
 
-  if g:LSP_24x7_Complete
+  if lspOptions.autoComplete
     if completeItems->empty()
       # no matches
       return
index 27981f058275e2784a6ffd46bb7199a55a2cdb04..66e43e807091e28097c5bd67c00a0a0c80ffd869 100644 (file)
@@ -2,6 +2,7 @@ vim9script
 
 # Vim9 LSP client
 
+import lspOptions from './lspoptions.vim'
 import NewLspServer from './lspserver.vim'
 import {WarnMsg,
        ErrMsg,
@@ -30,6 +31,13 @@ var bufnrToServer: dict<dict<any>> = {}
 
 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',
@@ -238,6 +246,12 @@ def g:LspDiagExpr(): string
     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
 
@@ -283,18 +297,13 @@ def lsp#addFile(bnr: number): void
   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
@@ -304,10 +313,10 @@ def lsp#addFile(bnr: number): void
   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
@@ -315,6 +324,28 @@ def lsp#addFile(bnr: number): void
     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
 
@@ -1139,7 +1170,7 @@ def lsp#rename()
     return
   endif
 
-  var newName: string = input("Enter new name: ", expand('<cword>'))
+  var newName: string = input("Rename symbol: ", expand('<cword>'))
   if newName == ''
     return
   endif
index 3f8e4ae0d03405768a64d43fbab689cf569f6bf1..5246d998bfad27897e699d13eab7ad718b058920 100644 (file)
@@ -2,12 +2,12 @@
 
 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
@@ -214,16 +214,20 @@ accepts a list of LSP servers with the above information.
 
                        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
@@ -366,10 +370,10 @@ By default, in insert mode, the LSP plugin automatically displays the matches
 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|).
index 512b57be9a9b19dd2977632bdd581ce40c6c13d4..8683e639089068d7879f39e45e49bb0d3b81f521 100644 (file)
@@ -5,20 +5,6 @@ if v:version < 802 || !has('patch-8.2.2342')
   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 *