Skip to content

Commit 977c191

Browse files
committed
Merges branch 'release/0.2.1'
2 parents 5f99a86 + 796c55a commit 977c191

File tree

11 files changed

+74
-14
lines changed

11 files changed

+74
-14
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
### 0.2.1
4+
5+
* Adds support for nested plugin directories like,
6+
`foo-plugin/repo/foo-plugin.`. This detection assumes that the
7+
in-between directory contains the keyword `repo`.
8+
* Improves error messaging if WordPress path is not detected.
9+
* Improves excludes list passed to `ctags`, better fix for #16.
10+
311
### 0.2.0
412

513
* Built using @tek's Riml fork.

autoload/wordpress.vim

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,11 @@ function! s:PluginDetector_is_plugin(path) dict
752752
let dirname = fnamemodify(a:path, ':t')
753753
if dirname ==# 'plugins' || dirname ==# 'mu-plugins'
754754
return 1
755+
elseif dirname =~# 'repo'
756+
let parent_dir = fnamemodify(a:path, ':h')
757+
let parent_dirname = fnamemodify(parent_dir, ':t')
758+
let plugin_file = parent_dir . "/" . dirname . "/" . parent_dirname . ".php"
759+
return self.has_plugin_file(plugin_file) && self.has_plugin_header(plugin_file)
755760
else
756761
let plugin_file = a:path . "/" . dirname . ".php"
757762
return self.has_plugin_file(plugin_file) && self.has_plugin_header(plugin_file)
@@ -1552,7 +1557,7 @@ function! s:CTagsCommandBuilder_build() dict
15521557
let cmd .= " --regex-PHP=" . shellescape(re)
15531558
let dirs = self.get_exclude_dirs()
15541559
for dir in dirs
1555-
let cmd .= " --exclude " . dir
1560+
let cmd .= " --exclude=" . dir
15561561
endfor
15571562
let cmd .= " ."
15581563
return cmd
@@ -2544,8 +2549,12 @@ function! s:WordPressPath_get_path(root) dict
25442549
endif
25452550
endfor
25462551
let path = self.find_wp_cli_project_path(a:root)
2547-
if path ==# '' && exists('g:wordpress_vim_wordpress_path')
2548-
let path = g:wordpress_vim_wordpress_path
2552+
if path ==# ''
2553+
if exists('g:wordpress_vim_wordpress_path')
2554+
let path = g:wordpress_vim_wordpress_path
2555+
else
2556+
call s:echo_error('WordPress not detected, Please set g:wordpress_vim_wordpress_path in your vimrc')
2557+
endif
25492558
endif
25502559
return path
25512560
endfunction
@@ -3910,6 +3919,10 @@ function! s:ConfigureTagsCommand_generate_ctags(...) dict
39103919
let msg = 'Generating'
39113920
endif
39123921
let ctags_builder = self.lookup('ctags_builder')
3922+
if ctags_builder.get_project_path() ==# ''
3923+
call s:echo_error('Could not generate tags, WordPress not detected, Please set g:wordpress_vim_wordpress_path in your vimrc')
3924+
return 0
3925+
endif
39133926
if self.needs_tags_generation()
39143927
call s:echo_msg("WordPress: " . msg . " ctags ...")
39153928
call ctags_builder.generate()
@@ -3928,8 +3941,10 @@ function! s:ConfigureTagsCommand_regenerate_ctags() dict
39283941
if filereadable(tags_path)
39293942
call delete(tags_path)
39303943
endif
3931-
call self.generate_ctags('Regenerating')
3932-
call s:echo_msg('WordPress: Regenerating ctags DONE')
3944+
let didGenerate = self.generate_ctags('Regenerating')
3945+
if didGenerate
3946+
call s:echo_msg('WordPress: Regenerating ctags DONE')
3947+
endif
39333948
endfunction
39343949

39353950
function! s:ConfigureTagsCommand_needs_tags_generation() dict

lib/wordpress/controllers/commands/configure_tags_command.riml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class ConfigureTagsCommand < WordPressProjectCommand
3434

3535
defm generate_ctags(msg = 'Generating')
3636
ctags_builder = self.lookup('ctags_builder')
37+
if ctags_builder.get_project_path() == ''
38+
echo_error('Could not generate tags, WordPress not detected, Please set g:wordpress_vim_wordpress_path in your vimrc')
39+
return false
40+
end
3741

3842
if self.needs_tags_generation()
3943
echo_msg("WordPress: #{msg} ctags ...")
@@ -57,8 +61,10 @@ class ConfigureTagsCommand < WordPressProjectCommand
5761
delete(tags_path)
5862
end
5963

60-
self.generate_ctags('Regenerating')
61-
echo_msg('WordPress: Regenerating ctags DONE')
64+
didGenerate = self.generate_ctags('Regenerating')
65+
if didGenerate
66+
echo_msg('WordPress: Regenerating ctags DONE')
67+
end
6268
end
6369

