-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Allow other extensions to query properties of the current configuration #1524
Comments
VS code allows extensions to export functions that other extensions can call. So we could export some GetCurrentConfiguration method. Another potential option would be to store the current configuration name in a setting, and then the setting could be referenced using ${config.} in launch.json. We currently just save the current configuration as a number/index, which we send to the processes when the number changes. You should be able to implement this yourself with our open source typescript and we could accept a pull request. |
I think exposing the current configuration (as the full JSON) would probably be more beneficial to clients. As far as exposing a function goes, I found a way of executing another extension's commands, is that what you're referring to? If so I think it would be easy to add a new command (that isn't attached to anything in the UI) that returns the current configuration. |
I don't know what you mean by "exposing the current configuration (as the full JSON)". We currently use a c_cpp_properties.json that other extensions can read/write (the same way our extension does using JSON apis), but the currently selected configuration is not available anywhere. We plan to migrate away from that json file and just use the normal settings.json later though, although c_cpp_properties.json might still be supported for backwards compatibility unless do a conversion, in which case the currently selected configuration might just be a setting as well. I don't think we want to add a "command", which are listed in the command palette for users to execute. I'm referring to returning a public API from our activate method: https://code.visualstudio.com/docs/extensionAPI/vscode-api#_extensions: console.log(importedApi.mul(42, 1));` |
What I was hoping to expose was the contents of the configuration in c_cpp_properties.json for the selected configuration. (I.e. if I've selected configuration "A", and I ask vscode-cpptools for the current configuration, I get back the JSON object that contains
That sounds pretty promising, and would be pretty useful. Depending on the timeline, I could live without the feature I'm requesting if the feature you describe was implemented. Any idea on when that change might take place? |
Actually. If we just exposed the current configuration's name through settings.json, it would solve our problems (as far as needing the configuration exposed) and be a stepping stone to having vscode-cpptools exclusively use settings.json. Would you be opposed to that solution? |
Yeah, that sounds good to me. I can't think of any blocking problems that would cause (or a need to modify the language server process). @bobbrow @grdowns @ronglums Do you guys see any issues? If the setting name doesn't match any names in the c_cpp_properties.json it should switch to the default and update the workspace setting to be valid. Did you want to add this yourself? I'm not sure when we'd be able to add it. |
I'd be happy to try 😄 |
Sure, let us know if you have any questions or want help with something. |
I think it would be better to export an API (it's something I eventually want to do for CMake integration anyway) than add a new setting for this. A setting opens up some weird cases since it can be set in any of three scopes (global, workspace, folder) and this really only ever applies to a folder. Another potential option would be to write the active configuration index into the c_cpp_properties.json file (it sounds like you're reading the configs from there already?). I think I considered doing this at one point, but ended up using the persistent storage stuff instead to avoid incrementing the version number of c_cpp_properties.json. We still haven't sat down and thought through the migration of c_cpp_properties.json to settings.json so I have concerns about adding a setting that has the potential to be obsoleted in a month or two. Exporting an API that can provide this information sidesteps any potential issues here and is the safest option, IMO. |
The global/workspace scopes are still valid as defaults if the folder setting isn't set yet. The problem with the export API is that I don't think you can add that to a task/launch.json, which I assumed was a goal -- see #1444 for another recent user request. Way back in December 2016, I was thinking about something like... Whatever the exact setting layout is, I don't think having the configuration name in a setting would become obsolete. Putting the configuration in the c_cpp_properties.json seems more likely to become obsolete. |
Fair point. I forgot about tasks. |
From a client's perspective, |
Either way, there's always something to maintain. 😉 |
Alright, now time for the tough parts. When the index was internal, it wasn't really a possibility that it got out of sync with the config file (if the file changes, we just reset the index). Now that the "index" is a name in the settings file, it makes it getting out of sync a lot easier. What would you guys prefer the extension do in situations where the config file changes (in a way that "invalidates" the current configuration name)? Or if the user adds/changes the current configuration name to one that isn't valid? |
Fair note: Blasting the user's setting is a valid possibility in either scenario 😄 |
What we really want is a read-only setting, but is it possible to write to the environment and have the task work with that (e.g. But stepping back for a second... you're building an extension, right? Do you even need to use tasks/launch.json or can you encapsulate your "tasks" in a command? This is what the CMake extension does. You drive the inputs to your commands via your extension's settings and you don't require your users to meddle with tasks/launch.json. If you expose your tasks as commands, then our extension can supply the necessary information via an exported API and then we don't need to deal with bad user input. |
That's definitely an option for us. But my ideal solution is that my extension generates tasks/launch.json the client. That way they don't have to learn a new workflow. |
I was thinking that that the setting would be read/write but would be updated to match a valid value if invalid input was used and if the current config name changed, it would update the setting. I'm not aware of any technical problem with keeping the 2 settings in-sync, but there could be. Oh, I remember wanting to be able add a setting to our package.json as an extension provided built-in variable, but it looked like VS Code didn't support that. |
What I'm hung up on is that I really want the setting to be read-only. Sorry for being a stickler on this. If our extension exported a read-only API (or if writing to the environment works), your extension could consume that and save the config name to your own setting (e.g. |
Environment variables would get messy, since the user could have several instances of vscode running. For insight, I don't explicitly need a setting. My extension will be generating c_cpp_properties.json, tasks.json and launch.json (and keeping them up to date if the user changes their dependencies, etc...). So all I need is the current configuration when they want to do something (like launch the debugger). |
Another previous request was #742 . |
I can prototype a read-only setting and see how it turns out. Might feel clunky to the user, depending on some of the design decisions. What I'm imagining is that if the user changes it to be invalid, it "snaps" back to the valid value. Similarly if the user re-configures the c_cpp_properties, it "snaps" to a valid value. It's too bad I can't dynamically set enum values. That would be pretty useful 😃 |
What do you mean by "re-configures the c_cpp_properties"? What is being snapped to a valid value? The package.json can be dynamically modified with different enum values, but the problem is that the change won't be picked up until the extension reloads. |
"re-configures the c_cpp_properties" means if the user removes some configurations (maybe the current one?) Although I'll admit, I haven't thought about this in the context of the hierarchy of settings (global, workspace, folder).
I didn't know that was a feature, mind pointing me to the documentation? |
Ah, the "it" you're referring to is the setting snapping to valid value and not the c_cpp_properties.json changing. I don't think I've seen documentation on the package.json re-writing behavior. We do it in main.ts in the rewriteManifest() method and we also potentially do it in processCpptoolsJson() in abTesting.ts, but that code isn't currently hittable. We used to do more package.json re-writing for the debugger, but we got rid of that because users found the extra reload requirement annoying. I think only the workspace setting (or folder setting for multi-root) would need to be snapped to a valid value because it takes precedence over the higher settings, e.g. a user may have an default config set that is only valid for 50% of the folders they open, so we wouldn't want to change the user setting. |
FYI, I've been discussing this with the VSCode team and asking them for a way to do this that doesn't require us to expose a setting or an API. |
I like the sound of that. It definitely allows for more interesting things, while keeping the active config private in the cpptools extension. |
We've added |
I'm writing an extension that plugs in our companies build processes on top of vscode-cpptools. Stuff like generating c_cpp_properties.json, launch.json, etc...
Ideally, the user would have their workspace set up so that they've selected a configuration for intellisense, and when they hit F5, the appropriate launch.json configuration is selected for their selected c_cpp_properties.json configuration.
The easiest way I can think of would be to allow other extensions to query vscode-cpptools for the current configuration, and then clients can use that to get the name or any other property.
I'm still getting my hands dirty with extensions, so let me know if this already exists, or there's a better way to accomplish this.
Thanks!
The text was updated successfully, but these errors were encountered: