chef / vscode-chef

Chef Infra Extension for Visual Studio Code
Apache License 2.0
39 stars 19 forks source link

Depends on deprecated extensions #242

Closed floh96 closed 4 days ago

floh96 commented 11 months ago

Describe the problem

The extension depends on the following deprecated extensions Ruby and VSCode-Ruby https://github.com/rubyide/vscode-ruby. These extensions are deprecated and will not be updated anymore VSCode prompts to uninstall them.

Software Version

Extension Version 2.1.0

Possible Solution

Migrate to https://github.com/Shopify/vscode-ruby-lsp wich is recommended by vscode

floh96 commented 11 months ago

fyi @vkarve-chef @johnmccrae

bkonick commented 7 months ago

Can the release from #245 be made available in VS Code?

donwlewis commented 7 months ago

I would also like to see this made available in VS Code marketplace. Thanks!

jsloan117 commented 7 months ago

me as well, since we've had to uninstall the extension since it no longer works.

SeanSith commented 6 months ago

Sorry to bring you all back into this conversation @vkarve-chef @johnmccrae , but I was hoping to get some eyes on this.

bkonick commented 5 months ago

Can the release from #245 be made available in VS Code?

Still waiting for this. My team would greatly appreciate if releasing it in VS Code can be prioritized.

JHBoricua commented 4 months ago

Can the release from #245 be made available in VS Code?

Still waiting for this. My team would greatly appreciate if releasing it in VS Code can be prioritized.

I know this isn't the answer you're looking for but just clone the repo and build it yourself, then distribute the extension to your team. That's what I ended up doing for my team after getting tired of waiting for a newer version of the plugin to be published in the vscode marketplace.

It's not that difficult. It actually took longer to download/install some of the required tools than to actually build the extension.

bkonick commented 3 months ago

Can the release from #245 be made available in VS Code?

Still waiting for this. My team would greatly appreciate if releasing it in VS Code can be prioritized.

I know this isn't the answer you're looking for but just clone the repo and build it yourself, then distribute the extension to your team. That's what I ended up doing for my team after getting tired of waiting for a newer version of the plugin to be published in the vscode marketplace.

It's not that difficult. It actually took longer to download/install some of the required tools than to actually build the extension.

I ended up doing the same a while ago. Annoying, but yes it works and was fairly simple.

HP41 commented 3 weeks ago

Any update on publishing the latest version to VSCode Extension repository?

Is there an account/token issue perhaps?

SeanSith commented 1 week ago

Seems that 2.2.12 was released this morning. Thanks to whomever made the release!!! ❤️

HP41 commented 1 week ago

Thank you!

Unsure if this should be a separate issue or more of a discussion.

With the deprecated Ruby extensions, linting, syntax highlighint, formatting, autocomplete were pretty automatic (albeit not complete or a bit odd as it was not a full blown LSP)

With ruby-lsp while being a full blown LSP with a good featureset, it is more suited for Ruby/Rails dev.

To get a more integrated dev environment for Chef cookbooks similar to the dperecated extensions and even more I've found some ways to hack around it to work with chef-workstation by:

<project_dir>/.vscode/settings.json

"rubyLsp.rubyVersionManager": {
  "identifier": "custom"
},

// Ensures it uses chef ruby env/workstation.
"rubyLsp.customRubyCommand": "eval \"$(/usr/bin/chef shell-init sh)\"",
// The gems must still be specified explicitly for ruby-lsp to parse the code for intellisense(ish), class/fn documentation, cookstyle requires, etc
// NOTE: The above does not include any chef dsl code. Just for pure ruby code/gems/modules.
"rubyLsp.bundleGemfile": ".vscode/Gemfile",
"rubyLsp.erbSupport": true, // default

// cookstyle does not seem to work here regardless if cookstyle is specified in your Gemfile.
// Therefore it must be rubocop with cookstyle
"rubyLsp.linters": ["rubocop"], // Should auto detect anyways

<project_dir>/.vscode/Gemfile

# Including all gems installed by chef-workstation slows down Ruby LSP\
# Ruby LSP indexing time also increases a lot when all are included
# Therefore only requiring gems that we care about.

# gem 'json', require: false
# require 'json'

# JSON.load_file('/opt/chef-workstation/gem-version-manifest.json').keys.each do |gm|
#   gem gm
# end

gem 'chef', require: false
gem 'chef-vault', require: false
gem 'chefspec', require: false

# cookstyle must be specified here else ruby-lsp rubocop will not run with cookstyle (as you type)
gem 'cookstyle', require: false
gem 'erb', require: false
gem 'erubi', require: false
gem 'erubis', require: false
gem 'fileutils', require: false
gem 'inifile', require: false
gem 'iniparse', require: false
gem 'ipaddr', require: false
gem 'ipaddress', require: false
gem 'json', require: false
gem 'os', require: false
gem 'resolv', require: false
gem 'yaml', require: false

# ruby-lsp must be specified in gemfile if a custom gemfile (this) is specified.
gem 'ruby-lsp', require: false

require 'chef'

# For any gems specified in cookbook metadata
m = Chef::Cookbook::Metadata.new
m.from_file File.join(File.expand_path('..', __dir__), 'metadata.rb')
m.gems.each do |name, version|
  puts name
  gem name, version, require: false
end

<project_dir>/.vscode/tasks.json

// When custom Gemfile is present, ruby-lsp will not manage installation or update of gem. 
// In this case it only installs ruby-lsp on project first open (when it needs to create a Gemfile.lock)
// Thereafter it does not update it.
// It takes a long time to run update the gem for us on every project open hence only running once.
// Gemfile.lock is updated every run (and runs fast as it references locally installed gems only) in case chef-workstation has been updated since last project open
// Gemfile.lock is also needed for ruby-lsp to work
// 
{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Update Gemfile with chef-workstation gemfiles",
      "type": "shell",
      "command": "cd .vscode; [ ! -f Gemfile.lock ] && /usr/bin/chef gem install ruby-lsp; /usr/bin/chef exec bundle lock --local",
      "group": "none",
      "presentation": {
        "reveal": "always",
        "panel": "new"
      },
      "runOptions": {
        "runOn": "folderOpen"
      }
    }
  ]
}

<project_dir>/.rubocop.yml

# needed for pure rubocop runs to work with cookstyle
require:
  - cookstyle

# ... rest of the config

These all seem quite hacky and a workaround for a extension that is targeted towards classical ruby dev.

Another issue faced, which might be a ruby-lsp issue is that it does not have a good handle on its own ruby-lsp processes and sometimes spawns multiple and leaves them running.

There seems to be no way to run a static ruby-lsp server on a port or socket that any chef project can plug into. As all chef cookbooks one works on uses the same environment, i.e one's own chef-workstation.

There might be ways to do some hack around with multi-root workspaces: https://github.com/Shopify/ruby-lsp/blob/main/vscode/README.md#multi-root-workspaces

One clean way to do this (if it is even possible) is to write a custom ruby-lsp plugin that works with chef dsl and knows to work with the chef-workstation embedded ruby environment and not in a classical ruby dev env.