BetterErrors / better_errors

Better error page for Rack apps

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

vscode remote: Interpolate environment variable to build editor link scheme?

coezbek opened this issue · comments

I am using Visual Studio Code under WSL remote. To build the URL for the editor link scheme I need to access an environment variable for the current distro being used. This works as an initializer, but I was hoping to contribute a patch to the KNOWN_EDITORS.

if defined?(BetterErrors)
  BetterErrors.editor = "vscode://vscode-remote/wsl+#{ENV['WSL_DISTRO_NAME']}%{file_unencoded}:%{line}"
end

Discussion on SO for building the URL path for VS code remote: https://stackoverflow.com/questions/66582696/url-for-opening-vscode-in-file-in-wsl-workspace?noredirect=1#comment124115062_66582696

Thanks for this @coezbek! I see that you added it to the wiki page already, which is what I would have recommended rather than adding to KNOWN_EDITORS, especially since your case uses an environment variable to assemble the URL. However, I would also recommend that you change your snippet to only be executed when that environment variable is set. i.e.

if defined?(BetterErrors) && (distro_name = ENV['WSL_DISTRO_NAME'])
  BetterErrors.editor = "vscode://vscode-remote/wsl+#{distro_name}%{file_unencoded}:%{line}"
end