-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support schema associations in yaml files #204
- association done using modeline "# yaml-language-server: $schema=<mySchemaURL"> Signed-off-by: Aurélien Pupier <[email protected]>
- Loading branch information
Showing
4 changed files
with
191 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Red Hat. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import { TextDocument } from 'vscode-languageserver'; | ||
import { getLanguageService } from '../src/languageservice/yamlLanguageService'; | ||
import { toFsPath, schemaRequestService, workspaceContext } from './utils/testHelper'; | ||
import assert = require('assert'); | ||
import path = require('path'); | ||
|
||
const languageService = getLanguageService(schemaRequestService, workspaceContext, [], null); | ||
|
||
const languageSettings = { | ||
schemas: [], | ||
completion: true | ||
}; | ||
|
||
const uri = toFsPath(path.join(__dirname, './fixtures/testArrayMaxProperties.json')); | ||
languageService.configure(languageSettings); | ||
|
||
suite('Auto Completion Tests with schema defined in file', () => { | ||
|
||
describe('yamlCompletion with schema defined in file', function () { | ||
|
||
function setup(content: string) { | ||
return TextDocument.create('file://~/Desktop/vscode-k8s/test-schemainfile.yaml', 'yaml', 0, content); | ||
} | ||
|
||
function parseSetup(content: string, position) { | ||
const testTextDocument = setup(content); | ||
return languageService.doComplete(testTextDocument, testTextDocument.positionAt(position), false); | ||
} | ||
|
||
it('Provide completion from schema declared in file', done => { | ||
const content = `# yaml-language-server: $schema=${uri}\n- `; | ||
const completion = parseSetup(content, content.length); | ||
completion.then(function (result) { | ||
assert.equal(result.items.length, 3); | ||
}).then(done, done); | ||
}); | ||
|
||
it('Provide completion from schema declared in file with several attributes', done => { | ||
const content = `# yaml-language-server: $schema=${uri} anothermodeline=value\n- `; | ||
const completion = parseSetup(content, content.length); | ||
completion.then(function (result) { | ||
assert.equal(result.items.length, 3); | ||
}).then(done, done); | ||
}); | ||
}); | ||
}); |
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,84 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Red Hat. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import assert = require('assert'); | ||
import {parse} from './../src/languageservice/parser/yamlParser07'; | ||
import { YAMLDocument } from '../src/languageservice/parser/yamlParser07'; | ||
import { getNodeValue } from '../src/languageservice/parser/jsonParser07'; | ||
|
||
|
||
suite('Test parser', () => { | ||
|
||
describe('test parser', function () { | ||
|
||
it('parse emtpy text', () => { | ||
const parsedDocument = parse(''); | ||
assert(parsedDocument.documents.length === 0, 'A document has been created for an empty text'); | ||
}); | ||
|
||
it('parse single document', () => { | ||
const parsedDocument = parse('test'); | ||
assert(parsedDocument.documents.length === 1, `A single document shoudl be available but there are ${parsedDocument.documents.length}`); | ||
assert(parsedDocument.documents[0].root.children.length === 0, `There should no children available but there are ${parsedDocument.documents[0].root.children.length}`); | ||
}); | ||
|
||
it('parse single document with directives', () => { | ||
const parsedDocument = parse('%TAG demo\n---\ntest'); | ||
assert(parsedDocument.documents.length === 1, `A single document shoudl be available but there are ${parsedDocument.documents.length}`); | ||
assert(parsedDocument.documents[0].root.children.length === 0, `There should no children available but there are ${parsedDocument.documents[0].root.children.length}`); | ||
}); | ||
|
||
it('parse 2 documents', () => { | ||
const parsedDocument = parse('test\n---\ntest2'); | ||
assert(parsedDocument.documents.length === 2, `2 documents should be available but there are ${parsedDocument.documents.length}`); | ||
assert(parsedDocument.documents[0].root.children.length === 0, `There should no children available but there are ${parsedDocument.documents[0].root.children.length}`); | ||
assert(parsedDocument.documents[0].root.value === 'test'); | ||
assert(parsedDocument.documents[1].root.children.length === 0, `There should no children available but there are ${parsedDocument.documents[1].root.children.length}`); | ||
assert(parsedDocument.documents[1].root.value === 'test2'); | ||
}); | ||
|
||
it('parse 3 documents', () => { | ||
const parsedDocument = parse('test\n---\ntest2\n---\ntest3'); | ||
assert(parsedDocument.documents.length === 3, `3 documents should be available but there are ${parsedDocument.documents.length}`); | ||
assert(parsedDocument.documents[0].root.children.length === 0, `There should no children available but there are ${parsedDocument.documents[0].root.children.length}`); | ||
assert(parsedDocument.documents[0].root.value === 'test'); | ||
assert(parsedDocument.documents[1].root.children.length === 0, `There should no children available but there are ${parsedDocument.documents[1].root.children.length}`); | ||
assert(parsedDocument.documents[1].root.value === 'test2'); | ||
assert(parsedDocument.documents[2].root.children.length === 0, `There should no children available but there are ${parsedDocument.documents[2].root.children.length}`); | ||
assert(parsedDocument.documents[2].root.value === 'test3'); | ||
}); | ||
|
||
it('parse single document with comment', () => { | ||
const parsedDocument = parse('# a comment\ntest'); | ||
assert(parsedDocument.documents.length === 1, `A single document should be available but there are ${parsedDocument.documents.length}`); | ||
assert(parsedDocument.documents[0].root.children.length === 0, `There should no children available but there are ${parsedDocument.documents[0].root.children.length}`); | ||
assert(parsedDocument.documents[0].lineComments.length === 1); | ||
assert(parsedDocument.documents[0].lineComments[0] === '# a comment'); | ||
}); | ||
|
||
it('parse 2 documents with comment', () => { | ||
const parsedDocument = parse('# a comment\ntest\n---\n# a second comment\ntest2'); | ||
assert(parsedDocument.documents.length === 2, `2 documents should be available but there are ${parsedDocument.documents.length}`); | ||
assert(parsedDocument.documents[0].root.children.length === 0, `There should no children available but there are ${parsedDocument.documents[0].root.children.length}`); | ||
assert(parsedDocument.documents[0].lineComments.length === 1); | ||
assert(parsedDocument.documents[0].lineComments[0] === '# a comment'); | ||
|
||
assert(parsedDocument.documents[1].root.children.length === 0, `There should no children available but there are ${parsedDocument.documents[0].root.children.length}`); | ||
assert(parsedDocument.documents[1].lineComments.length === 1); | ||
assert(parsedDocument.documents[1].lineComments[0] === '# a second comment'); | ||
}); | ||
|
||
it('parse 2 documents with comment and a directive', () => { | ||
const parsedDocument = parse('%TAG demo\n---\n# a comment\ntest\n---\n# a second comment\ntest2'); | ||
assert(parsedDocument.documents.length === 2, `2 documents should be available but there are ${parsedDocument.documents.length}`); | ||
assert(parsedDocument.documents[0].root.children.length === 0, `There should no children available but there are ${parsedDocument.documents[0].root.children.length}`); | ||
assert(parsedDocument.documents[0].lineComments.length === 1); | ||
assert(parsedDocument.documents[0].lineComments[0] === '# a comment'); | ||
|
||
assert(parsedDocument.documents[1].root.children.length === 0, `There should no children available but there are ${parsedDocument.documents[0].root.children.length}`); | ||
assert(parsedDocument.documents[1].lineComments.length === 1); | ||
assert(parsedDocument.documents[1].lineComments[0] === '# a second comment'); | ||
}); | ||
}); | ||
}); |