Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/languageservice/services/yamlSchemaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1483,12 +1483,13 @@ export class YAMLSchemaService implements IJSONSchemaService {

// Set the priority of a schema in the schema service
public addSchemaPriority(uri: string, priority: number): void {
let currSchemaArray = this.schemaPriorityMapping.get(uri);
const id = normalizeId(uri);
const currSchemaArray = this.schemaPriorityMapping.get(id);
if (currSchemaArray) {
currSchemaArray = currSchemaArray.add(priority);
this.schemaPriorityMapping.set(uri, currSchemaArray);
currSchemaArray.add(priority);
this.schemaPriorityMapping.set(id, currSchemaArray);
} else {
this.schemaPriorityMapping.set(uri, new Set<SchemaPriority>().add(priority));
this.schemaPriorityMapping.set(id, new Set<SchemaPriority>().add(priority));
}
}

Expand Down
26 changes: 26 additions & 0 deletions test/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,32 @@ address:
languageSettingsSetup = new ServiceSetup().withCompletion();
});

for (const { description, uri } of [
{ description: 'encoded Windows drive colon', uri: 'file:///c%3A/Users/user1/schema.json' },
{ description: 'unencoded Windows drive colon', uri: 'file:///c:/Users/user1/schema.json' },
]) {
it(`Preserves settings priority for ${description}`, async () => {
languageSettingsSetup
.withSchemaFileMatch({
fileMatch: ['test.yaml'],
uri: 'https://example.test/schema-store.json',
priority: SchemaPriority.SchemaStore,
schema: schemaStoreSample,
})
.withSchemaFileMatch({
fileMatch: ['test.yaml'],
uri,
priority: SchemaPriority.Settings,
schema: schemaSettingsSample,
});
languageService.configure(languageSettingsSetup.languageSettings);
const document = setupTextDocument('');
const result = await languageService.doComplete(document, Position.create(0, 0), false);
assert.strictEqual(result.items.length, 1);
assert.strictEqual(result.items[0].label, 'settings');
});
}

it('Modeline Schema takes precendence over all other schema APIs', async () => {
languageSettingsSetup
.withSchemaFileMatch({
Expand Down
25 changes: 25 additions & 0 deletions test/yamlSchemaService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,31 @@ describe('YAML Schema Service', () => {
expect(schema.schema.type).eqls('array');
});

for (const { description, uri } of [
{ description: 'encoded Windows drive colon', uri: 'file:///c%3A/Users/user1/schema.json' },
{ description: 'unencoded Windows drive colon', uri: 'file:///c:/Users/user1/schema.json' },
]) {
it(`should resolve a schema URI with an ${description}`, async () => {
const yamlDock = parse('foo: bar');
const normalizedUri = 'file:///c:/Users/user1/schema.json';
requestServiceMock = sandbox.fake.resolves(
JSON.stringify({
type: 'object',
properties: {
foo: { type: 'string' },
},
})
);

const service = new SchemaService.YAMLSchemaService(requestServiceMock);
service.registerExternalSchema(uri, ['test.yaml']);
const schema = await service.getSchemaForResource('test.yaml', yamlDock.documents[0]);

expect(requestServiceMock).calledOnceWithExactly(normalizedUri);
expect(schema.schema.properties.foo).to.include({ type: 'string' });
});
}

it('should use local sibling schema path before remote $id ref', async () => {
const content = `# yaml-language-server: $schema=file:///schemas/primary.json\nmode: stage`;
const yamlDock = parse(content);
Expand Down
Loading