diff --git a/Emacs.md b/Emacs.md index f012ac9..a9b4cb4 100644 --- a/Emacs.md +++ b/Emacs.md @@ -133,49 +133,50 @@ For a symbol named `Name::FooBar`, all of `FooBar`, `foo bar`, `nafoba` find the Aside from definitions/references/workspace symbol, ccls provides some LSP extensions that find base/derived classes/methods, vars of a type, callers of a function. You may call: ```elisp -(lsp-find-custom "$ccls/callers") +;; direct callers +(lsp-find-custom "$ccls/call") +;; callers up to 2 levels +(lsp-find-custom "$ccls/call" '(:levels 2)) +;; direct callees +(lsp-find-custom "$ccls/call" '(:callee t)) + (lsp-find-custom "$ccls/vars") ; Use lsp-goto-implementation or lsp-ui-peek-find-implementation for derived types/functions ;; Alternatively, use lsp-ui-peek interface -(lsp-ui-peek-find-custom 'callers "$ccls/callers") +(lsp-ui-peek-find-custom 'caller "$ccls/call") +(lsp-ui-peek-find-custom 'callee "$ccls/call" '(:callee t)) -(defun ccls/vars (kind) (lsp-ui-peek-find-custom 'vars "$ccls/vars" (plist-put (lsp--text-document-position-params) :kind kind))) +(defun ccls/vars (kind) (lsp-ui-peek-find-custom 'vars "$ccls/vars" `(:kind ,kind))) (ccls/vars 3) ;; field or local variable (ccls/vars 1) ;; field (ccls/vars 4) ;; parameter ``` -There are flattened versions of hierarchies with `:flat t`: +Recommended helpers: ```elisp -(defun ccls/bases () +(defun ccls/callee () (interactive) - (lsp-ui-peek-find-custom 'base "$ccls/inheritanceHierarchy" - (append (lsp--text-document-position-params) '(:flat t :level 3)))) -(defun ccls/derived () + (lsp-ui-peek-find-custom 'callee "$ccls/call" '(:callee t))) +(defun ccls/caller () (interactive) - (lsp-ui-peek-find-custom 'derived "$ccls/inheritanceHierarchy" - (append (lsp--text-document-position-params) '(:flat t :level 3 :derived t)))) + (lsp-ui-peek-find-custom 'caller "$ccls/call")) +(defun ccls/vars (kind) + (lsp-ui-peek-find-custom 'vars "$ccls/vars" `(:kind ,kind))) +(defun ccls/base (level) + (lsp-ui-peek-find-custom 'base "$ccls/inheritance" `(:level ,level))) +(defun ccls/derived (level) + (lsp-ui-peek-find-custom 'derived "$ccls/inheritance" `(:level ,level :derived t))) +(defun ccls/member () + (interactive) + (lsp-ui-peek-find-custom 'member "$ccls/member")) + +;; ccls/vars ccls/base ccls/derived have a parameter while others are interactive. ``` Hierarchies provide a flattened xref interface: -```elisp -(defun ccls/bases () - (interactive) - (lsp-ui-peek-find-custom 'base "$ccls/inheritanceHierarchy" - (append (lsp--text-document-position-params) '(:flat t :level 3)))) -(defun ccls/derived () - (interactive) - (lsp-ui-peek-find-custom 'derived "$ccls/inheritanceHierarchy" - (append (lsp--text-document-position-params) '(:flat t :level 3 :derived t)))) -(defun ccls/members () - (interactive) - (lsp-ui-peek-find-custom 'base "$ccls/memberHierarchy" - (append (lsp--text-document-position-params) '(:flat t)))) -``` - ### Documentation (comments) lsp-ui-doc.el renders comments in a child frame (Emacs >= 26) or inline (< 26). @@ -249,20 +250,20 @@ For the long story, refer to the corresponding [emacs-devel thread](https://list ### Call/member/inheritance Hierarchies `M-x ccls-member-hierarchy` -![$ccls/memberHierarchy](https://ptpb.pw/iOSt.gif) +![$ccls/member hierarchy:true](https://ptpb.pw/iOSt.gif) ```elisp (ccls-call-hierarchy nil) ; caller hierarchy (ccls-call-hierarchy t) ; callee hierarchy ``` -![$ccls/callHierarchy](https://ptpb.pw/Dv8K.gif) +![$ccls/call](https://ptpb.pw/Dv8K.gif) ```elisp (ccls-inheritance-hierarchy nil) ; base hierarchy (ccls-inheritance-hierarchy t) ; derived hierarchy ``` -![$ccls/inheritanceHierarchy](https://ptpb.pw/JkyT.gif) +![$ccls/inheritance hierarchy:true](https://ptpb.pw/JkyT.gif) ### `ccls-navigate` diff --git a/LanguageClient-neovim.md b/LanguageClient-neovim.md index 163c29c..d0fc229 100644 --- a/LanguageClient-neovim.md +++ b/LanguageClient-neovim.md @@ -73,36 +73,44 @@ nn xl :call LanguageClient#findLocations({'method':'$ccls/navigate','di ### Custom cross references ```vim +" bases +nn xb :call LanguageClient#findLocations({'method':'$ccls/inheritance'}) " bases of up to 3 levels -nn xb :call LanguageClient#findLocations({'method':'$ccls/inheritanceHierarchy','flat':v:true,'levels':3,'derived':v:false}) +nn xB :call LanguageClient#findLocations({'method':'$ccls/inheritance','levels':3}) " derived of up to 3 levels -nn xd :call LanguageClient#findLocations({'method':'$ccls/inheritanceHierarchy','flat':v:true,'levels':3,'derived':v:true}) -nn xe :call LanguageClient#findLocations({'method':'$ccls/callers'}) -nn xm :call LanguageClient#findLocations({'method':'$ccls/memberHierarchy','flat':v:true}) -nn xt :call LanguageClient#textDocument_typeDefinition() -nn xv :call LanguageClient#findLocations({'method':'$ccls/vars'}) -nn xV :call LanguageClient#findLocations({'method':'$ccls/vars','kind':1}) +nn xd :call LanguageClient#findLocations({'method':'$ccls/inheritance','derived':v:true}) +" derived of up to 3 levels +nn xD :call LanguageClient#findLocations({'method':'$ccls/inheritance','derived':v:true,'levels':3}) + +" caller +nn xc :call LanguageClient#findLocations({'method':'$ccls/call'}) +" callee +nn xC :call LanguageClient#findLocations({'method':'$ccls/call','callee':v:true}) + +" $ccls/member +nn xm :call LanguageClient#findLocations({'method':'$ccls/member'}) + nn xx x ``` -`$ccls/inheritanceHierarchy flat:t derived:false`: base classes/overridden methods/specialized from +`$ccls/inheritance derived:false`: base classes/overridden methods/specialized from -![$ccls/inheritanceHierarchy flat:t derived:false](https://ptpb.pw/pEDL.jpg) +![$ccls/inheritanceHierarchy derived:false](https://ptpb.pw/pEDL.jpg) -`$ccls/inheritanceHierarchy flat:t derived:true` +`$ccls/inheritance derived:true` -![$ccls/inheritanceHierarchy flat:t derived:true](https://ptpb.pw/QgCd.jpg) +![$ccls/inheritanceHierarchy derived:true](https://ptpb.pw/QgCd.jpg) -`$ccls/callers`: callers of a function +`$ccls/call`: callers/callees of a function ![$ccls/callers](https://ptpb.pw/2RDi.jpg) -The more general `$ccls/callHierarchy` has not been implemented by a Vim plugin. - `$ccls/vars`: instances of a type ![$ccls/vars](https://ptpb.pw/peyX.jpg) -`$ccls/memberHierarchy flat:t`: fields of a struct/class/union/... +`$ccls/member`: fields of a struct/class/union/... -![$ccls/memberHierarchy flat:t](https://ptpb.pw/V8WR.jpg) +![$ccls/member](https://ptpb.pw/V8WR.jpg) + +There are also hierarchical views of `$ccls/call` `$ccls/inheritance` `$ccls/member` (see the Emacs page) but they have not been implemented by a Vim plugin.