How to open a local file from the URL bar in VS Code (#tilPost)

I just discovered the React component click-to-component. The component adds a visual overlay to your React application, allowing you to click on an element and jump right into your code base. Magic!
Obviously, there’s some bundling…


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis

I just discovered the React component click-to-component. The component adds a visual overlay to your React application, allowing you to click on an element and jump right into your code base. Magic!

Obviously, there's some bundling and build magic involved to figure out the component file path, but I wondered how it opens the editor. Is the running server some shell commands?

Nope. All it does is open a URL with the editor's protocol. Here's an example URL that opens a file of my site.

vscode://file/Users/stefanjudis/Projects/github.com/stefanjudis/stefanjudis-website/index.html

Pretty cool! But where's this vscode protocol coming from? On macOS apparently, applications can register URL handlers in the Info.plist file. Here's the responsible part I discovered in my /Applications/Visual Studio Code.app/Contents/Info.plist.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>CFBundleURLTypes</key>
    <array>
      <dict>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>CFBundleURLName</key>
        <string>Visual Studio Code</string>
        <key>CFBundleURLSchemes</key>
        <array>
          <string>vscode</string>
        </array>
      </dict>
    </array>
  </dict>
</plist>

How does it work on Windows? No idea... But if you do, let me know! I'd love to extend this post.


Reply to Stefan


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis


Print Share Comment Cite Upload Translate Updates
APA

Stefan Judis | Sciencx (2024-11-10T23:00:00+00:00) How to open a local file from the URL bar in VS Code (#tilPost). Retrieved from https://www.scien.cx/2024/11/10/how-to-open-a-local-file-from-the-url-bar-in-vs-code-tilpost/

MLA
" » How to open a local file from the URL bar in VS Code (#tilPost)." Stefan Judis | Sciencx - Sunday November 10, 2024, https://www.scien.cx/2024/11/10/how-to-open-a-local-file-from-the-url-bar-in-vs-code-tilpost/
HARVARD
Stefan Judis | Sciencx Sunday November 10, 2024 » How to open a local file from the URL bar in VS Code (#tilPost)., viewed ,<https://www.scien.cx/2024/11/10/how-to-open-a-local-file-from-the-url-bar-in-vs-code-tilpost/>
VANCOUVER
Stefan Judis | Sciencx - » How to open a local file from the URL bar in VS Code (#tilPost). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/11/10/how-to-open-a-local-file-from-the-url-bar-in-vs-code-tilpost/
CHICAGO
" » How to open a local file from the URL bar in VS Code (#tilPost)." Stefan Judis | Sciencx - Accessed . https://www.scien.cx/2024/11/10/how-to-open-a-local-file-from-the-url-bar-in-vs-code-tilpost/
IEEE
" » How to open a local file from the URL bar in VS Code (#tilPost)." Stefan Judis | Sciencx [Online]. Available: https://www.scien.cx/2024/11/10/how-to-open-a-local-file-from-the-url-bar-in-vs-code-tilpost/. [Accessed: ]
rf:citation
» How to open a local file from the URL bar in VS Code (#tilPost) | Stefan Judis | Sciencx | https://www.scien.cx/2024/11/10/how-to-open-a-local-file-from-the-url-bar-in-vs-code-tilpost/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.