]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Add a test for omni completion. Update the help text
authorYegappan Lakshmanan <yegappan@yahoo.com>
Fri, 24 Mar 2023 14:21:52 +0000 (07:21 -0700)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Fri, 24 Mar 2023 14:21:52 +0000 (07:21 -0700)
autoload/lsp/completion.vim
autoload/lsp/lspserver.vim
doc/lsp.txt
test/clangd_tests.vim
test/common.vim

index 51c35eaf7b85a2d75cd55d9ec694fc25a0a043b8..84867338d97fb0b88173adb5e0ae42b60306f9ed 100644 (file)
@@ -98,6 +98,8 @@ export def CompletionReply(lspserver: dict<any>, cItems: any)
 
   var start_col = start_idx + 1
 
+  #writefile([$'chcol = {chcol}, starttext = [{starttext}], prefix = [{prefix}], start_idx = {start_idx}, end_idx = {end_idx}, start_col = {start_col}'], '/tmp/lspcomplete.log', 'a')
+
   var completeItems: list<dict<any>> = []
   for item in items
     var d: dict<any> = {}
@@ -496,7 +498,7 @@ export def BufferInit(lspserver: dict<any>, bnr: number, ftype: string)
     endif
   else
     if LspOmniComplEnabled(ftype)
-      setbufvar(bnr, '&omnifunc', 'LspOmniFunc')
+      setbufvar(bnr, '&omnifunc', 'g:LspOmniFunc')
     endif
   endif
 
index dc5a7227b2a9cda0e6b00187ad5d45947eb78a88..e959c7c1a11271b7d653381aa147f3067ca8916f 100644 (file)
@@ -622,7 +622,7 @@ def Rpc(lspserver: dict<any>, method: string, params: any, handleError: bool = t
     return reply
   endif
 
-  if handleError && reply->has_key('error')
+  if reply->has_key('error') && handleError
     # request failed
     var emsg: string = reply.error.message
     emsg ..= $', code = {reply.error.code}'
index f1fd20935d8d9ca5f92dd00a7aa2b998185b743d..727e0952056e4213c24157d36126c5e0b16dc09e 100644 (file)
@@ -2,7 +2,7 @@
 
 Author: Yegappan Lakshmanan  (yegappan AT yahoo DOT com)
 For Vim version 9.0 and above
-Last change: March 16, 2023
+Last change: March 24, 2023
 
 ==============================================================================
                                                *lsp-license*
@@ -266,68 +266,73 @@ Some of the LSP plugin features can be enabled or disabled by using the
 LspOptionsSet() function. This function accepts a dictionary argument with the
 following optional items:
 
-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
-                       occurrences of the symbol under the cursor. By default
-                       this is set to false.
-autoHighlightDiags     Automatically place signs on the lines with a
-                       diagnostic message from the language server. By
-                       default this is set to true.
-autoPopulateDiags      Automatically populate the location list with
-                       diagnostics from the language server. By default this
-                       is set to false.
-diagLineHL             Highlight used for diagnostic line.
-                       By default uses `Cursor`.
-                       Use `NONE` to disable.
-echoSignature          In insert mode, echo the current symbol signature
-                       instead of showing it in a popup. By default this is
-                       set to false.
-completionMatcher      Enable fuzzy or incase sensitive completion for language
-                       servers that replies with a full list of completion
-                       items.  Some language servers does completion filtering
-                       in the server, while other relies on the client to do
-                       the filtering.
+autoComplete           |Boolean| option. In insert mode, automatically
+                       complete the current symbol. Otherwise use
+                       omni-completion. By default this is set to true.
+autoHighlight          |Boolean| option. In normal mode, automatically
+                       highlight all the occurrences of the symbol under the
+                       cursor. By default this is set to false.
+autoHighlightDiags     |Boolean| option. Automatically place signs on the
+                       lines with a diagnostic message from the language
+                       server. By default this is set to true.
+autoPopulateDiags      |Boolean| option. Automatically populate the location
+                       list with diagnostics from the language server.
+                       By default this is set to false.
+diagLineHL             |String| option. Highlight used for diagnostic line.
+                       By default uses `Cursor`.  Use `NONE` to disable.
+echoSignature          |Boolean| option.  In insert mode, echo the current
+                       symbol signature instead of showing it in a popup.
+                       By default this is set to false.
+completionMatcher      |String| option.  Enable fuzzy or case insensitive
+                       completion for language servers that replies with a
+                       full list of completion items.  Some language servers
+                       does completion filtering in the server, while other
+                       relies on the client to do the filtering.
 
                        This option only works for language servers that expect
                        the client to filter the completion items.
 
-                       Can be either `fuzzy`, `icase` or `case`, default is
-                       `case`.
-hideDisabledCodeActions Hide all disabled code actions
-ignoreMissingServer    Do not print a missing language server executable.
+                       This option accepts one of the following values:
+                           case  - case sensitive matching (default).
+                           fuzzy - fuzzy match completion items.
+                           icase - ignore case when matching items.
+hideDisabledCodeActions |Boolean| option. Hide all the disabled code actions.
                        By default this is set to false.
-keepFocusInReferences  Focus on the location list window after
-                       LspShowReferences.  By default this is set to 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.
-noNewlineInCompletion  Suppress adding a new line on completion selection
-                       with <CR>.
+ignoreMissingServer    |Boolean| option.  Do not print a missing language
+                       server executable.  By default this is set to false.
+keepFocusInReferences  |Boolean| option.  Focus on the location list window
+                       after LspShowReferences.
                        By default this is set to false.
-outlineOnRight         Open the outline window on the right side, by default
-                       this is false.
-outlineWinSize         Outline window size, by default this is 20.
-showDiagInPopup                When using the |:LspDiagCurrent| command to display
-                       the diagnostic message for the current line, use a
-                       popup window to display the message instead of
-                       echoing in the status area.  By default this is set to
-                       true.
-showDiagOnStatusLine   Show a diagnostic message on a status line.
+noDiagHoverOnLine      |Boolean| option.  Suppress diagnostic hover from
+                       appearing when the mouse is over the line instead of
+                       the signature.  By default this is set to true.
+noNewlineInCompletion  |Boolean| option.  Suppress adding a new line on
+                       completion selection with <CR>.
                        By default this is set to false.
-showInlayHints         Show inlay hints from the language server.  By default
-                       this is set to false.  The inlay hint text is
-                       displayed as a virtual text.  Needs Vim version
-                       9.0.0178 or later.
-showSignature          In insert mode, automatically show the current symbol
-                       signature in a popup. By default this is set to true.
-snippetSupport         Enable snippet completion support.  Need a snippet
-                       completion plugin like vim-vsnip. By default this is
-                       set to false.
-usePopupInCodeAction    When using the |:LspCodeAction| command to display the
-                       code action for the current line, use a popup menu
-                       instead of echoing.
+outlineOnRight         |Boolean| option.  Open the outline window on the
+                       right side, by default this is false.
+outlineWinSize         |Number| option.  The size of the symbol Outline
+                       window.  By default this is set to 20.
+showDiagInPopup                |Boolean| option.  When using the |:LspDiagCurrent|
+                       command to display the diagnostic message for the
+                       current line, use a popup window to display the
+                       message instead of echoing in the status area.
+                       By default this is set to true.
+showDiagOnStatusLine   |Boolean| option.  Show a diagnostic message on a
+                       status line.  By default this is set to false.
+showInlayHints         |Boolean| option.  Show inlay hints from the language
+                       server.  By default this is set to false.  The inlay
+                       hint text is displayed as a virtual text.  Needs Vim
+                       version 9.0.0178 or later.
+showSignature          |Boolean| option.  In insert mode, automatically show
+                       the current symbol signature in a popup.
+                       By default this is set to true.
+snippetSupport         |Boolean| option.  Enable snippet completion support.
+                       Need a snippet completion plugin like vim-vsnip.
+                       By default this is set to false.
+usePopupInCodeAction    |Boolean| option.  When using the |:LspCodeAction|
+                       command to display the code action for the current
+                       line, use a popup menu instead of echoing.
                        By default this is set to false.
 
 For example, to disable the automatic placement of signs for the LSP
@@ -754,13 +759,23 @@ default. The following example disables omni-completion for python: >
                \   ]
 <
 If you want to use omni completion, in addition to the automatic completion,
