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.
Question posted in Visual Studio Code
View the official documentation.
View the official documentation.
2
Answers
Just use the
workspace
object’sworkspaceFolders
field and take theuri
field of eachWorkspaceFolder
. You’ll get aUri
object from which you can take thepath
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).For user settings try this:
That last version is if they are using the Insiders Build, which you can check with
For workspace settings ( as @user suggested), this code works:
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