1 if !has('vim9script') || v:version < 900
2 " Needs Vim version 9.0 and above
8 # Language Server Protocol (LSP) plugin for vim
12 import '../autoload/lsp/options.vim'
13 import autoload '../autoload/lsp/lsp.vim'
15 # Set LSP plugin options from 'opts'.
16 def g:LspOptionsSet(opts: dict<any>)
17 options.OptionsSet(opts)
20 # Return a copy of all the LSP plugin options
21 def g:LspOptionsGet(): dict<any>
22 return options.OptionsGet()
25 # Add one or more LSP servers in 'serverList'
26 def g:LspAddServer(serverList: list<dict<any>>)
27 lsp.AddServer(serverList)
30 # Register 'Handler' callback function for LSP command 'cmd'.
31 def g:LspRegisterCmdHandler(cmd: string, Handler: func)
32 lsp.RegisterCmdHandler(cmd, Handler)
35 # Returns true if the language server for the current buffer is initialized
36 # and ready to accept requests.
37 def g:LspServerReady(): bool
38 return lsp.ServerReady()
41 # Returns true if the language server for 'ftype' file type is running
42 def g:LspServerRunning(ftype: string): bool
43 return lsp.ServerRunning(ftype)
48 autocmd BufNewFile,BufReadPost,FileType * lsp.AddFile(expand('<abuf>')->str2nr())
49 # Note that when BufWipeOut is invoked, the current buffer may be different
50 # from the buffer getting wiped out.
51 autocmd BufWipeOut * lsp.RemoveFile(expand('<abuf>')->str2nr())
52 autocmd BufWinEnter * lsp.BufferLoadedInWin(expand('<abuf>')->str2nr())
55 # TODO: Is it needed to shutdown all the LSP servers when exiting Vim?
56 # This takes some time.
57 # autocmd VimLeavePre * call lsp.StopAllServers()
60 command! -nargs=? -bar -range LspCodeAction lsp.CodeAction(<line1>, <line2>, <q-args>)
61 command! -nargs=0 -bar LspCodeLens lsp.CodeLens()
62 command! -nargs=0 -bar -bang LspDiagCurrent lsp.LspShowCurrentDiag(<bang>false)
63 command! -nargs=0 -bar LspDiagFirst lsp.JumpToDiag('first')
64 command! -nargs=0 -bar LspDiagHighlightDisable lsp.DiagHighlightDisable()
65 command! -nargs=0 -bar LspDiagHighlightEnable lsp.DiagHighlightEnable()
66 command! -nargs=0 -bar LspDiagLast lsp.JumpToDiag('last')
67 command! -nargs=0 -bar -count=1 LspDiagNext lsp.JumpToDiag('next', <count>)
68 command! -nargs=0 -bar -count=1 LspDiagPrev lsp.JumpToDiag('prev', <count>)
69 command! -nargs=0 -bar LspDiagShow lsp.ShowDiagnostics()
70 command! -nargs=0 -bar LspDiagHere lsp.JumpToDiag('here')
71 command! -nargs=0 -bar LspDocumentSymbol lsp.ShowDocSymbols()
72 command! -nargs=0 -bar LspFold lsp.FoldDocument()
73 command! -nargs=0 -bar -range=% LspFormat lsp.TextDocFormat(<range>, <line1>, <line2>)
74 command! -nargs=0 -bar -count LspGotoDeclaration lsp.GotoDeclaration(v:false, <q-mods>, <count>)
75 command! -nargs=0 -bar -count LspGotoDefinition lsp.GotoDefinition(v:false, <q-mods>, <count>)
76 command! -nargs=0 -bar -count LspGotoImpl lsp.GotoImplementation(v:false, <q-mods>, <count>)
77 command! -nargs=0 -bar -count LspGotoTypeDef lsp.GotoTypedef(v:false, <q-mods>, <count>)
78 command! -nargs=0 -bar LspHighlight call LspDocHighlight(<q-mods>)
79 command! -nargs=0 -bar LspHighlightClear call LspDocHighlightClear()
80 command! -nargs=? -bar LspHover lsp.Hover(<q-mods>)
81 command! -nargs=1 -bar -complete=customlist,lsp.LspInlayHintsComplete LspInlayHints lsp.InlayHints(<q-args>)
82 command! -nargs=0 -bar LspIncomingCalls lsp.IncomingCalls()
83 command! -nargs=0 -bar LspOutgoingCalls lsp.OutgoingCalls()
84 command! -nargs=0 -bar -count LspOutline lsp.Outline(<q-mods>, <count>)
85 command! -nargs=0 -bar -count LspPeekDeclaration lsp.GotoDeclaration(v:true, <q-mods>, <count>)
86 command! -nargs=0 -bar -count LspPeekDefinition lsp.GotoDefinition(v:true, <q-mods>, <count>)
87 command! -nargs=0 -bar -count LspPeekImpl lsp.GotoImplementation(v:true, <q-mods>, <count>)
88 command! -nargs=0 -bar LspPeekReferences lsp.ShowReferences(v:true)
89 command! -nargs=0 -bar -count LspPeekTypeDef lsp.GotoTypedef(v:true, <q-mods>, <count>)
90 command! -nargs=? -bar LspRename lsp.Rename(<q-args>)
91 command! -nargs=0 -bar LspSelectionExpand lsp.SelectionExpand()
92 command! -nargs=0 -bar LspSelectionShrink lsp.SelectionShrink()
93 command! -nargs=+ -bar -complete=customlist,lsp.LspServerComplete LspServer lsp.LspServerCmd(<q-args>)
94 command! -nargs=0 -bar LspShowReferences lsp.ShowReferences(v:false)
95 command! -nargs=0 -bar LspShowAllServers lsp.ShowAllServers()
96 command! -nargs=0 -bar LspShowSignature call LspShowSignature()
97 command! -nargs=0 -bar LspSubTypeHierarchy lsp.TypeHierarchy(0)
98 command! -nargs=0 -bar LspSuperTypeHierarchy lsp.TypeHierarchy(1)
99 # Clangd specifc extension to switch from one C/C++ source file to a
100 # corresponding header file
101 command! -nargs=0 -bar LspSwitchSourceHeader lsp.SwitchSourceHeader()
102 command! -nargs=? -bar LspSymbolSearch lsp.SymbolSearch(<q-args>, <q-mods>)
103 command! -nargs=1 -bar -complete=dir LspWorkspaceAddFolder lsp.AddWorkspaceFolder(<q-args>)
104 command! -nargs=0 -bar LspWorkspaceListFolders lsp.ListWorkspaceFolders()
105 command! -nargs=1 -bar -complete=dir LspWorkspaceRemoveFolder lsp.RemoveWorkspaceFolder(<q-args>)
107 # Add the GUI menu entries
108 if has('gui_running')
109 anoremenu <silent> L&sp.Goto.Definition :LspGotoDefinition<CR>
110 anoremenu <silent> L&sp.Goto.Declaration :LspGotoDeclaration<CR>
111 anoremenu <silent> L&sp.Goto.Implementation :LspGotoImpl<CR>
112 anoremenu <silent> L&sp.Goto.TypeDef :LspGotoTypeDef<CR>
114 anoremenu <silent> L&sp.Show\ Signature :LspShowSignature<CR>
115 anoremenu <silent> L&sp.Show\ References :LspShowReferences<CR>
116 anoremenu <silent> L&sp.Show\ Detail :LspHover<CR>
117 anoremenu <silent> L&sp.Outline :LspOutline<CR>
119 anoremenu <silent> L&sp.Goto\ Symbol :LspDocumentSymbol<CR>
120 anoremenu <silent> L&sp.Symbol\ Search :LspSymbolSearch<CR>
121 anoremenu <silent> L&sp.Outgoing\ Calls :LspOutgoingCalls<CR>
122 anoremenu <silent> L&sp.Incoming\ Calls :LspIncomingCalls<CR>
123 anoremenu <silent> L&sp.Rename :LspRename<CR>
124 anoremenu <silent> L&sp.Code\ Action :LspCodeAction<CR>
126 anoremenu <silent> L&sp.Highlight\ Symbol :LspHighlight<CR>
127 anoremenu <silent> L&sp.Highlight\ Clear :LspHighlightClear<CR>
130 anoremenu <silent> L&sp.Diagnostics.Current :LspDiagCurrent<CR>
131 anoremenu <silent> L&sp.Diagnostics.Show\ All :LspDiagShow<CR>
132 anoremenu <silent> L&sp.Diagnostics.First :LspDiagFirst<CR>
133 anoremenu <silent> L&sp.Diagnostics.Last :LspDiagLast<CR>
134 anoremenu <silent> L&sp.Diagnostics.Next :LspDiagNext<CR>
135 anoremenu <silent> L&sp.Diagnostics.Prev :LspDiagPrev<CR>
136 anoremenu <silent> L&sp.Diagnostics.This :LspDiagHere<CR>
138 if &mousemodel =~ 'popup'
139 anoremenu <silent> PopUp.L&sp.Go\ to\ Definition
140 \ :LspGotoDefinition<CR>
141 anoremenu <silent> PopUp.L&sp.Go\ to\ Declaration
142 \ :LspGotoDeclaration<CR>
143 anoremenu <silent> PopUp.L&sp.Find\ All\ References
144 \ :LspShowReferences<CR>
145 anoremenu <silent> PopUp.L&sp.Show\ Detail
147 anoremenu <silent> PopUp.L&sp.Highlight\ Symbol
149 anoremenu <silent> PopUp.L&sp.Highlight\ Clear
150 \ :LspHighlightClear<CR>
154 # vim: shiftwidth=2 softtabstop=2