From 97263fd235d399400cbc775c2a9a62497e8341a6 Mon Sep 17 00:00:00 2001 From: Andreas Louv Date: Sun, 16 Apr 2023 20:28:42 +0200 Subject: [PATCH] Make ":LspOutline" work like "outlineWinSize" --- autoload/lsp/lsp.vim | 4 ++-- autoload/lsp/outline.vim | 9 +++++++-- plugin/lsp.vim | 2 +- test/clangd_tests.vim | 9 +++++++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index 945ea47..4b8456b 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -801,8 +801,8 @@ def g:LspRequestDocSymbols() enddef # open a window and display all the symbols in a file (outline) -export def Outline(cmdmods: string) - outline.OpenOutlineWindow(cmdmods) +export def Outline(cmdmods: string, winsize: number) + outline.OpenOutlineWindow(cmdmods, winsize) g:LspRequestDocSymbols() enddef diff --git a/autoload/lsp/outline.vim b/autoload/lsp/outline.vim index b42fe64..7a337b3 100644 --- a/autoload/lsp/outline.vim +++ b/autoload/lsp/outline.vim @@ -218,7 +218,7 @@ def OutlineCleanup() enddef # open the symbol outline window -export def OpenOutlineWindow(cmdmods: string) +export def OpenOutlineWindow(cmdmods: string, winsize: number) var wid: number = bufwinid('LSP-Outline') if wid != -1 return @@ -235,7 +235,12 @@ export def OpenOutlineWindow(cmdmods: string) endif endif - execute $'{mods} :{opt.lspOptions.outlineWinSize}new LSP-Outline' + var size = winsize + if size == 0 + size = opt.lspOptions.outlineWinSize + endif + + execute $'{mods} :{size}new LSP-Outline' :setlocal modifiable :setlocal noreadonly :silent! :%d _ diff --git a/plugin/lsp.vim b/plugin/lsp.vim index 4abb8b9..1e282da 100644 --- a/plugin/lsp.vim +++ b/plugin/lsp.vim @@ -78,7 +78,7 @@ command! -nargs=0 -bar LspHighlightClear call LspDocHighlightClear() command! -nargs=0 -bar LspHover lsp.Hover() command! -nargs=0 -bar LspIncomingCalls lsp.IncomingCalls() command! -nargs=0 -bar LspOutgoingCalls lsp.OutgoingCalls() -command! -nargs=0 -bar LspOutline lsp.Outline() +command! -nargs=0 -bar -count LspOutline lsp.Outline(, ) command! -nargs=0 -bar LspPeekDeclaration lsp.GotoDeclaration(v:true, ) command! -nargs=0 -bar LspPeekDefinition lsp.GotoDefinition(v:true, ) command! -nargs=0 -bar LspPeekImpl lsp.GotoImplementation(v:true, ) diff --git a/test/clangd_tests.vim b/test/clangd_tests.vim index 4fb057b..f9a5f98 100644 --- a/test/clangd_tests.vim +++ b/test/clangd_tests.vim @@ -1191,6 +1191,15 @@ def g:Test_LspOutline() execute $':{bnum}bw' g:LspOptionsSet({ outlineWinSize: 20 }) + # Validate that works for LspOutline + :37LspOutline + assert_equal(2, winnr('$')) + bnum = winbufnr(winid + 5) + assert_equal('LSP-Outline', bufname(bnum)) + assert_equal(['Function', ' aFunc', ' bFunc'], getbufline(bnum, 4, '$')) + assert_equal(37, winwidth(winid + 5)) + execute $':{bnum}bw' + :%bw! enddef -- 2.50.0