-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load schema content contributed by other extensions (#451)
* Load schema content contributed by other extensions Signed-off-by: Yevhen Vydolob <[email protected]> * Fix review comments Signed-off-by: Yevhen Vydolob <[email protected]> * update readme with way to disable code lens Signed-off-by: Yevhen Vydolob <[email protected]>
- Loading branch information
Showing
5 changed files
with
84 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Red Hat, Inc. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import * as vscode from 'vscode'; | ||
import { getDocUri, activate } from './helper'; | ||
import * as assert from 'assert'; | ||
|
||
describe('Tests for JSON Schema content provider', () => { | ||
const SCHEMA = 'myschema'; | ||
const schemaJSON = JSON.stringify({ | ||
type: 'object', | ||
properties: { | ||
version: { | ||
type: 'string', | ||
description: 'A stringy string string', | ||
enum: ['test'], | ||
}, | ||
}, | ||
}); | ||
|
||
function onRequestSchema1URI(resource: string): string | undefined { | ||
if (resource.endsWith('completion.yaml') || resource.endsWith('basic.yaml')) { | ||
return `${SCHEMA}://schema/porter`; | ||
} | ||
return undefined; | ||
} | ||
|
||
function onRequestSchema1Content(): string | undefined { | ||
return schemaJSON; | ||
} | ||
|
||
it('should handle "json-schema" url', async () => { | ||
const docUri = getDocUri('completion/completion.yaml'); | ||
const client = await activate(docUri); | ||
client._customSchemaContributors = {}; | ||
client.registerContributor(SCHEMA, onRequestSchema1URI, onRequestSchema1Content); | ||
const customUri = vscode.Uri.parse(`json-schema://some/url/schema.json#${SCHEMA}://some/path/schema.json`); | ||
const doc = await vscode.workspace.openTextDocument(customUri); | ||
const editor = await vscode.window.showTextDocument(doc); | ||
assert.strictEqual(editor.document.getText(), JSON.stringify(JSON.parse(schemaJSON), null, 2)); | ||
client._customSchemaContributors = {}; | ||
}); | ||
}); |