BetterErrors / better_errors

Better error page for Rack apps
MIT License
6.88k stars 435 forks source link

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

Open coezbek opened 2 years ago

coezbek commented 2 years ago

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

RobinDaugherty commented 2 years ago

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
coezbek commented 2 years ago

One downside of this solution is that is isn't compatible with multiple users using different editors on the same codebase. That's why I asked..

(I updated the wiki with the improved snippet. Thank you!)