dsawardekar / wordpress.vim

Vim Plugin for WordPress Development
MIT License
166 stars 17 forks source link

Tweak the Plugin & Theme Detection #13

Closed dsawardekar closed 10 years ago

dsawardekar commented 10 years ago

I'm planning to make some changes to WordPress.vim's Plugin and Theme detection code. This is pretty fundamental to the plugin. The actual plugin is only loaded in Vim if the current directory is detected as a WordPress project.

Currently it detects,

(1) foo-plugin/foo-plugin.php

That is, if you are in the foo-plugin directory, if it finds a corresponding foo-plugin.php, it will mark it as a wordpress plugin.

(2) foo-theme/style.css

Same idea, but with foo-theme. For themes the file it looks for is style.css.

(3) wp cli yml.

If it finds any wp-cli.yml or wp-cli.local.yml it's a WP Cli project and hence a WordPress one.

(4) core

Else it looks for core files like wp-load.php.

There are some other checks that look at headers and validity of paths, but these are the main types detected. All of this is done while walking though parent directories. So even if you are inside a sub directory, it will still detect things correctly.

My proposed change is to add a secondary directory between the checks for theme & plugins. The reason for this is that a lot of my work is done on Plugins and Themes outside of a working WordPress directory. I add a wp-cli local config to the plugin/theme and .gitignore it.

My directory structure is,

my-plugin/repo/my-plugin.php

Where, repo is usually a git repository. The my-plugin directory will usually contain other files and assets not to be included in git, like binaries, credentials, etc.

I'm looking for feedback on other directory structure/patterns that could benefit from this. If you have a different directory structure that WordPress.vim is not able to auto-detect, please post the details in this thread.

Thanks.

curtismchale commented 10 years ago

90% of the time I run my WordPress projects from wp-content as the main directory I'm working in. I do this because for a client project I'm usually tweaking the theme, building a few plugins...and I need to be in both spots.

I don't run at the same level as wp-config.php because it simply clutters up stuff like CTRL-P when searching files and I really don't need WP under version control most of the time.

I've actually been wondering if I really had WordPress.vim working but based on the notes above, I bet it's not even loading for me.

dsawardekar commented 10 years ago

@curtismchale If you are inside a WordPress directory, it should already be working. The wp-content directory should work fine, since it walks up the tree. Do you see the WordPress Loading ... message in the status bar?

Also do any of the WordPress.vim features work for you? Eg:- With CTags installed, In any PHP file inside a WordPress project type in,

add_action('template_redirect', 'foo');

Place the cursor on template_redirect and hit Ctrl-]. That should take you to the definition of the Action hook.

Edit: After looking at the linked thread, perhaps you haven't got Ctags installed?

tnorthcutt commented 10 years ago

I don't have much input on this, since I am typically working in a root wp directory or /wp-content, since I'm usually tweaking a theme and building plugins like @curtismchale.

Your question about the WordPress Loading ... message does bring up a question, though: should that text always be visible? I've just assumed that's a bug or problem with my configuration, since it stays visible long after (I assume) everything has been loaded.

dsawardekar commented 10 years ago

@tnorthcutt The message should change to WordPress Loading ... Generating CTags and then to WordPress Loading ... DONE. Can you paste the output of, :messages after you start Vim.

Also do you have Exuberant CTags installed?

tnorthcutt commented 10 years ago

@dsawardekar ahh, thanks, those are the messages I see, and it does change to ...DONE for me. I just find that annoying, I suppose :smile:

I do have Exuberant CTags installed, yes.

dsawardekar commented 10 years ago

@tnorthcutt Yeah, I agree it's annoying. Thanks for bringing that up, I've also been meaning to address it.

I only added it because the Ctags step runs the first time, which takes about 3-4 seconds. I was worried that Vim would seem like hung hence the message.

Let's follow up on this on #14.

dsawardekar commented 10 years ago

I have been using the plugin on a daily basis without issues. But I'm leaving this open, until there is some clarity on whether anyone else has bugs in the existing detection code that are unreported.

Also I have a simpler solution to get what I outlined.

  1. Given the directory structure foo-plugin\repo\foo-plugin.php.
  2. Create a symlink from repo to foo-plugin.
  3. So the psuedo structure is foo-plugin\foo-plugin\foo-plugin.php.
  4. Now if you use the symlinked directory as your working dir, Wordpress.vim detection works.
dsawardekar commented 10 years ago

This is now implemented in 0.2.1. The detection assumes that the in-between directory contains the word repo. So it will detect things like, my-plugin/repo/my-plugin.php, and it's variants like my-plugin/upstream-repo/my-plugin.php and so on.