Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions autoload/puppet/include.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function! puppet#include#IncludeExpr(fname) abort
" Remove puppet 3.x style leading :: since they mean nothing for the path
let l:fname = substitute(a:fname, '^::', '', '')

" If we can't find a second element, then we're referring to the init.pp
" file
if match(l:fname, '::') < 0
return 'init'
endif

" Remove first element. It'll make finding files easier since the module
" name might not be in the find path.
let l:fname = substitute(l:fname,'^[^:]\+::','','')

" Replace all subsequent :: in order to get a real file path
let l:fname = substitute(l:fname,'::','/','g')

return l:fname
endfunction
5 changes: 5 additions & 0 deletions ftplugin/puppet.vim
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ setlocal commentstring=#\ %s

setlocal formatexpr=puppet#format#Format()

setlocal suffixesadd=.pp
setlocal include=\\v^\\s*(include\|contain\|require\|class\\s*\\\{\|Class\\s*\\\[)\\s*[\"\']?\\zs(\\w+\|::)+
setlocal includeexpr=puppet#include#IncludeExpr(v:fname)

let b:undo_ftplugin = '
\ setlocal tabstop< tabstop< softtabstop< shiftwidth< expandtab<
\| setlocal keywordprg< iskeyword< comments< commentstring<
\| setlocal formatexpr<
\| setlocal suffixesadd< include< includeexpr<
\'
23 changes: 23 additions & 0 deletions test/include/include.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Given puppet (All possible includes in manifest):
include apache::config
include('apache::package')
include(
'apache::settings',
'apache::service'
)
contain apache::box::inside
contain('apache::bag::of::things')
contain(
'apache::field',
'apache::whole_world'
)
require apache::important
require('apache::important::too')
require(
'apache::important::three',
'apache::important::nan'
)

Execute (list all discovered include files):
let file_list = execute(':checkpath!')
AssertEqual "--- Included files in path ---\nmanifests/config.pp\nmanifests/package.pp\nmanifests/settings.pp\nmanifests/service.pp\nmanifests/box/inside.pp\nmanifests/bag/of/things.pp\nmanifests/field.pp\nmanifests/whole_world.pp\nmanifests/important.pp\nmanifests/important/too.pp\nmanifests/important/three.pp\nmanifests/important/nan.pp", file_list
Loading