From aeabdffa8870c2b90a32f53c1d0e5b63367a6e27 Mon Sep 17 00:00:00 2001 From: Marc Coquand Date: Sun, 30 Jun 2024 17:20:44 -0500 Subject: Vim --- vim/pack/downloads/opt/lsp/plugin/lsp.vim | 163 ++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 vim/pack/downloads/opt/lsp/plugin/lsp.vim (limited to 'vim/pack/downloads/opt/lsp/plugin') diff --git a/vim/pack/downloads/opt/lsp/plugin/lsp.vim b/vim/pack/downloads/opt/lsp/plugin/lsp.vim new file mode 100644 index 0000000..3b3815a --- /dev/null +++ b/vim/pack/downloads/opt/lsp/plugin/lsp.vim @@ -0,0 +1,163 @@ +if !has('vim9script') || v:version < 900 + " Needs Vim version 9.0 and above + finish +endif + +vim9script noclear + +# Language Server Protocol (LSP) plugin for vim + +if get(g:, 'loaded_lsp', false) + finish +endif +g:loaded_lsp = true + +import '../autoload/lsp/options.vim' +import autoload '../autoload/lsp/lsp.vim' + +# Set LSP plugin options from 'opts'. +def g:LspOptionsSet(opts: dict) + options.OptionsSet(opts) +enddef + +# Return a copy of all the LSP plugin options +def g:LspOptionsGet(): dict + return options.OptionsGet() +enddef + +# Add one or more LSP servers in 'serverList' +def g:LspAddServer(serverList: list>) + lsp.AddServer(serverList) +enddef + +# Register 'Handler' callback function for LSP command 'cmd'. +def g:LspRegisterCmdHandler(cmd: string, Handler: func) + lsp.RegisterCmdHandler(cmd, Handler) +enddef + +# Returns true if the language server for the current buffer is initialized +# and ready to accept requests. +def g:LspServerReady(): bool + return lsp.ServerReady() +enddef + +# Returns true if the language server for 'ftype' file type is running +def g:LspServerRunning(ftype: string): bool + return lsp.ServerRunning(ftype) +enddef + +augroup LSPAutoCmds + au! + autocmd BufNewFile,BufReadPost,FileType * lsp.AddFile(expand('')->str2nr()) + # Note that when BufWipeOut is invoked, the current buffer may be different + # from the buffer getting wiped out. + autocmd BufWipeOut * lsp.RemoveFile(expand('')->str2nr()) + autocmd BufWinEnter * lsp.BufferLoadedInWin(expand('')->str2nr()) +augroup END + +# TODO: Is it needed to shutdown all the LSP servers when exiting Vim? +# This takes some time. +# autocmd VimLeavePre * call lsp.StopAllServers() + +# LSP commands +command! -nargs=? -bar -range LspCodeAction lsp.CodeAction(, , ) +command! -nargs=0 -bar LspCodeLens lsp.CodeLens() +command! -nargs=+ -bar -bang -count -complete=customlist,lsp.LspDiagComplete LspDiag lsp.LspDiagCmd(, , false) +command! -nargs=0 -bar -bang LspDiagCurrent lsp.LspShowCurrentDiag(false) +command! -nargs=0 -bar LspDiagFirst lsp.JumpToDiag('first') +command! -nargs=0 -bar LspDiagLast lsp.JumpToDiag('last') +command! -nargs=0 -bar -count=1 LspDiagNext lsp.JumpToDiag('next', ) +command! -nargs=0 -bar -count=1 LspDiagNextWrap lsp.JumpToDiag('nextWrap', ) +command! -nargs=0 -bar -count=1 LspDiagPrev lsp.JumpToDiag('prev', ) +command! -nargs=0 -bar -count=1 LspDiagPrevWrap lsp.JumpToDiag('prevWrap', ) +command! -nargs=0 -bar LspDiagShow lsp.ShowDiagnostics() +command! -nargs=0 -bar LspDiagHere lsp.JumpToDiag('here') +command! -nargs=0 -bar LspDocumentSymbol lsp.ShowDocSymbols() +command! -nargs=0 -bar LspFold lsp.FoldDocument() +command! -nargs=0 -bar -range=% LspFormat lsp.TextDocFormat(, , ) +command! -nargs=0 -bar -count LspGotoDeclaration lsp.GotoDeclaration(v:false, , ) +command! -nargs=0 -bar -count LspGotoDefinition lsp.GotoDefinition(v:false, , ) +command! -nargs=0 -bar -count LspGotoImpl lsp.GotoImplementation(v:false, , ) +command! -nargs=0 -bar -count LspGotoTypeDef lsp.GotoTypedef(v:false, , ) +command! -nargs=0 -bar LspHighlight call LspDocHighlight(bufnr(), ) +command! -nargs=0 -bar LspHighlightClear call LspDocHighlightClear() +command! -nargs=? -bar LspHover lsp.Hover() +command! -nargs=1 -bar -complete=customlist,lsp.LspInlayHintsComplete LspInlayHints lsp.InlayHints() +command! -nargs=0 -bar LspIncomingCalls lsp.IncomingCalls() +command! -nargs=0 -bar LspOutgoingCalls lsp.OutgoingCalls() +command! -nargs=0 -bar -count LspOutline lsp.Outline(, ) +command! -nargs=0 -bar -count LspPeekDeclaration lsp.GotoDeclaration(v:true, , ) +command! -nargs=0 -bar -count LspPeekDefinition lsp.GotoDefinition(v:true, , ) +command! -nargs=0 -bar -count LspPeekImpl lsp.GotoImplementation(v:true, , ) +command! -nargs=0 -bar LspPeekReferences lsp.ShowReferences(v:true) +command! -nargs=0 -bar -count LspPeekTypeDef lsp.GotoTypedef(v:true, , ) +command! -nargs=? -bar LspRename lsp.Rename() +command! -nargs=0 -bar LspSelectionExpand lsp.SelectionExpand() +command! -nargs=0 -bar LspSelectionShrink lsp.SelectionShrink() +command! -nargs=+ -bar -complete=customlist,lsp.LspServerComplete LspServer lsp.LspServerCmd() +command! -nargs=0 -bar LspShowReferences lsp.ShowReferences(v:false) +command! -nargs=0 -bar LspShowAllServers lsp.ShowAllServers() +command! -nargs=0 -bar LspShowSignature call LspShowSignature() +command! -nargs=0 -bar LspSubTypeHierarchy lsp.TypeHierarchy(0) +command! -nargs=0 -bar LspSuperTypeHierarchy lsp.TypeHierarchy(1) +# Clangd specifc extension to switch from one C/C++ source file to a +# corresponding header file +command! -nargs=0 -bar LspSwitchSourceHeader lsp.SwitchSourceHeader() +command! -nargs=? -bar LspSymbolSearch lsp.SymbolSearch(, ) +command! -nargs=1 -bar -complete=dir LspWorkspaceAddFolder lsp.AddWorkspaceFolder() +command! -nargs=0 -bar LspWorkspaceListFolders lsp.ListWorkspaceFolders() +command! -nargs=1 -bar -complete=dir LspWorkspaceRemoveFolder lsp.RemoveWorkspaceFolder() + +# Add the GUI menu entries +if has('gui_running') + anoremenu L&sp.Goto.Definition :LspGotoDefinition + anoremenu L&sp.Goto.Declaration :LspGotoDeclaration + anoremenu L&sp.Goto.Implementation :LspGotoImpl + anoremenu L&sp.Goto.TypeDef :LspGotoTypeDef + + anoremenu L&sp.Show\ Signature :LspShowSignature + anoremenu L&sp.Show\ References :LspShowReferences + anoremenu L&sp.Show\ Detail :LspHover + anoremenu L&sp.Outline :LspOutline + + anoremenu L&sp.Goto\ Symbol :LspDocumentSymbol + anoremenu L&sp.Symbol\ Search :LspSymbolSearch + anoremenu L&sp.Outgoing\ Calls :LspOutgoingCalls + anoremenu L&sp.Incoming\ Calls :LspIncomingCalls + anoremenu L&sp.Rename :LspRename + anoremenu L&sp.Code\ Action :LspCodeAction + + anoremenu L&sp.Highlight\ Symbol :LspHighlight + anoremenu L&sp.Highlight\ Clear :LspHighlightClear + + # Diagnostics + anoremenu L&sp.Diagnostics.Current :LspDiag current + anoremenu L&sp.Diagnostics.Show\ All :LspDiag show + anoremenu L&sp.Diagnostics.First :LspDiag first + anoremenu L&sp.Diagnostics.Last :LspDiag last + anoremenu L&sp.Diagnostics.Next :LspDiag next + anoremenu L&sp.Diagnostics.Previous :LspDiag prev + anoremenu L&sp.Diagnostics.This :LspDiag here + + if &mousemodel =~ 'popup' + anoremenu PopUp.L&sp.Go\ to\ Definition + \ :LspGotoDefinition + anoremenu PopUp.L&sp.Go\ to\ Declaration + \ :LspGotoDeclaration + anoremenu PopUp.L&sp.Find\ All\ References + \ :LspShowReferences + anoremenu PopUp.L&sp.Show\ Detail + \ :LspHover + anoremenu PopUp.L&sp.Highlight\ Symbol + \ :LspHighlight + anoremenu PopUp.L&sp.Highlight\ Clear + \ :LspHighlightClear + endif +endif + +# Invoke autocmd to register LSP servers and to set LSP options +if exists('#User#LspSetup') + :doautocmd User LspSetup +endif + +# vim: shiftwidth=2 softtabstop=2 -- cgit v1.2.3