Skip to content

feat(configuration): support extends in folder settings files - #299164

Closed
scarf (scarf005) wants to merge 2 commits into
microsoft:mainfrom
scarf005:feat/15909/settings-file-extends
Closed

scarf (scarf005) wants to merge 2 commits into
microsoft:mainfrom
scarf005:feat/15909/settings-file-extends

Conversation

@scarf005

Copy link
Copy Markdown

Summary

  • add support for extends in folder .vscode/settings.json by resolving and merging inherited settings before parsing
  • watch inherited settings files and trigger configuration reload when inherited files change
  • add coverage for override precedence and inherited-file change propagation

Fixes #15909.

Testing

  • npm run compile
  • npm run test-node -- --run "src/vs/workbench/services/configuration/test/common/configurationModels.test.ts" --grep "FolderSettingsModelParser"
  • attempted targeted electron/browser tests for configurationService.test.ts; blocked in this container due missing X server and missing Playwright host libraries

Resolve .vscode/settings.json extends chains before parsing so shared settings files can be inherited and watched for updates. Add coverage for merge precedence and dependency-file change propagation.

Assisted-by: openai/gpt-5.3-codex on opencode
Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 4, 2026 09:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for extends in folder-level workspace settings (.vscode/settings.json) by resolving and merging inherited settings prior to parsing, and wiring file watching so changes in inherited settings trigger a configuration reload. This fits into the workbench configuration pipeline by enhancing how FolderConfiguration (and the underlying file-service based configuration loader) resolves settings content.

Changes:

  • Resolve and merge extends chains for folder settings before parsing into ConfigurationModel.
  • Track/watch resolved inherited settings resources so changes propagate via configuration reload events.
  • Add browser-side configuration service tests covering precedence and change propagation for extended settings.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/vs/workbench/services/configuration/browser/configuration.ts Implements extends resolution/merging for settings content and watches inherited resources to trigger reloads.
src/vs/workbench/services/configuration/test/browser/configurationService.test.ts Adds tests for extended folder settings precedence and reload propagation when an inherited file changes.
Comments suppressed due to low confidence (1)

src/vs/workbench/services/configuration/browser/configuration.ts:429

  • resolveExtendsResource treats any string that parses with a URI scheme as an absolute URI. This breaks common absolute Windows paths like C:\foo\bar.json or c:/foo/bar.json because URI.parse interprets the drive letter as the scheme (c:), causing later readFile calls to fail. Consider detecting Windows drive/UNC paths (and other non-URI absolute paths) and routing them through extUri.resolvePath instead of URI.parse scheme handling.
	private resolveExtendsResource(settingsResource: URI, extendsRef: string): URI | undefined {
		try {
			const parsed = URI.parse(extendsRef);
			if (parsed.scheme) {
				return parsed;
			}

Comment on lines +425 to +437
try {
const parsed = URI.parse(extendsRef);
if (parsed.scheme) {
return parsed;
}
} catch {
}

if (!extendsRef.trim()) {
return undefined;
}

return this.uriIdentityService.extUri.resolvePath(this.uriIdentityService.extUri.dirname(settingsResource), extendsRef);

Copilot AI Mar 4, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extends references are resolved via extUri.resolvePath(dirname(settingsResource), extendsRef), which allows .. segments to escape the .vscode configuration folder (and even the workspace) and then readFile will load that external file. Because workspace settings are repo-controlled, this enables arbitrary file reads outside the workspace and can expose local data via configuration APIs. Please restrict allowed extends targets (e.g., require the resolved resource to be equal-or-child of the configuration folder and to match the base scheme/authority), and ignore/log otherwise.

Suggested change
try {
const parsed = URI.parse(extendsRef);
if (parsed.scheme) {
return parsed;
}
} catch {
}
if (!extendsRef.trim()) {
return undefined;
}
return this.uriIdentityService.extUri.resolvePath(this.uriIdentityService.extUri.dirname(settingsResource), extendsRef);
const trimmedRef = extendsRef.trim();
if (!trimmedRef) {
return undefined;
}
const baseDir = this.uriIdentityService.extUri.dirname(settingsResource);
let candidate: URI | undefined;
try {
const parsed = URI.parse(trimmedRef);
if (parsed.scheme) {
candidate = parsed;
}
} catch {
// Not a URI, treat as relative path below
}
if (!candidate) {
candidate = this.uriIdentityService.extUri.resolvePath(baseDir, trimmedRef);
}
// Enforce same scheme/authority and restrict to configuration directory subtree
if (candidate.scheme !== baseDir.scheme || candidate.authority !== baseDir.authority) {
this.logService.trace(`Ignoring extends reference '${extendsRef}' from '${settingsResource.toString()}' because it has a different scheme or authority.`);
return undefined;
}
if (!this.uriIdentityService.extUri.isEqualOrParent(candidate, baseDir)) {
this.logService.trace(`Ignoring extends reference '${extendsRef}' from '${settingsResource.toString()}' because it resolves outside the configuration folder.`);
return undefined;
}
return candidate;

Copilot uses AI. Check for mistakes.
Ignore extends targets that cross scheme/authority boundaries or resolve outside the settings directory to prevent unsafe file traversal. Add a regression test for escaping the .vscode folder.

Assisted-by: openai/gpt-5.3-codex on opencode
Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
@nanbiz

nanbiz commented May 18, 2026

Copy link
Copy Markdown
if (!this.uriIdentityService.extUri.isEqualOrParent(candidate, baseDir)) {
    this.logService.trace(`Ignoring extends reference '${extendsRef}' from '${settingsResource.toString()}' because it resolves outside the configuration folder.`);
    return undefined;
}

If I understand correctly here, the current approach would not allow what most users including the original issue author in #15909 want.
One example that might be very common are monorepos like this:

<root>/
├── .vscode/
│   └── settings.json         <- parent (would be extended FROM)
└── project_A/
    └── .vscode/
        └── settings.json     <- child, contains "extends": "../../.vscode/settings.json"

And with the current approach that would not work as the root is outside of project_A.
If path traversal is a problem, an alternative might be to
a) allow settings in .vscode folders within parent directories
b) allow files in the current git repository if one is opened

But leaving it like it currently is, I think the feature wouldn't be useful to many users.

@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Jul 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ability to extend from other settings files

4 participants