madebyraygun / craft-component-library

Craft CMS Plugin for Component Library
MIT License
2 stars 0 forks source link

Open component in VSCode from browser #16

Open vanrez-nez opened 2 months ago

vanrez-nez commented 2 months ago

It is possible to open files directly from the browser into VSCode. This could become really handy and save a couple seconds of what I think is a very common task while working with the library.

Basically support opening files from the Browser using VSCode Urls. The challege here is that, when running from a container (like DDEV) the actual path is the one inside the FS of the container and not the one in the user host.

Example:

<a href="vscode://file/Users/user/Documents/web-dev/library-core/craft/library/02-elements/image/image.twig">Edit Component in VSCode</a>
daltonrooney commented 2 months ago

Agreed, this could be very useful!

vanrez-nez commented 1 month ago

Just an udpdate on how this could be done:

Since Docker purpose is to isolate everything from the host machine there is not way I'm aware to retrieve the path for current working files. To solve this we could:

1) Configure manually a path from the plugin config as a string i.e. (/Users/vanrez/Documents/web-dev/library-core) but maybe reading it from an ENV var since this is dependent on each user, so this would become something like:

<?php
use craft\helpers\App;

return [
    'hostPwd' => App::env('CRAFT_HOST_PWD')
];

2) For users in DDEV this could be done by editing the .ddev/config.yaml to include:

web_environment:
  - CRAFT_HOST_PWD=${PWD}

The benefits of doing this with DDEV is that the declaration is not needed in the user's .env file since it's beign taken from PWD var in which the host is running.

Failing to retrieve the ENV var would disable this feature on the library. @daltonrooney do you think this is a good aproach?