Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show all json schemas for yaml file in codelens #424

Merged
merged 6 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 0 additions & 4 deletions src/languageservice/jsonSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,3 @@ export interface JSONSchema {
export interface JSONSchemaMap {
[name: string]: JSONSchemaRef;
}

export function isJSONSchema(schema: JSONSchemaRef): schema is JSONSchema {
return typeof schema !== 'boolean';
}
5 changes: 3 additions & 2 deletions src/languageservice/services/yamlCodeLens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import { yamlDocumentsCache } from '../parser/yaml-documents';
import { YAMLSchemaService } from './yamlSchemaService';
JPinkney marked this conversation as resolved.
Show resolved Hide resolved
import { URI } from 'vscode-uri';
import * as path from 'path';
import { isJSONSchema, JSONSchema, JSONSchemaRef } from '../jsonSchema';
import { JSONSchema, JSONSchemaRef } from '../jsonSchema';
import { CodeLensParams } from 'vscode-languageserver-protocol';
import { isBoolean } from '../utils/objects';

export class YamlCodeLens {
constructor(private schemaService: YAMLSchemaService) {}
Expand Down Expand Up @@ -93,7 +94,7 @@ function addSchemasForOf(schema: JSONSchema, result: Map<string, JSONSchema>): v

function addInnerSchemaUrls(schemas: JSONSchemaRef[], result: Map<string, JSONSchema>): void {
for (const subSchema of schemas) {
if (isJSONSchema(subSchema)) {
if (!isBoolean(subSchema)) {
Copy link
Member

Choose a reason for hiding this comment

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

This still does not confirm that it is a JSONSchema.

"I'm looking for a dog. Is a bird? No, it's not a bird. OK, it's not a bird so it must be a dog" That does not work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We have only two choices, subSchema can be boolean or JSONSchema
It would be enough to check that schema is not boolean, as rest check will do TS compiler.

Copy link
Member

Choose a reason for hiding this comment

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

OK, since you are not using an any I guess that could work.

I was thinking that if you wanted to confirm that matched the interface then test for expected mandatory fields. But I'll leave it up to you.

if (subSchema.url && !result.has(subSchema.url)) {
result.set(subSchema.url, subSchema);
}
Expand Down