6470
defm needs_tags_generation

lib/wordpress/ctags/ctags_command_builder.riml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class CTagsCommandBuilder
2727
" exclude files to fix #16
2828
dirs = self.get_exclude_dirs();
2929
for dir in dirs
30-
cmd .= " --exclude #{dir}"
30+
cmd .= " --exclude=#{dir}"
3131
end
3232

3333
cmd .= " ."

lib/wordpress/models/detectors/plugin_detector.riml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ class PluginDetector < BufferTypeDetector
2626

2727
if dirname == 'plugins' || dirname == 'mu-plugins'
2828
return true
29+
elseif dirname =~ 'repo'
30+
parent_dir = fnamemodify(path, ':h')
31+
parent_dirname = fnamemodify(parent_dir, ':t')
32+
plugin_file = "#{parent_dir}/#{dirname}/#{parent_dirname}.php"
33+
return self.has_plugin_file(plugin_file) && self.has_plugin_header(plugin_file)
2934
else
3035
plugin_file = "#{path}/#{dirname}.php"
3136
return self.has_plugin_file(plugin_file) && self.has_plugin_header(plugin_file)

lib/wordpress/models/wordpress_path.riml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ class WordPressPath
2626
" path comes from ~/.wp-cli/config.yml
2727
path = self.find_wp_cli_project_path(root)
2828

29-
if path == '' && exists('g:wordpress_vim_wordpress_path')
30-
" wp cli missing but has global wordpress vim config
31-
path = g:wordpress_vim_wordpress_path
29+
if path == ''
30+
if exists('g:wordpress_vim_wordpress_path')
31+
" wp cli missing but has global wordpress vim config
32+
path = g:wordpress_vim_wordpress_path
33+
else
34+
echo_error('WordPress not detected, Please set g:wordpress_vim_wordpress_path in your vimrc')
35+
end
3236
end
3337

3438
return path

lib/wordpress/version.riml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
g:wordpress_vim_version = '0.2.0'
1+
g:wordpress_vim_version = '0.2.1'

plugin/wordpress.vim

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ function! s:PluginDetector_is_plugin(path) dict
196196
let dirname = fnamemodify(a:path, ':t')
197197
if dirname ==# 'plugins' || dirname ==# 'mu-plugins'
198198
return 1
199+
elseif dirname =~# 'repo'
200+
let parent_dir = fnamemodify(a:path, ':h')
201+
let parent_dirname = fnamemodify(parent_dir, ':t')
202+
let plugin_file = parent_dir . "/" . dirname . "/" . parent_dirname . ".php"
203+
return self.has_plugin_file(plugin_file) && self.has_plugin_header(plugin_file)
199204
else
200205
let plugin_file = a:path . "/" . dirname . ".php"
201206
return self.has_plugin_file(plugin_file) && self.has_plugin_header(plugin_file)
@@ -382,7 +387,7 @@ function! s:echo_with(args, style)
382387
endfunction
383388

384389
" included: 'version.riml'
385-
let g:wordpress_vim_version = '0.2.0'
390+
let g:wordpress_vim_version = '0.2.1'
386391
function! s:WordPressPluginConstructor()
387392
let wordPressPluginObj = {}
388393
let wordPressPluginObj.start = function('<SNR>' . s:SID() . '_WordPressPlugin_start')

spec/wordpress/ctags/ctags_command_builder_spec.riml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class CTagsCommandBuilderSpec
128128
dirs = self.builder.get_exclude_dirs()
129129

130130
for dir in dirs
131-
expect(cmd).to_match("--exclude #{dir}")
131+
expect(cmd).to_match("--exclude=#{dir}")
132132
end
133133
end
134134
end

spec/wordpress/models/detectors/plugin_detector_spec.riml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ class PluginDetectorSpec
4242
expect(result).to_be_false()
4343
end
4444

45+
defm it_knows_plugin_inside_repo_is_a_wordpress_plugin
46+
repo_plugin = "spec/wordpress/projects/plugin-inside-repo/repo"
47+
result = self.detector.is_plugin(repo_plugin)
48+
expect(result).to_be_true()
49+
end
50+
4551
defm it_can_detect_if_path_is_inside_plugin
4652
result = self.detector.detect('spec/wordpress/projects/sample-wordpress-plugin')
4753
expect(result.status).to_be_true()
@@ -77,4 +83,10 @@ class PluginDetectorSpec
7783
expect(result.status).to_be_true()
7884
expect(result.path).to_match('spec/wordpress/projects/sample-wordpress-plugin$')
7985
end
86+
87+
defm it_can_detect_correct_path_for_plugin_inside_repo
88+
result = self.detector.detect('spec/wordpress/projects/plugin-inside-repo/repo')
89+
expect(result.status).to_be_true()
90+
expect(result.path).to_match('spec/wordpress/projects/plugin-inside-repo/repo$')
91+
end
8092
end

0 commit comments

Comments
 (0)