Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debt: Support launch.json creation through extension host code #9061

Closed
weinand opened this issue Jul 11, 2016 · 11 comments
Closed

Debt: Support launch.json creation through extension host code #9061

weinand opened this issue Jul 11, 2016 · 11 comments
Assignees
Labels
debt Code quality issues debug Debug viewlet, configurations, breakpoints, adapter issues feature-request Request for new features or functionality

Comments

@weinand
Copy link
Contributor

weinand commented Jul 11, 2016

Currently an extension can only contribute an initial launch.json statically, so it cannot adapt the launch.json to the contents or structure of an existing project folder.

For node.js we work around this in VS Code by specific code that understands the package.json.
With this feature we could move this code from VS Code into node-debug.

@weinand weinand added the debug Debug viewlet, configurations, breakpoints, adapter issues label Jul 11, 2016
@isidorn isidorn added the feature-request Request for new features or functionality label Jul 19, 2016
@isidorn
Copy link
Contributor

isidorn commented Jul 22, 2016

August to investigate if we can introduce some vscode api such that the adapter extension could write the launch.json

@isidorn isidorn added this to the August 2016 milestone Jul 22, 2016
@egamma egamma changed the title Dept: Support launch.json creation through extension host code Debt: Support launch.json creation through extension host code Jul 28, 2016
@egamma egamma added the debt Code quality issues label Jul 28, 2016
@isidorn
Copy link
Contributor

isidorn commented Aug 26, 2016

For this we are depending on the API for extensions to write to configuration files. Currently in discussion with @bpasero and @jrieken since optimally this would be the same API extensions use to change the user / workspace configuration.
Will probably be pushed out to september.

@weinand
Copy link
Contributor Author

weinand commented Aug 29, 2016

@isidorn this feature request is about the initial configuration and not about modifying the launch.json at any time. I'm not sure that this feature has to go through the extension API for write to configuration files.

@isidorn
Copy link
Contributor

isidorn commented Sep 5, 2016

@weinand somehow github did not notify me about this comment, thus the slow response - sorry.
Yes, but this feature request is a subset of writing to the launch.json at any time - which feels to me like a clean and elegant solution which conforms to our VSCode api.

@DustinCampbell
Copy link
Member

Is there any opportunity for #10861 to be included as part of this work?

@weinand weinand removed their assignment Sep 19, 2016
@isidorn
Copy link
Contributor

isidorn commented Sep 20, 2016

Thanks to @bpasero and @jrieken now it is possible to modify the launch.json through extension host code. More details about this can be found #1396
Here's a small snippet where I am adding a new launch configuration through extension host code

        const launchConfig = vscode.workspace.getConfiguration('launch');
        const configurations = launchConfig['configurations'];
        configurations.push({
            "name": "My New Launch Config",
            "type": "extensionHost",
            "request": "launch",
            "runtimeExecutable": "${execPath}",
            "args": ["/Users/isidor/development/vscode", "--extensionDevelopmentPath=${workspaceRoot}" ],
            "stopOnEntry": false,
            "sourceMaps": true,
            "outDir": "${workspaceRoot}/out/src",
            "preLaunchTask": "npm"
        });
        launchConfig.update('configurations', configurations, false).then(() => 
            vscode.window.showInformationMessage('Added new configuration to launch.json!')
        );

@isidorn
Copy link
Contributor

isidorn commented Sep 20, 2016

Also note if you want to try this out in your extension right now you need the latest vscode.d.ts:

  • open your extensions package.json file
  • change the engine.vscode property to *
  • run npm run postinstall (assuming you have the vscode module as dev-dependency)
  • undo the engine-version change from step 2

@isidorn
Copy link
Contributor

isidorn commented Sep 20, 2016

Here's a snippet where I am creating a full new launch.json:

        const configuration = vscode.workspace.getConfiguration();
        const launchConfig =  {
            "version": "0.1.0",
            "configurations": [
                {
                    "name": "Launch Extension",
                    "type": "extensionHost",
                    "request": "launch",
                    "runtimeExecutable": "${execPath}",
                    "args": ["/Users/isidor/development/vscode", "--extensionDevelopmentPath=${workspaceRoot}" ],
                    "stopOnEntry": false,
                    "sourceMaps": true,
                    "outDir": "${workspaceRoot}/out/src",
                    "preLaunchTask": "npm"
                }
            ]
        };
        configuration.update('launch', launchConfig, false).then(() => 
            vscode.window.showInformationMessage('Created my launch.json!')
        );

@weinand
Copy link
Contributor Author

weinand commented Sep 20, 2016

@isidorn part of this feature request is to eliminate the node-specific code for generating the initial launch configuration from VS Code by moving it to the node-debug extension.
Please try to do this!

@isidorn isidorn reopened this Sep 20, 2016
@bpasero
Copy link
Member

bpasero commented Sep 22, 2016

@isidorn @weinand @jrieken @dbaeumer one thing to keep in mind when using the new configuration write API is that there are a bunch of error cases that can all lead to the configuration not being written to the file. you will get the promise returned in error state so you can handle the error but I wonder if we should just always show a message back to the user in case this happens.

The reason being that some of the errors are actually user errors or specific to the environment the user is in:

  • the settings file is dirty
  • the settings file contains a JSON error (e.g. too much trailing comma)

Instead of asking each and every user of this API to handle the error by showing a message, we could show the message within the configuration editing service and still return the promise in error state so that the extension can also react. I think doing so would allow us to guide the user to do the right thing (e.g. correct a malformed settings file or save the settings file).

The downside of this approach is that it might not be easy for a user to actually repeat the exact same action that was triggering the configuration editing in the first place. Maybe you have suggestions?

@jrieken
Copy link
Member

jrieken commented Sep 22, 2016

we could show the message within the configuration editing service and still return the promise in error state

Not a big fan of that as it won't allow extension authors to implement custom (maybe better suited) error handling

@isidorn isidorn mentioned this issue Sep 22, 2016
1 task
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debt Code quality issues debug Debug viewlet, configurations, breakpoints, adapter issues feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

6 participants