Refactor and re-document Bookmark.getNode()

A few minor changes were made to the "Bookmark.getNode()" function for
the purposes of improving readability and documentation clarity.

This process also led me to the conclusion that the "findNode()"
function should be refactored to throw an error if a node cannot be
found. This would lead to greater uniformity in the reporting of
failures to find a node. It is generally better style to have an error
thrown as close to the source as possible. A substantial change like
this should wait for now.
This commit is contained in:
Jason Franklin 2017-06-10 13:29:27 -04:00
parent c0b90811b0
commit a03a639390

View File

@ -157,18 +157,23 @@ function! s:Bookmark.delete()
endfunction endfunction
" FUNCTION: Bookmark.getNode(nerdtree, searchFromAbsoluteRoot) {{{1 " FUNCTION: Bookmark.getNode(nerdtree, searchFromAbsoluteRoot) {{{1
" Gets the treenode for this bookmark " Returns the tree node object associated with this Bookmark.
" Throws "NERDTree.BookmarkedNodeNotFoundError" if the node is not found.
" "
" Args: " Args:
" searchFromAbsoluteRoot: specifies whether we should search from the current " searchFromAbsoluteRoot: boolean flag, search from the highest cached node
" tree root, or the highest cached node " if true and from the current tree root if false
function! s:Bookmark.getNode(nerdtree, searchFromAbsoluteRoot) function! s:Bookmark.getNode(nerdtree, searchFromAbsoluteRoot)
let searchRoot = a:searchFromAbsoluteRoot ? a:nerdtree.root.AbsoluteTreeRoot() : a:nerdtree.root if a:searchFromAbsoluteRoot
let targetNode = searchRoot.findNode(self.path) let l:searchRoot = a:nerdtree.root.AbsoluteTreeRoot()
if empty(targetNode) else
throw "NERDTree.BookmarkedNodeNotFoundError: no node was found for bookmark: " . self.name let l:searchRoot = a:nerdtree.root
endif endif
return targetNode let l:targetNode = l:searchRoot.findNode(self.path)
if empty(l:targetNode)
throw 'NERDTree.BookmarkedNodeNotFoundError: node for bookmark "' . self.name . '" not found'
endif
return l:targetNode
endfunction endfunction
" FUNCTION: Bookmark.GetNodeForName(name, searchFromAbsoluteRoot, nerdtree) {{{1 " FUNCTION: Bookmark.GetNodeForName(name, searchFromAbsoluteRoot, nerdtree) {{{1