chef/vscode-chef

Rubocop highlighting not present if 'cookbooks' is not part of project path

charlesjohnson opened this issue · 4 comments

Summary:

Rubocop syntax checking is not working as expected. While following the example in the gif included in the README documentation, I'm unable to duplicate the results if the word 'cookbooks' is not part of my project path.

Current behavior: Rubocop hints only appear in the editor if 'cookbooks' is part of the project path.
Expected behavior: Regardless of the project path, Rubocop hints will appear in the editor.

Versions:

  • vscode 1.1.0
  • vscode-chef: 0.5.2
  • chefdk: 0.13.21
  • Platform: Mac OSX, 10.11.4
  • vscode plugins / customization: No other plugins installed. Using Light+ (default light) color theme.

Reproduction steps for failure case:

  • Install ChefDK 0.13
  • Ensure there is no knife.rb, config.rb, or solo.rb in ~/.chef, or up the present PWD tree
  • ChefDK 0.13 has a bug in which Rubocop does not get linked into /opt/chefdk/bin/rubocop. Solve for this by running sudo ln -h /opt/chefdk/embedded/bin/rubocop /opt/chefdk/bin/rubocop
  • Install visual studio code 1.1.0
  • Using the command palette, install vscode-chef
  • Restart vscode when prompted
  • Change color theme of vscode to Light+ if not already
  • From a path that does not have the word "cookbooks"Run chef generate cookbook foo
  • Run code foo
  • Open recipes/default.rb in editor
  • Add the following text to the default recipe:
def badNameDefinition  
  puts "hello, VS Code!"  
end
  • Save the default recipe.
  • None of the expected syntax hints will appear.

Reproduction steps for success case:

  • Install ChefDK 0.13
  • Ensure there is no knife.rb, config.rb, or solo.rb in ~/.chef, or up the present PWD tree
  • ChefDK 0.13 has a bug in which Rubocop does not get linked into /opt/chefdk/bin/rubocop. Solve for this by running sudo ln -h /opt/chefdk/embedded/bin/rubocop /opt/chefdk/bin/rubocop
  • Install visual studio code 1.1.0
  • Using the command palette, install vscode-chef
  • Restart vscode when prompted
  • Change color theme of vscode to Light+ if not already
  • Run mkdir -p bar/cookbooks/
  • Run chef generate cookbook bar/cookbooks/foo
  • Run code bar
  • Open cookbooks/recipes/default.rb in editor
  • Add the following text to the default recipe:
def badNameDefinition  
  puts "hello, VS Code!"  
end
  • Save the default recipe.
  • All of the expected syntax hints will appear.

Troubleshooting

Run the plugin in debug mode

Fired up the vscode-chef project in vscode, and used the debug console to start the plugin. Generated this error output by saving a file via the error case:

at Object.exports.wrapFsWithAsar.fs.readdirSync (ELECTRON_ASAR.js:496:28)
at getCookbookPaths (/Users/charlesjohnson/Development/vscode-chef/out/extension.js:161:15)
at recalculateValidCookbookPaths (/Users/charlesjohnson/Development/vscode-chef/out/extension.js:55:25)
at validateWorkspace (/Users/charlesjohnson/Development/vscode-chef/out/extension.js:77:9)
at /Users/charlesjohnson/Development/vscode-chef/out/extension.js:112:9
at e.invoke (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:6:26640)
at e.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:6:28093)
at e._acceptModelSaved (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:15:20361)

The problem appears to be at out/extension.js, line 53-60:

 function recalculateValidCookbookPaths() {
    cookbookPaths = [];
    var cookbookNames = getCookbookPaths(path.join(vscode.workspace.rootPath, "cookbooks"));
    for (var _i = 0, cookbookNames_1 = cookbookNames; _i < cookbookNames_1.length; _i++) {
        var cookbookName = cookbookNames_1[_i];
        cookbookPaths.push("cookbooks" + "/" + cookbookName);
    }
}

Rather than testing to see if this is a cookbook project by looking for cookbooks in the path, perhaps testing on the presence of metadata.rb or could yield a similar result without having a hard path requirement for the project?

Thanks so much for this elaborate report! The cookbook detection should only be for Foodcritic. But I can see if this fails for some reason it prevents rubucop from working as expected. I'll look into it. Will report back soon. Thanks again.

Sure thing, I always try to write the ticket I wish I was reading. Thanks for looking into it!

Hi @charlesjohnson - please try and update your extension to the latest build 0.6.0 - things should work a lot better now. I've also changed the default location of the binstubs to the embedded folder in this build, and made a few other performances fixes. Please check it out and let me know how it looks.

Confirmed, this is working much better.

Thank you very much for the fast turnaround, and for the excellent plugin!