|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Red Hat. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | +import { getLanguageService } from '../src/languageservice/yamlLanguageService'; |
| 6 | +import { schemaRequestService, setupTextDocument, workspaceContext } from './utils/testHelper'; |
| 7 | +import assert = require('assert'); |
| 8 | + |
| 9 | +const languageService = getLanguageService(schemaRequestService, workspaceContext, [], null); |
| 10 | + |
| 11 | +suite('FindDefintion Tests', () => { |
| 12 | + |
| 13 | + describe('Jump to defintion', function () { |
| 14 | + |
| 15 | + function findDefinitions(content: string, position: number) { |
| 16 | + const testTextDocument = setupTextDocument(content); |
| 17 | + return languageService.findDefinition(testTextDocument, testTextDocument.positionAt(position)); |
| 18 | + } |
| 19 | + |
| 20 | + it('Find source defintion', done => { |
| 21 | + const content = "definitions:\n link:\n type: string\ntype: object\nproperties:\n uri:\n $ref: '#/definitions/link'\n"; |
| 22 | + const definitions = findDefinitions(content, content.lastIndexOf('/li')); |
| 23 | + definitions.then(function (results) { |
| 24 | + assert.equal(results.length, 1); |
| 25 | + assert.deepEqual(results[0].originSelectionRange, { |
| 26 | + start: { |
| 27 | + line: 6, |
| 28 | + character: 10 |
| 29 | + }, |
| 30 | + end: { |
| 31 | + line: 6, |
| 32 | + character: 30 |
| 33 | + } |
| 34 | + }); |
| 35 | + assert.deepEqual(results[0].targetRange, { |
| 36 | + start: { |
| 37 | + line: 2, |
| 38 | + character: 4 |
| 39 | + }, |
| 40 | + end: { |
| 41 | + line: 2, |
| 42 | + character: 16 |
| 43 | + } |
| 44 | + }); |
| 45 | + }).then(done, done); |
| 46 | + }); |
| 47 | + }); |
| 48 | +}); |
0 commit comments