rokucommunity / vscode-brightscript-language

A Visual Studio Code extension for Roku's BrightScript language
MIT License
110 stars 40 forks source link

Read environment variables from external file for debuggin #78

Closed bvisin closed 5 years ago

bvisin commented 5 years ago

I would like to have a launch config file like:

{
    "version": "0.2.0",
    "configurations": [

        {
            "type": "brightscript",
            "request": "launch",
            "name": "Roku Launch",
            "envFile": "${workspaceFolder}/.env",
            "stopOnEntry": false,
            "host": "${env:ROKU_DEV_TARGET}",
            "password": "${env:ROKU_DEVPASSWORD}",
            "rootDir": "${workspaceFolder}/src",
            "consoleOutput": "normal",
            "outDir": "${workspaceFolder}/out",
            "files":[
                "manifest",
                "source/**/*.*",
                "components/**/*.*",
                "images/**/*.*",
                "fonts/**/*.*",
                "csfake/**/*.*"
            ],

        }
    ]
}
"envFile": "${workspaceFolder}/.env",

I think VS Code does this for node debugging: https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_load-environment-variables-from-external-file-node

https://github.com/Microsoft/vscode/issues/15964

https://github.com/Microsoft/vscode/issues/14523

But I would like to add this functionality to the BS debugger as well.

TwitchBronBron commented 5 years ago

I'm cool with this. I'll start working on it now, shouldn't be too difficult to implement; we can leverage something like this dotenv npm package for the .env parsing (4,410,783 weekly downloads...it's probably stable enough lol)

TwitchBronBron commented 5 years ago

I have a working version of this feature in this branch: https://github.com/TwitchBronBron/vscode-brightscript-language/tree/feature/dotenv-support-in-launch

Can you pull it down and try it out? Let me know if that solves your needs.

bvisin commented 5 years ago

@TwitchBronBron Pulled down the branch and works perfect! Thanks for jumping on this so quickly! Really appreciate the addition. I'll continue to use the branch for a while to see if I notice any abnormalities, but I would say this is a great feature that should be included in the next release.

bvisin commented 5 years ago

@TwitchBronBron I am seeing an issue with the remote not working as the remote pulls the IP from the launch file...

BrightScriptCommands.ts:109
rejected promise not handled within 1 second
extensionHostProcess.js:768

So I think we can easily detect ${env:VAR} and replace that with the env variable...not sure how that all works with different processes as I would like to be loading that in from the .env file but I will try and look into it when I get some time.

TwitchBronBron commented 5 years ago

@bvisin thanks for fixing that issue. This feature is included in release 1.8.0. If you find any more issues with this implementation, please open a new ticket.

bvisin commented 5 years ago

Awesome @TwitchBronBron Thank you!