diff --git a/package.json b/package.json index 6165f73b..0bc28506 100755 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "js-yaml": "^3.13.1", "jsonc-parser": "^2.2.1", "request-light": "^0.2.4", - "vscode-json-languageservice": "^3.10.0", + "vscode-json-languageservice": "^4.0.2", "vscode-languageserver": "^7.0.0", "vscode-languageserver-textdocument": "^1.0.1", "vscode-languageserver-types": "^3.16.0", diff --git a/test/documentSymbols.test.ts b/test/documentSymbols.test.ts index 1811ebab..5c0144b5 100644 --- a/test/documentSymbols.test.ts +++ b/test/documentSymbols.test.ts @@ -3,7 +3,11 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import { setupLanguageService, setupTextDocument, TEST_URI } from './utils/testHelper'; -import { createExpectedSymbolInformation, createExpectedDocumentSymbol } from './utils/verifyError'; +import { + createExpectedSymbolInformation, + createExpectedDocumentSymbol, + createExpectedDocumentSymbolNoDetail, +} from './utils/verifyError'; import { DocumentSymbol, SymbolKind } from 'vscode-languageserver-types'; import assert = require('assert'); import { ServiceSetup } from './utils/serviceSetup'; @@ -141,29 +145,29 @@ describe('Document Symbols Tests', () => { const content = 'cwd: test'; const symbols = parseHierarchicalSetup(content); assert.equal(symbols.length, 1); - assert.deepEqual(symbols[0], createExpectedDocumentSymbol('cwd', 15, 0, 0, 0, 9, 0, 0, 0, 3)); + assert.deepEqual(symbols[0], createExpectedDocumentSymbol('cwd', 15, 0, 0, 0, 9, 0, 0, 0, 3, [], 'test')); }); it('Document Symbols with number', () => { const content = 'node1: 10000'; const symbols = parseHierarchicalSetup(content); assert.equal(symbols.length, 1); - assert.deepEqual(symbols[0], createExpectedDocumentSymbol('node1', 16, 0, 0, 0, 12, 0, 0, 0, 5)); + assert.deepEqual(symbols[0], createExpectedDocumentSymbol('node1', 16, 0, 0, 0, 12, 0, 0, 0, 5, [], '10000')); }); it('Document Symbols with boolean', () => { const content = 'node1: False'; const symbols = parseHierarchicalSetup(content); assert.equal(symbols.length, 1); - assert.deepEqual(symbols[0], createExpectedDocumentSymbol('node1', 17, 0, 0, 0, 12, 0, 0, 0, 5)); + assert.deepEqual(symbols[0], createExpectedDocumentSymbol('node1', 17, 0, 0, 0, 12, 0, 0, 0, 5, [], 'false')); }); it('Document Symbols with object', () => { const content = 'scripts:\n node1: test\n node2: test'; const symbols = parseHierarchicalSetup(content); assert.equal(symbols.length, 1); - const child1 = createExpectedDocumentSymbol('node1', SymbolKind.String, 1, 2, 1, 13, 1, 2, 1, 7); - const child2 = createExpectedDocumentSymbol('node2', SymbolKind.String, 2, 2, 2, 13, 2, 2, 2, 7); + const child1 = createExpectedDocumentSymbol('node1', SymbolKind.String, 1, 2, 1, 13, 1, 2, 1, 7, [], 'test'); + const child2 = createExpectedDocumentSymbol('node2', SymbolKind.String, 2, 2, 2, 13, 2, 2, 2, 7, [], 'test'); const children = [child1, child2]; assert.deepEqual(symbols[0], createExpectedDocumentSymbol('scripts', SymbolKind.Module, 0, 0, 2, 13, 0, 0, 0, 7, children)); }); @@ -172,15 +176,18 @@ describe('Document Symbols Tests', () => { const content = 'apiVersion: null'; const symbols = parseHierarchicalSetup(content); assert.equal(symbols.length, 1); - assert.deepEqual(symbols[0], createExpectedDocumentSymbol('apiVersion', SymbolKind.Variable, 0, 0, 0, 16, 0, 0, 0, 10)); + assert.deepEqual( + symbols[0], + createExpectedDocumentSymbol('apiVersion', SymbolKind.Variable, 0, 0, 0, 16, 0, 0, 0, 10, [], 'null') + ); }); it('Document Symbols with array of strings', () => { const content = 'items:\n - test\n - test'; const symbols = parseHierarchicalSetup(content); assert.equal(symbols.length, 1); - const child1 = createExpectedDocumentSymbol('0', SymbolKind.String, 1, 4, 1, 8, 1, 4, 1, 8); - const child2 = createExpectedDocumentSymbol('1', SymbolKind.String, 2, 4, 2, 8, 2, 4, 2, 8); + const child1 = createExpectedDocumentSymbolNoDetail('0', SymbolKind.String, 1, 4, 1, 8, 1, 4, 1, 8); + const child2 = createExpectedDocumentSymbolNoDetail('1', SymbolKind.String, 2, 4, 2, 8, 2, 4, 2, 8); const children = [child1, child2]; assert.deepEqual(symbols[0], createExpectedDocumentSymbol('items', SymbolKind.Array, 0, 0, 2, 8, 0, 0, 0, 5, children)); }); @@ -189,11 +196,11 @@ describe('Document Symbols Tests', () => { const content = 'authors:\n - name: Josh\n - email: jp'; const symbols = parseHierarchicalSetup(content); - const object1 = createExpectedDocumentSymbol('name', SymbolKind.String, 1, 4, 1, 14, 1, 4, 1, 8); - const arrayChild1 = createExpectedDocumentSymbol('0', SymbolKind.Module, 1, 4, 1, 14, 1, 4, 1, 14, [object1]); + const object1 = createExpectedDocumentSymbol('name', SymbolKind.String, 1, 4, 1, 14, 1, 4, 1, 8, [], 'Josh'); + const arrayChild1 = createExpectedDocumentSymbolNoDetail('0', SymbolKind.Module, 1, 4, 1, 14, 1, 4, 1, 14, [object1]); - const object2 = createExpectedDocumentSymbol('email', SymbolKind.String, 2, 4, 2, 13, 2, 4, 2, 9); - const arrayChild2 = createExpectedDocumentSymbol('1', SymbolKind.Module, 2, 4, 2, 13, 2, 4, 2, 13, [object2]); + const object2 = createExpectedDocumentSymbol('email', SymbolKind.String, 2, 4, 2, 13, 2, 4, 2, 9, [], 'jp'); + const arrayChild2 = createExpectedDocumentSymbolNoDetail('1', SymbolKind.Module, 2, 4, 2, 13, 2, 4, 2, 13, [object2]); const children = [arrayChild1, arrayChild2]; assert.deepEqual(symbols[0], createExpectedDocumentSymbol('authors', SymbolKind.Array, 0, 0, 2, 13, 0, 0, 0, 7, children)); }); @@ -203,16 +210,16 @@ describe('Document Symbols Tests', () => { const symbols = parseHierarchicalSetup(content); assert.equal(symbols.length, 2); - const child1 = createExpectedDocumentSymbol('node1', SymbolKind.String, 1, 2, 1, 13, 1, 2, 1, 7); - const child2 = createExpectedDocumentSymbol('node2', SymbolKind.String, 2, 2, 2, 13, 2, 2, 2, 7); + const child1 = createExpectedDocumentSymbol('node1', SymbolKind.String, 1, 2, 1, 13, 1, 2, 1, 7, [], 'test'); + const child2 = createExpectedDocumentSymbol('node2', SymbolKind.String, 2, 2, 2, 13, 2, 2, 2, 7, [], 'test'); const children = [child1, child2]; assert.deepEqual(symbols[0], createExpectedDocumentSymbol('scripts', SymbolKind.Module, 0, 0, 2, 13, 0, 0, 0, 7, children)); - const object1 = createExpectedDocumentSymbol('name', SymbolKind.String, 4, 4, 4, 14, 4, 4, 4, 8); - const arrayChild1 = createExpectedDocumentSymbol('0', SymbolKind.Module, 4, 4, 4, 14, 4, 4, 4, 14, [object1]); + const object1 = createExpectedDocumentSymbol('name', SymbolKind.String, 4, 4, 4, 14, 4, 4, 4, 8, [], 'Josh'); + const arrayChild1 = createExpectedDocumentSymbolNoDetail('0', SymbolKind.Module, 4, 4, 4, 14, 4, 4, 4, 14, [object1]); - const object2 = createExpectedDocumentSymbol('email', SymbolKind.String, 5, 4, 5, 13, 5, 4, 5, 9); - const arrayChild2 = createExpectedDocumentSymbol('1', SymbolKind.Module, 5, 4, 5, 13, 5, 4, 5, 13, [object2]); + const object2 = createExpectedDocumentSymbol('email', SymbolKind.String, 5, 4, 5, 13, 5, 4, 5, 9, [], 'jp'); + const arrayChild2 = createExpectedDocumentSymbolNoDetail('1', SymbolKind.Module, 5, 4, 5, 13, 5, 4, 5, 13, [object2]); const children2 = [arrayChild1, arrayChild2]; assert.deepEqual(symbols[1], createExpectedDocumentSymbol('authors', SymbolKind.Array, 3, 0, 5, 13, 3, 0, 3, 7, children2)); @@ -222,8 +229,11 @@ describe('Document Symbols Tests', () => { const content = '---\nanalytics: true\n...\n---\njson: test\n...'; const symbols = parseHierarchicalSetup(content); assert.equal(symbols.length, 2); - assert.deepEqual(symbols[0], createExpectedDocumentSymbol('analytics', SymbolKind.Boolean, 1, 0, 1, 15, 1, 0, 1, 9)); - assert.deepEqual(symbols[1], createExpectedDocumentSymbol('json', SymbolKind.String, 4, 0, 4, 10, 4, 0, 4, 4)); + assert.deepEqual( + symbols[0], + createExpectedDocumentSymbol('analytics', SymbolKind.Boolean, 1, 0, 1, 15, 1, 0, 1, 9, [], 'true') + ); + assert.deepEqual(symbols[1], createExpectedDocumentSymbol('json', SymbolKind.String, 4, 0, 4, 10, 4, 0, 4, 4, [], 'test')); }); it('Document Symbols with complex mapping and aliases', () => { @@ -243,12 +253,15 @@ describe('Document Symbols Tests', () => { const symbols = parseHierarchicalSetup(content); assert.equal(symbols.length, 3); - assert.deepEqual(symbols[0], createExpectedDocumentSymbol('version', SymbolKind.String, 1, 12, 1, 26, 1, 12, 1, 19)); + assert.deepEqual( + symbols[0], + createExpectedDocumentSymbol('version', SymbolKind.String, 1, 12, 1, 26, 1, 12, 1, 19, [], '0.0.1') + ); - const element = createExpectedDocumentSymbol('element', SymbolKind.String, 5, 16, 5, 28, 5, 16, 5, 23); + const element = createExpectedDocumentSymbol('element', SymbolKind.String, 5, 16, 5, 28, 5, 16, 5, 23, [], 'div'); const root1 = createExpectedDocumentSymbol('root', SymbolKind.Module, 3, 22, 5, 28, 3, 22, 3, 26, [element]); - const height = createExpectedDocumentSymbol('height', SymbolKind.Number, 10, 18, 10, 28, 10, 18, 10, 24); + const height = createExpectedDocumentSymbol('height', SymbolKind.Number, 10, 18, 10, 28, 10, 18, 10, 24, [], '41'); const style = createExpectedDocumentSymbol('style', SymbolKind.Module, 9, 16, 10, 28, 9, 16, 9, 21, [height]); const root2 = createExpectedDocumentSymbol('root', SymbolKind.Module, 7, 17, 10, 28, 7, 17, 7, 21, [style]); diff --git a/test/utils/verifyError.ts b/test/utils/verifyError.ts index f76fb637..806dafd5 100644 --- a/test/utils/verifyError.ts +++ b/test/utils/verifyError.ts @@ -64,6 +64,32 @@ export function createExpectedSymbolInformation( } export function createExpectedDocumentSymbol( + name: string, + kind: SymbolKind, + startLine: number, + startCharacter: number, + endLine: number, + endCharacter: number, + startLineSelection: number, + startCharacterSelection: number, + endLineSelection: number, + endCharacterSelection: number, + children: DocumentSymbol[] = [], + detail?: string +): DocumentSymbol { + const docSymbol = DocumentSymbol.create( + name, + detail, + kind, + Range.create(startLine, startCharacter, endLine, endCharacter), + Range.create(startLineSelection, startCharacterSelection, endLineSelection, endCharacterSelection), + children + ); + + return docSymbol; +} + +export function createExpectedDocumentSymbolNoDetail( name: string, kind: SymbolKind, startLine: number, @@ -76,31 +102,17 @@ export function createExpectedDocumentSymbol( endCharacterSelection: number, children: DocumentSymbol[] = [] ): DocumentSymbol { - return { + const docSymbol = DocumentSymbol.create( name, + undefined, kind, - range: { - start: { - character: startCharacter, - line: startLine, - }, - end: { - character: endCharacter, - line: endLine, - }, - }, - selectionRange: { - start: { - character: startCharacterSelection, - line: startLineSelection, - }, - end: { - character: endCharacterSelection, - line: endLineSelection, - }, - }, - children, - }; + Range.create(startLine, startCharacter, endLine, endCharacter), + Range.create(startLineSelection, startCharacterSelection, endLineSelection, endCharacterSelection), + children + ); + + delete docSymbol.detail; + return docSymbol; } export function createExpectedCompletion( diff --git a/yarn.lock b/yarn.lock index 42b69d45..187b4fae 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1305,10 +1305,10 @@ jsonc-parser@^2.2.1: resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-2.2.1.tgz#db73cd59d78cce28723199466b2a03d1be1df2bc" integrity sha512-o6/yDBYccGvTz1+QFevz6l6OBZ2+fMVu2JZ9CIhzsYRX4mjaK5IyX9eldUdCmga16zlgQxyrj5pt9kzuj2C02w== -jsonc-parser@^2.3.1: - version "2.3.1" - resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-2.3.1.tgz#59549150b133f2efacca48fe9ce1ec0659af2342" - integrity sha512-H8jvkz1O50L3dMZCsLqiuB2tA7muqbSg1AtGEkN0leAqGjsUzDJir3Zwr02BhqdcITPg3ei3mZ+HjMocAknhhg== +jsonc-parser@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-3.0.0.tgz#abdd785701c7e7eaca8a9ec8cf070ca51a745a22" + integrity sha512-fQzRfAbIBnR0IQvftw9FJveWiHp72Fg20giDrHz6TdfB12UH/uue0D3hm57UB5KgAVuniLMCaS8P1IMj9NR7cA== jsprim@^1.2.2: version "1.4.1" @@ -2244,16 +2244,16 @@ verror@1.10.0: core-util-is "1.0.2" extsprintf "^1.2.0" -vscode-json-languageservice@^3.10.0: - version "3.10.0" - resolved "https://registry.yarnpkg.com/vscode-json-languageservice/-/vscode-json-languageservice-3.10.0.tgz#19eed884fd0f234f8ed2fa0a96e772f293ccc5c4" - integrity sha512-8IvuRSQnjznu+obqy6Dy4S4H68Ke7a3Kb+A0FcdctyAMAWEnrORpCpMOMqEYiPLm/OTYLVWJ7ql3qToDTozu4w== +vscode-json-languageservice@^4.0.2: + version "4.0.2" + resolved "https://registry.yarnpkg.com/vscode-json-languageservice/-/vscode-json-languageservice-4.0.2.tgz#8f91dc3a33dac180063067f8277f4facdc0795b6" + integrity sha512-d8Ahw990Cq/G60CzN26rehXcbhbMgMGMmXeN6C/V/RYZUhfs16EELRK+EL7b/3Y8ZGshtKqboePSeDVa94qqFg== dependencies: - jsonc-parser "^2.3.1" + jsonc-parser "^3.0.0" vscode-languageserver-textdocument "^1.0.1" - vscode-languageserver-types "3.16.0-next.2" + vscode-languageserver-types "^3.16.0" vscode-nls "^5.0.0" - vscode-uri "^2.1.2" + vscode-uri "^3.0.2" vscode-jsonrpc@6.0.0: version "6.0.0" @@ -2278,11 +2278,6 @@ vscode-languageserver-types@3.16.0, vscode-languageserver-types@^3.16.0: resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.16.0.tgz#ecf393fc121ec6974b2da3efb3155644c514e247" integrity sha512-k8luDIWJWyenLc5ToFQQMaSrqCHiLwyKPHKPQZ5zz21vM+vIVUSvsRpcbiECH4WR88K2XZqc4ScRcZ7nk/jbeA== -vscode-languageserver-types@3.16.0-next.2: - version "3.16.0-next.2" - resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.16.0-next.2.tgz#940bd15c992295a65eae8ab6b8568a1e8daa3083" - integrity sha512-QjXB7CKIfFzKbiCJC4OWC8xUncLsxo19FzGVp/ADFvvi87PlmBSCAtZI5xwGjF5qE0xkLf0jjKUn3DzmpDP52Q== - vscode-languageserver@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/vscode-languageserver/-/vscode-languageserver-7.0.0.tgz#49b068c87cfcca93a356969d20f5d9bdd501c6b0" @@ -2305,10 +2300,10 @@ vscode-uri@^2.1.1: resolved "https://registry.yarnpkg.com/vscode-uri/-/vscode-uri-2.1.1.tgz#5aa1803391b6ebdd17d047f51365cf62c38f6e90" integrity sha512-eY9jmGoEnVf8VE8xr5znSah7Qt1P/xsCdErz+g8HYZtJ7bZqKH5E3d+6oVNm1AC/c6IHUDokbmVXKOi4qPAC9A== -vscode-uri@^2.1.2: - version "2.1.2" - resolved "https://registry.yarnpkg.com/vscode-uri/-/vscode-uri-2.1.2.tgz#c8d40de93eb57af31f3c715dd650e2ca2c096f1c" - integrity sha512-8TEXQxlldWAuIODdukIb+TR5s+9Ds40eSJrw+1iDDA9IFORPjMELarNQE3myz5XIkWWpdprmJjm1/SxMlWOC8A== +vscode-uri@^3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/vscode-uri/-/vscode-uri-3.0.2.tgz#ecfd1d066cb8ef4c3a208decdbab9a8c23d055d0" + integrity sha512-jkjy6pjU1fxUvI51P+gCsxg1u2n8LSt0W6KrCNQceaziKzff74GoWmjVG46KieVzybO1sttPQmYfrwSHey7GUA== which-module@^2.0.0: version "2.0.0"