-then you can set the 'omnifunc' option to the "LspOmniFunc" function: >
+then you can set the 'omnifunc' option to the "g:LspOmniFunc" function: >
 
-       set omnifunc=LspOmniFunc
+       set omnifunc=g:LspOmniFunc
 <
 To use omni completion, press CTRL-X CTRL-O in insert mode.  Refer to
 |compl-omni| for more information.
 
+When doing insert-mode completion, the plugin sends a request message to the
+language server to return a list of possible completion matches for the
+current cursor position.  The plugin retrieves the keyword before the cursor
+(see 'iskeyword') and then filters the returned list of completion items
+against this keyword and displays the completion menu.  Some language servers
+does completion filtering in the server, while other relies on the client to
+do the filtering.  By default, case sensitive comparison is used to filter the
+returned items.  You can modify the 'completionMatcher' option to use either
+case insensitive or fuzzy comparison.
+
 ==============================================================================
 7. Diagnostics
 
index f405a860456cc559e66461529b7e5722817734bc..a817cb07bf234b0f29a4b0c40e7bb4580f7751f3 100644 (file)
@@ -3,6 +3,9 @@ vim9script
 
 source common.vim
 
+var lspOpts = {autoComplete: false}
+g:LspOptionsSet(lspOpts)
+
 var lspServers = [{
       filetype: ['c', 'cpp'],
       path: (exepath('clangd-14') ?? exepath('clangd')),
@@ -957,6 +960,25 @@ def g:Test_ScanFindIdent()
   bw!
 enddef
 
+# Test for doing omni completion from the first column
+def g:Test_OmniComplete_FirstColumn()
+  :silent! edit Xtest.c
+  sleep 200m
+  var lines: list<string> =<< trim END
+    typedef struct Foo_ {
+    } Foo_t;
+
+    #define FOO 1
+  END
+  setline(1, lines)
+  :sleep 1
+  redraw!
+
+  feedkeys("G0i\<C-X>\<C-O>", 'xt')
+  assert_equal('Foo_t#define FOO 1', getline('.'))
+  :bw!
+enddef
+
 # TODO:
 # 1. Add a test for autocompletion with a single match while ignoring case.
 #    After the full matched name is typed, the completion popup should still
@@ -964,6 +986,7 @@ enddef
 #
 #      int MyVar = 1;
 #      int abc = myvar<C-N><C-Y>
+# 2. Add a test for jumping to a non-existing symbol definition, declaration.
 
 # Start the C language server.  Returns true on success and false on failure.
 def g:StartLangServer(): bool
index 5a3e9aa6e6ecc19fdd47c8d53e5ed790d9f9d100..135b7f0842bf72d598f5400763b9507a9cf60fa3 100644 (file)
@@ -20,9 +20,8 @@ def g:LoadLspPlugin()
       profile! file */lsp/*
   endif
 
-  source ../plugin/lsp.vim
-
   g:LSPTest = true
+  source ../plugin/lsp.vim
 enddef
 
 # The WaitFor*() functions are reused from the Vim test suite.