Skip to content

[ExtensionDev] Expose API to get at file system locations #2741

Closed

Description

@SrTobi

Some extension relay on hard coded paths that are not exposed by vscode. See for example code-sittings-sync. Those extension are broken in the insiders version. I see t two possible ways:

  1. Just expose all paths used by vscode to extensions. Otherwise they will hard code them. No more security, just more messy code.
  2. Expose if the extension is used by the insider version. There might be a way, but I have not found it yet. I thought about getting the version and check if it ends with -insiders, but I have not found a way to get this information either.

Activity

  1. added
    feature-request
    on Feb 6, 2016
  2. egamma commented on Feb 6, 2016

    @egamma
    Member

    Interesting... the insider version should be considered as a separate product, with its own user settings and extensions folders. This enables a clean side-by-side install. Therefore, the code-sittings-sync extension is product specific, depending on whether it is installed in the insiders or the stable product it should sync the corresponding product settings.

    An extension gets its path passed in the ExtensionContext of the activate call. From the extension path you can derive in which product the extension is installed.
    /.vscode-insiders/extensions/ or .vscode/extensions/.

    Having said this a workaround, an extension should not have to do this path math and we exposing API to avoid this.

  3. changed the title [-][ExtensionDev] How to find out if in insider mode.[/-] [+][ExtensionDev] Expose API to get at file system locations[/+] on Feb 10, 2016
  4. jrieken commented on May 12, 2016

    @jrieken
    Contributor

    To recap, the paths we should expose

    • extensions home folder, like /Users/jrieken/.vscode-oss-dev/extensions
    • user config folder, like /Users/jrieken/Library/Application Support/code-oss-dev/User

    I am unsure if we should also expose the individual files inside that folder like settings.json, keybindings.json cos that list isn't finite.

  5. jrieken commented on May 12, 2016

    @jrieken
    Contributor

    Alessandro Fragnani (@alefragnani) for the bookmark extension I believe you need the user config folder. is that right? Tobias Kahlert (@SrTobi) I am unsure if you only looking at sync'ing the user-level settings.json or also at others, like our keybindings.json and a potential future bookmarks.json etc

  6. alefragnani commented on May 14, 2016

    @alefragnani

    Johannes Rieken (@jrieken) exactly... thanks 👍

  7. Tyriar commented on May 15, 2016

    @Tyriar
    Contributor

    FYI #5570 is moving the user data directory to be a sibling of the extensions dir.

  8. jrieken commented on May 17, 2016

    @jrieken
    Contributor

    Daniel Imms (@Tyriar) so should we expose the parent folder of those two directories?

  9. Tyriar commented on May 17, 2016

    @Tyriar
    Contributor

    Johannes Rieken (@jrieken) potentially... Post #5570, it might be better to move snippets, settings.json and keybindings.json to the parent directory so it stays away from Chrome's config. Do you know if there's any reason it's in user data as opposed to sitting next to extensions?

  10. jrieken commented on May 17, 2016

    @jrieken
    Contributor
  11. 13 remaining items

  12. golf1052 commented on Aug 5, 2016

    @golf1052
    Member

    Just wanted to check in on this. I assume this is also being pushed out past August like #3884

  13. jrieken commented on Aug 5, 2016

    @jrieken
    Contributor

    yeah - I am handcuffed as long as the underlying api/data isn't ready

  14. Tyriar commented on Aug 5, 2016

    @Tyriar
    Contributor

    Johannes Rieken (@jrieken) it should be fine to expose the User directory now, that will be the root config directory eventually after #3884. settings.json and keybindings.json will still be located there.

  15. davidsk commented on Oct 3, 2016

    @davidsk

    Any movement on this item? I'm after a way to reliably locate the snippets folder.

  16. jrieken commented on Oct 4, 2016

    @jrieken
    Contributor

    Sorry no - there is still no decision on how to re-structure the fs layout (which might then be a breaking change)

  17. shanalikhan commented on Jul 22, 2018

    @shanalikhan

    Johannes Rieken (@jrieken)
    Any update on getting the paths for extensions and all those things for portable mode.

    #49306

  18. cantonios commented on Dec 4, 2018

    @cantonios

    Most links related to obtaining the user-data-dir refer here, but the provided solution of using storagePath is workspace-dependent.

    It seems storagePath is the fs-equivalent of the memento workspaceState.

    Is there a similar option somewhere for the fs-equivalent of the memento globalState?

    I could use the extension folder extensionPath, but this would mean that data will be lost if you ever remove the plugin or update to a new version.

  19. usernamehw commented on Jan 7, 2019

    @usernamehw
    Contributor

    Expose if the extension is used by the insider version. There might be a way, but I have not found it yet. I thought about getting the version and check if it ends with -insiders, but I have not found a way to get this information either.

    const isInsiders = /insiders/i.test(vscode.env.appName);

    Is there anything terribly wrong with this way of getting User dir?

    const UserDirPath = path.join(extensionContext.logPath, '..', '..', '..', '..', 'User');
  20. octref commented on Jul 3, 2019

    @octref
  21. Lakr233 commented on Feb 2, 2020

    @Lakr233

    I have been thinking it would be possible to get it from the shell

    	let ret = execSync("cd ~ && echo $(pwd)");
    	LKutils.shared.setUserHome(ret.toString());
    

    but an API is better for sure.

  22. roblabla commented on Sep 17, 2020

    @roblabla

    I have a bit of an odd need for this:

    I'm using an extension that has an interactive help showing the keybindings that can be used, edamagit. Here's a small example:
    image

    Now the problem is, the user can change the keybindings in their keybindings.json. To make sure the correct keybindings are shown, the extension parses the keybindings.json.

    Now the problem is, when using the extension remotely, there appears to be no way to get to this keybindings.json file. Delving into the vscode source, it appears that the correct URI to access keybindings.json is something like vscode-userdata:c:/Users/roblabla/AppData/Roaming/Code - Insiders/User/setting.json. The problem is, this URI depends on a ton of app and os-specific information that seems to be totally inaccessible from a remote extension.

    The only way I've found to access it is by spawning the settings editor with workbench.action.openGlobalKeybindingsFile:

        await commands.executeCommand('workbench.action.openGlobalKeybindingsFile');
        let keybindingsPath = null;
    
        for (let f of workspace.textDocuments) {
          if (f.uri.path.endsWith('keybindings.json')) {
            KEYBINDINGS_FILE_URI_CACHE = f.uri;
            break;
          }
        }
    
        // Close the keybinding and default keybinding views.
        await commands.executeCommand('workbench.action.closeActiveEditor');
        await commands.executeCommand('workbench.action.closeActiveEditor');

    which is a pretty terrible idea (it temporarily spawns a visible keybinding editor, which makes for a rather jarring experience...).

    Otherwise, the URI is available through the IEnvironmentService::keybindingsResource field, but this seems to be entirely inaccessible from extensions.

  23. added
    *out-of-scope
    on Oct 12, 2021
  24. vscode-triage-bot commented on Oct 12, 2021

    @vscode-triage-bot

    We closed this issue because we don't plan to address it in the foreseeable future. You can find more detailed information about our decision-making process here. If you disagree and feel that this issue is crucial: We are happy to listen and to reconsider.

    If you wonder what we are up to, please see our roadmap and issue reporting guidelines.

    Thanks for your understanding and happy coding!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

*out-of-scopeapifeature-request

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions