skip to Main Content

Is there a way to find location of settings file for User/Workspace/Folder scopes from an extension?
This is not to update the settings, but the extension I am working on just needs location of these files to show to user.

2

Answers


  1. Just use the workspace object’s workspaceFolders field and take the uri field of each WorkspaceFolder. You’ll get a Uri object from which you can take the path field and then just resolve the relative path .vscode/settings.json with respect to the workspace folder path. If needed, make sure to check that a file exists at that path (one might not if the user didn’t create one).

    Login or Signup to reply.
  2. For user settings try this:

    const path = require('path');
    
    const userSettingsPath = path.join(process.env.APPDATA, "Code/User/settings.json");
    
    // const userSettingsPath = path.join(process.env.APPDATA, "Code - Insiders/User/settings.json");
    

    That last version is if they are using the Insiders Build, which you can check with

    vscode.env.appName  // Visual Studio Code or Visual Studio Code - Insiders
    

    For workspace settings ( as @user suggested), this code works:

      const ws = vscode.workspace.asRelativePath(context.extensionUri);
      const workspaceSettings = path.join(ws, ".vscode/settings.json");
    

    BUT, the user might have a multiroot workspace open and so you would have to look at vscode.workspace.workspaceFolders for all workspaceFolders and if there is a .vscode/settings.json in any of them.


    And there might be issues if they are connected to remotely or to the web. Here are a couple of links about the settings locations: Setting file locations and remote extensions

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search