Skip to content

Commit

Permalink
Update instructions for using vim-plug to install the plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
yegappan committed Jan 18, 2024
1 parent 255170b commit 9cff546
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 14 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ The following language server protocol (LSP) features are supported:
* Folding code
* Inlay hints
* Visually select symbol block/region
* Semantic Highlight

## Configuration

Expand Down Expand Up @@ -157,16 +158,16 @@ call LspOptionsSet(#{

If you used [vim-plug](https://github.com/junegunn/vim-plug) to install the LSP plugin, then you need to use the VimEnter autocmd to initialize the LSP server and to set the LSP server options. For example:
```viml
let lspOpts = #{autoHighlightDiags: v:true}
autocmd VimEnter * call LspOptionsSet(lspOpts)
let lspServers = [#{
\ name: 'clang',
\ filetype: ['c', 'cpp'],
\ path: '/usr/local/bin/clangd',
\ args: ['--background-index']
\ }]
autocmd VimEnter * call LspAddServer(lspServers)
let lspOpts = #{autoHighlightDiags: v:true}
autocmd VimEnter * call LspOptionsSet(lspOpts)
```

## Supported Commands
Expand Down
32 changes: 23 additions & 9 deletions autoload/lsp/symbol.vim
Original file line number Diff line number Diff line change
Expand Up @@ -454,15 +454,30 @@ export def ShowLocations(lspserver: dict<any>, locations: list<dict<any>>,
enddef

# Key filter callback function used for the symbol popup window.
# Vim doesn't close the popup window when the escape key is pressed.
# This is function supports that.
def SymbolFilterCB(lspserver: dict<any>, id: number, key: string): bool
if key == "\<Esc>"
lspserver.peekSymbolPopup->popup_close()
return true
def SymbolFilterCB(symPopupWin: number, key: string): bool
var keyHandled = false

if key == "\<C-E>"
|| key == "\<C-D>"
|| key == "\<C-F>"
|| key == "\<PageDown>"
|| key == "\<C-Y>"
|| key == "\<C-U>"
|| key == "\<C-B>"
|| key == "\<PageUp>"
|| key == "\<C-Home>"
|| key == "\<C-End>"
# scroll the popup window
win_execute(symPopupWin, $'normal! {key}')
keyHandled = true
endif

if !keyHandled
# For any other key, close the window
symPopupWin->popup_close()
endif

return false
return keyHandled
enddef

# Display the file specified by LSP "LocationLink" in a popup window and
Expand All @@ -481,7 +496,6 @@ def PeekSymbolLocation(lspserver: dict<any>, location: dict<any>)
# If the symbol popup window is already present, close it.
lspserver.peekSymbolPopup->popup_close()
endif
var CbFunc = function(SymbolFilterCB, [lspserver])
var popupAttrs = {
title: $"{fnamemodify(fname, ':t')} ({fnamemodify(fname, ':h')})",
wrap: false,
Expand All @@ -493,7 +507,7 @@ def PeekSymbolLocation(lspserver: dict<any>, location: dict<any>)
cursorline: true,
border: [],
mapping: false,
filter: CbFunc
filter: SymbolFilterCB
}
lspserver.peekSymbolPopup = popup_atcursor(bnum, popupAttrs)

Expand Down
9 changes: 7 additions & 2 deletions test/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@

# Script to run the unit-tests for the LSP Vim plugin

VIMPRG=${VIMPRG:=$(which vim)}
#VIMPRG=${VIMPRG:=$(which vim)}
#VIMPRG=/home/yega/bin/vim90/bin/vim
#VIMRUNTIME=/home/yega/bin/vim90/share/vim/vim90
export VIMPRG=/home/yega/Documents/vim/vim9/vim/src/vim
export VIMRUNTIME=/home/yega/Documents/vim/vim9/vim/runtime
if [ -z "$VIMPRG" ]; then
echo "ERROR: vim (\$VIMPRG) is not found in PATH"
exit 1
fi

VIM_CMD="$VIMPRG -u NONE -U NONE -i NONE --noplugin -N --not-a-term"

TESTS="clangd_tests.vim tsserver_tests.vim gopls_tests.vim not_lspserver_related_tests.vim markdown_tests.vim"
#TESTS="clangd_tests.vim tsserver_tests.vim gopls_tests.vim not_lspserver_related_tests.vim markdown_tests.vim"
TESTS="clangd_tests.vim"

RunTestsInFile() {
testfile=$1
Expand Down
36 changes: 36 additions & 0 deletions test/tsserver_tests.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ source common.vim
source term_util.vim
source screendump.vim

var lspOpts = {autoComplete: false}
g:LspOptionsSet(lspOpts)

var lspServers = [{
filetype: ['typescript', 'javascript'],
path: exepath('typescript-language-server'),
Expand Down Expand Up @@ -34,6 +37,39 @@ echomsg systemlist($'{lspServers[0].path} --version')
# delete('Xcompletion1.js')
# enddef

# Test for auto-import using omni completion
def g:Test_autoimport()
:silent! edit autoImportMod1.ts
sleep 200m
var lines =<< trim END
export function getNumber() {
return 1;
}
END
setline(1, lines)
:redraw!
g:WaitForServerFileLoad(0)

var save_completopt = &completeopt
set completeopt=

:split autoImportMod2.ts
:sleep 200m
setline(1, 'console.log(getNum')
g:WaitForServerFileLoad(2)
feedkeys("A\<C-X>\<C-O>());", 'xt')
var expected =<< trim END
import { getNumber } from "./autoImportMod1";

());console.log(getNumber
END
assert_equal(expected, getline(1, '$'))

&completeopt = save_completopt

:%bw!
enddef

# Start the typescript language server. Returns true on success and false on
# failure.
def g:StartLangServer(): bool
Expand Down

0 comments on commit 9cff546

Please sign in to comment.