-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #257 from ananthakumaran/findDefinition
add support for textDocument/definition
- Loading branch information
Showing
6 changed files
with
98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { JSONSchemaRef, JSONSchema } from '../jsonSchema'; | ||
import { TextDocument, Position, DefinitionLink } from 'vscode-languageserver-types'; | ||
import { parse as parseYAML } from '../parser/yamlParser07'; | ||
import { matchOffsetToDocument } from '../utils/arrUtils'; | ||
import { findDefinition as JSONFindDefinition } from 'vscode-json-languageservice/lib/umd/services/jsonDefinition'; | ||
|
||
export function findDefinition(document: TextDocument, position: Position): Thenable<DefinitionLink[]> { | ||
const doc = parseYAML(document.getText()); | ||
const offset = document.offsetAt(position); | ||
const currentDoc = matchOffsetToDocument(offset, doc); | ||
if (currentDoc === null) { | ||
return Promise.resolve([]); | ||
} | ||
|
||
const currentDocIndex = doc.documents.indexOf(currentDoc); | ||
currentDoc.currentDocIndex = currentDocIndex; | ||
return JSONFindDefinition(document, position, currentDoc); | ||
} |
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,48 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Red Hat. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import { getLanguageService } from '../src/languageservice/yamlLanguageService'; | ||
import { schemaRequestService, setupTextDocument, workspaceContext } from './utils/testHelper'; | ||
import assert = require('assert'); | ||
|
||
const languageService = getLanguageService(schemaRequestService, workspaceContext, [], null); | ||
|
||
suite('FindDefintion Tests', () => { | ||
|
||
describe('Jump to defintion', function () { | ||
|
||
function findDefinitions(content: string, position: number) { | ||
const testTextDocument = setupTextDocument(content); | ||
return languageService.findDefinition(testTextDocument, testTextDocument.positionAt(position)); | ||
} | ||
|
||
it('Find source defintion', done => { | ||
const content = "definitions:\n link:\n type: string\ntype: object\nproperties:\n uri:\n $ref: '#/definitions/link'\n"; | ||
const definitions = findDefinitions(content, content.lastIndexOf('/li')); | ||
definitions.then(function (results) { | ||
assert.equal(results.length, 1); | ||
assert.deepEqual(results[0].originSelectionRange, { | ||
start: { | ||
line: 6, | ||
character: 10 | ||
}, | ||
end: { | ||
line: 6, | ||
character: 30 | ||
} | ||
}); | ||
assert.deepEqual(results[0].targetRange, { | ||
start: { | ||
line: 2, | ||
character: 4 | ||
}, | ||
end: { | ||
line: 2, | ||
character: 16 | ||
} | ||
}); | ||
}).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 |
---|---|---|
|
@@ -1490,15 +1490,15 @@ [email protected]: | |
core-util-is "1.0.2" | ||
extsprintf "^1.2.0" | ||
|
||
vscode-json-languageservice@^3.5.2: | ||
version "3.5.2" | ||
resolved "https://registry.yarnpkg.com/vscode-json-languageservice/-/vscode-json-languageservice-3.5.2.tgz#4b898140a8e581359c10660845a4cae15dcbb4f9" | ||
integrity sha512-9cUvBq00O08lpWVVOx6tQ1yLxCHss79nsUdEAVYGomRyMbnPBmc0AkYPcXI9WK1EM6HBo0R9Zo3NjFhcICpy4A== | ||
vscode-json-languageservice@^3.6.0: | ||
version "3.6.0" | ||
resolved "https://registry.yarnpkg.com/vscode-json-languageservice/-/vscode-json-languageservice-3.6.0.tgz#133a1e2c3a3dffe38564a1ba948516805c3c1869" | ||
integrity sha512-dXzFywypUZ9T0tjr4fREZiknXDz6vAGx1zsxbQY1+9DOpjMfbz0VLP873KmcbuvL4K3nseKTxc4TKHu8kLXRMw== | ||
dependencies: | ||
jsonc-parser "^2.2.1" | ||
vscode-languageserver-textdocument "^1.0.1" | ||
vscode-languageserver-types "^3.15.1" | ||
vscode-nls "^4.1.1" | ||
vscode-nls "^4.1.2" | ||
vscode-uri "^2.1.1" | ||
|
||
vscode-jsonrpc@^4.0.0: | ||
|