Skip to content

Commit 176bfb1

Browse files
jaensDetachHead
authored andcommitted
fix $schema being reported as unrecognized setting in config files
1 parent 206627d commit 176bfb1

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

packages/pyright-internal/src/common/configOptions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,11 +1577,13 @@ export class ConfigOptions {
15771577
this.initializedFromJson = true;
15781578
const console = serviceProvider.tryGet(ServiceKeys.console) ?? new NullConsole();
15791579

1580-
// we initialize it with `extends` because this option gets read before this function gets called
1581-
// 'executionEnvironments' also gets read elsewhere
15821580
const unusedConfigDetector = new UnusedConfigDetector<Record<string, object>>(configObj, [
1581+
// We ignore these because they get read elsewhere:
15831582
'extends',
15841583
'executionEnvironments',
1584+
// VS Code supports setting "$schema" in a JSON file to pick a validation schema.
1585+
// See https://code.visualstudio.com/docs/languages/json#_mapping-in-the-json
1586+
'$schema',
15851587
]);
15861588
configObj = unusedConfigDetector.proxy;
15871589

packages/pyright-internal/src/tests/config.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,26 @@ describe(`config test'}`, () => {
218218
assert.equal(configOptions.executionEnvironments[0].pythonPlatform, 'Linux');
219219
});
220220

221+
test('$schema is recognized', () => {
222+
const cwd = UriEx.file(normalizePath(process.cwd()));
223+
224+
const configOptions = new ConfigOptions(cwd);
225+
226+
const json = {
227+
$schema:
228+
'https://raw.githubusercontent.com/microsoft/pyright/main/packages/vscode-pyright/schemas/pyrightconfig.schema.json',
229+
typeCheckingMode: 'basic',
230+
};
231+
232+
const fs = new TestFileSystem(/* ignoreCase */ false);
233+
const console = new ErrorTrackingNullConsole();
234+
235+
const sp = createServiceProvider(fs, console);
236+
configOptions.initializeFromJson(json, cwd, sp, new NoAccessHost());
237+
238+
assert.deepStrictEqual(console.errors, []);
239+
});
240+
221241
describe('invalid config', () => {
222242
test('unknown top-level option', () => {
223243
const cwd = UriEx.file(normalizePath(process.cwd()));

0 commit comments

Comments
 (0)