diff --git a/autoload/puppet/include.vim b/autoload/puppet/include.vim new file mode 100644 index 0000000..1bf0672 --- /dev/null +++ b/autoload/puppet/include.vim @@ -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 diff --git a/ftplugin/puppet.vim b/ftplugin/puppet.vim index 6fc8967..8ff5085 100644 --- a/ftplugin/puppet.vim +++ b/ftplugin/puppet.vim @@ -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< \' diff --git a/test/include/include.vader b/test/include/include.vader new file mode 100644 index 0000000..66b46c3 --- /dev/null +++ b/test/include/include.vader @@ -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