diff --git a/package.json b/package.json index 7bd8603bfc..2e95edd2db 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "release:next-base": "npm run release:base -- --dist-tag next", "release:next-vue": "cd ./extensions/vscode && npm run release:next", "test": "vitest run", + "test:update": "vitest run --update", "lint": "tsslint --projects {tsconfig.json,packages/*/tsconfig.json,extensions/*/tsconfig.json}", "lint:fix": "npm run lint -- --fix", "chrome": "vscode-test-web --browserType=chromium --extensionDevelopmentPath=./extensions/vscode ../volar-starter" @@ -31,14 +32,14 @@ }, "pnpm": { "overrides": { - "@volar/kit": "https://pkg.pr.new/volarjs/volar.js/@volar/kit@87ad0b2", - "@volar/language-core": "https://pkg.pr.new/volarjs/volar.js/@volar/language-core@87ad0b2", - "@volar/language-server": "https://pkg.pr.new/volarjs/volar.js/@volar/language-server@87ad0b2", - "@volar/language-service": "https://pkg.pr.new/volarjs/volar.js/@volar/language-service@87ad0b2", - "@volar/source-map": "https://pkg.pr.new/volarjs/volar.js/@volar/source-map@87ad0b2", - "@volar/test-utils": "https://pkg.pr.new/volarjs/volar.js/@volar/test-utils@87ad0b2", - "@volar/typescript": "https://pkg.pr.new/volarjs/volar.js/@volar/typescript@87ad0b2", - "@volar/vscode": "https://pkg.pr.new/volarjs/volar.js/@volar/vscode@87ad0b2", + "@volar/kit": "https://pkg.pr.new/volarjs/volar.js/@volar/kit@28cbdee", + "@volar/language-core": "https://pkg.pr.new/volarjs/volar.js/@volar/language-core@28cbdee", + "@volar/language-server": "https://pkg.pr.new/volarjs/volar.js/@volar/language-server@28cbdee", + "@volar/language-service": "https://pkg.pr.new/volarjs/volar.js/@volar/language-service@28cbdee", + "@volar/source-map": "https://pkg.pr.new/volarjs/volar.js/@volar/source-map@28cbdee", + "@volar/test-utils": "https://pkg.pr.new/volarjs/volar.js/@volar/test-utils@28cbdee", + "@volar/typescript": "https://pkg.pr.new/volarjs/volar.js/@volar/typescript@28cbdee", + "@volar/vscode": "https://pkg.pr.new/volarjs/volar.js/@volar/vscode@28cbdee", "volar-service-typescript": "https://pkg.pr.new/volarjs/services/volar-service-typescript@177b9ed", "inquirer": "9.2.23" } diff --git a/packages/language-server/tests/__snapshots__/completions.spec.ts.snap b/packages/language-server/tests/__snapshots__/completions.spec.ts.snap deleted file mode 100644 index f2b3dd1bf6..0000000000 --- a/packages/language-server/tests/__snapshots__/completions.spec.ts.snap +++ /dev/null @@ -1,124 +0,0 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html - -exports[`Completions > #2454 1`] = ` -" - - - - " -`; - -exports[`Completions > #2511 1`] = ` -" - - " -`; - -exports[`Completions > #3658 1`] = ` -" - - " -`; - -exports[`Completions > #4639 1`] = ` -" - - " -`; - -exports[`Completions > $event argument 1`] = `""`; - -exports[`Completions > - " -`; - -exports[`Completions > Alias path 1`] = ` -" - - " -`; - -exports[`Completions > Component auto import 1`] = ` -" - - - - " -`; - -exports[`Completions > Directives 1`] = `""`; - -exports[`Completions > Directives 2`] = `""`; - -exports[`Completions > Directives 3`] = `""`; - -exports[`Completions > Directives 4`] = `""`; - -exports[`Completions > Relative path 1`] = ` -" - - " -`; - -exports[`Completions > Slot name 1`] = ` -" - - - - " -`; - -exports[`Completions > core#8811 1`] = ` -" - - - - " -`; diff --git a/packages/language-server/tests/__snapshots__/definitions.spec.ts.snap b/packages/language-server/tests/__snapshots__/definitions.spec.ts.snap deleted file mode 100644 index ff893647c0..0000000000 --- a/packages/language-server/tests/__snapshots__/definitions.spec.ts.snap +++ /dev/null @@ -1,61 +0,0 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html - -exports[`Definitions > #2600 1`] = `"tsconfigProject/foo.vue"`; - -exports[`Definitions > #2600 2`] = ` -{ - "end": { - "character": 0, - "line": 0, - }, - "start": { - "character": 0, - "line": 0, - }, -} -`; - -exports[`Definitions > Alias path 1`] = `"tsconfigProject/foo.ts"`; - -exports[`Definitions > Alias path 2`] = ` -{ - "end": { - "character": 25, - "line": 0, - }, - "start": { - "character": 0, - "line": 0, - }, -} -`; - -exports[`Definitions > TS to vue 1`] = `"tsconfigProject/empty.vue"`; - -exports[`Definitions > TS to vue 2`] = ` -{ - "end": { - "character": 0, - "line": 0, - }, - "start": { - "character": 0, - "line": 0, - }, -} -`; - -exports[`Definitions > TS to vue 3`] = `"tsconfigProject/empty.vue"`; - -exports[`Definitions > TS to vue 4`] = ` -{ - "end": { - "character": 0, - "line": 0, - }, - "start": { - "character": 0, - "line": 0, - }, -} -`; diff --git a/packages/language-server/tests/__snapshots__/inlayHints.spec.ts.snap b/packages/language-server/tests/__snapshots__/inlayHints.spec.ts.snap deleted file mode 100644 index 72d2107aaa..0000000000 --- a/packages/language-server/tests/__snapshots__/inlayHints.spec.ts.snap +++ /dev/null @@ -1,80 +0,0 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html - -exports[`Definitions > Destructured props 1`] = ` -" - - " -`; - -exports[`Definitions > Inline handler leading 1`] = ` -" - - - - " -`; - -exports[`Definitions > Missing props 1`] = ` -" - - - - " -`; - -exports[`Definitions > Options wrapper 1`] = ` -" - - " -`; diff --git a/packages/language-server/tests/__snapshots__/references.spec.ts.snap b/packages/language-server/tests/__snapshots__/references.spec.ts.snap deleted file mode 100644 index b741277166..0000000000 --- a/packages/language-server/tests/__snapshots__/references.spec.ts.snap +++ /dev/null @@ -1,91 +0,0 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html - -exports[`Definitions > Default slot 1`] = `"tsconfigProject/foo.vue"`; - -exports[`Definitions > Default slot 2`] = ` -{ - "end": { - "character": 16, - "line": 7, - }, - "start": { - "character": 5, - "line": 7, - }, -} -`; - -exports[`Definitions > Default slot 3`] = `"tsconfigProject/fixture.vue"`; - -exports[`Definitions > Default slot 4`] = ` -{ - "end": { - "character": 9, - "line": 2, - }, - "start": { - "character": 5, - "line": 2, - }, -} -`; - -exports[`Definitions > Named slot 1`] = `"tsconfigProject/foo.vue"`; - -exports[`Definitions > Named slot 2`] = ` -{ - "end": { - "character": 17, - "line": 6, - }, - "start": { - "character": 14, - "line": 6, - }, -} -`; - -exports[`Definitions > Named slot 3`] = `"tsconfigProject/fixture.vue"`; - -exports[`Definitions > Named slot 4`] = ` -{ - "end": { - "character": 19, - "line": 2, - }, - "start": { - "character": 16, - "line": 2, - }, -} -`; - -exports[`Definitions > v-bind shorthand 1`] = `"tsconfigProject/fixture.vue"`; - -exports[`Definitions > v-bind shorthand 2`] = ` -{ - "end": { - "character": 13, - "line": 6, - }, - "start": { - "character": 10, - "line": 6, - }, -} -`; - -exports[`Definitions > v-bind shorthand 3`] = `"tsconfigProject/fixture.vue"`; - -exports[`Definitions > v-bind shorthand 4`] = ` -{ - "end": { - "character": 12, - "line": 2, - }, - "start": { - "character": 9, - "line": 2, - }, -} -`; diff --git a/packages/language-server/tests/__snapshots__/renaming.spec.ts.snap b/packages/language-server/tests/__snapshots__/renaming.spec.ts.snap deleted file mode 100644 index 4ba2f85a1e..0000000000 --- a/packages/language-server/tests/__snapshots__/renaming.spec.ts.snap +++ /dev/null @@ -1,573 +0,0 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html - -exports[`Renaming > #2410 1`] = `"fixture.vue"`; - -exports[`Renaming > #2410 2`] = ` -[ - { - "newText": "h2", - "range": { - "end": { - "character": 18, - "line": 0, - }, - "start": { - "character": 16, - "line": 0, - }, - }, - }, - { - "newText": "h2", - "range": { - "end": { - "character": 13, - "line": 0, - }, - "start": { - "character": 11, - "line": 0, - }, - }, - }, -] -`; - -exports[`Renaming > #2410 3`] = `"fixture.vue"`; - -exports[`Renaming > #2410 4`] = ` -[ - { - "newText": "h2", - "range": { - "end": { - "character": 18, - "line": 0, - }, - "start": { - "character": 16, - "line": 0, - }, - }, - }, - { - "newText": "h2", - "range": { - "end": { - "character": 13, - "line": 0, - }, - "start": { - "character": 11, - "line": 0, - }, - }, - }, -] -`; - -exports[`Renaming > @@ -58,16 +82,32 @@ describe('Completions', async () => { it('#2511', async () => { await ensureGlobalTypesHolder('tsconfigProject'); - await openDocument('tsconfigProject/component-for-auto-import.vue', 'vue', ``); - await assertCompletion('tsconfigProject/fixture.vue', 'vue', ` - - `, 'ComponentForAutoImport'); + await prepareDocument('tsconfigProject/component-for-auto-import.vue', 'vue', ``); + expect( + (await requestCompletionItem('tsconfigProject/fixture.vue', 'vue', ` + + `, 'ComponentForAutoImport')).textEdit + ).toMatchInlineSnapshot(` + { + "newText": "import componentForAutoImport$1 from './component-for-auto-import.vue';", + "range": { + "end": { + "character": 23, + "line": 2, + }, + "start": { + "character": 4, + "line": 2, + }, + }, + } + `); }); it('#3658', async () => { - await assertCompletion('fixture.vue', 'vue', ` + await requestCompletionItem('fixture.vue', 'vue', ` `); - await assertReferences('tsconfigProject/fixture.vue', 'vue', ` + expect( + await requestReferences('tsconfigProject/fixture.vue', 'vue', ` + `) + ).toMatchInlineSnapshot(` + [ + { + "range": { + "end": { + "character": 17, + "line": 6, + }, + "start": { + "character": 14, + "line": 6, + }, + }, + "uri": "file://\${testWorkspacePath}/tsconfigProject/foo.vue", + }, + { + "range": { + "end": { + "character": 19, + "line": 2, + }, + "start": { + "character": 16, + "line": 2, + }, + }, + "uri": "file://\${testWorkspacePath}/tsconfigProject/fixture.vue", + }, + ] `); }); it('v-bind shorthand', async () => { await ensureGlobalTypesHolder('tsconfigProject'); - await assertReferences('tsconfigProject/fixture.vue', 'vue', ` - + expect( + await requestReferences('tsconfigProject/fixture.vue', 'vue', ` + - + + `) + ).toMatchInlineSnapshot(` + [ + { + "range": { + "end": { + "character": 14, + "line": 6, + }, + "start": { + "character": 11, + "line": 6, + }, + }, + "uri": "file://\${testWorkspacePath}/tsconfigProject/fixture.vue", + }, + { + "range": { + "end": { + "character": 13, + "line": 2, + }, + "start": { + "character": 10, + "line": 2, + }, + }, + "uri": "file://\${testWorkspacePath}/tsconfigProject/fixture.vue", + }, + ] `); }); @@ -71,31 +163,31 @@ describe('Definitions', async () => { * @deprecated Remove this when #4717 fixed. */ async function ensureGlobalTypesHolder(folderName: string) { - const document = await openDocument(`${folderName}/globalTypesHolder.vue`, 'vue', ''); + const document = await prepareDocument(`${folderName}/globalTypesHolder.vue`, 'vue', ''); const server = await getLanguageServer(); await server.sendDocumentDiagnosticRequest(document.uri); } - async function assertReferences(fileName: string, languageId: string, content: string) { + async function requestReferences(fileName: string, languageId: string, content: string) { const offset = content.indexOf('|'); expect(offset).toBeGreaterThanOrEqual(0); content = content.slice(0, offset) + content.slice(offset + 1); const server = await getLanguageServer(); - let document = await openDocument(fileName, languageId, content); + let document = await prepareDocument(fileName, languageId, content); const position = document.positionAt(offset); const references = await server.sendReferencesRequest(document.uri, position, { includeDeclaration: false }); expect(references).toBeDefined(); - expect(references!.length).greaterThan(0); for (const loc of references!) { - expect(path.relative(testWorkspacePath, URI.parse(loc.uri).fsPath)).toMatchSnapshot(); - expect(loc.range).toMatchSnapshot(); + loc.uri = loc.uri.replace(testWorkspacePath, '${testWorkspacePath}'); } + + return references!; } - async function openDocument(fileName: string, languageId: string, content: string) { + async function prepareDocument(fileName: string, languageId: string, content: string) { const server = await getLanguageServer(); const uri = URI.file(`${testWorkspacePath}/${fileName}`); const document = await server.openInMemoryDocument(uri.toString(), languageId, content); diff --git a/packages/language-server/tests/renaming.spec.ts b/packages/language-server/tests/renaming.spec.ts index 20c357c7ef..f9b5905b86 100644 --- a/packages/language-server/tests/renaming.spec.ts +++ b/packages/language-server/tests/renaming.spec.ts @@ -7,82 +7,443 @@ import { getLanguageServer, testWorkspacePath } from './server.js'; describe('Renaming', async () => { it('#2410', async () => { - await assertRenaming('fixture.vue', 'vue', ``, 'h2'); - await assertRenaming('fixture.vue', 'vue', ``, 'h2'); + expect( + await requestRename('fixture.vue', 'vue', ``, 'h2') + ).toMatchInlineSnapshot(` + { + "changes": { + "file://\${testWorkspacePath}/fixture.vue": [ + { + "newText": "h2", + "range": { + "end": { + "character": 18, + "line": 0, + }, + "start": { + "character": 16, + "line": 0, + }, + }, + }, + { + "newText": "h2", + "range": { + "end": { + "character": 13, + "line": 0, + }, + "start": { + "character": 11, + "line": 0, + }, + }, + }, + ], + }, + } + `); + expect( + await requestRename('fixture.vue', 'vue', ``, 'h2') + ).toMatchInlineSnapshot(` + { + "changes": { + "file://\${testWorkspacePath}/fixture.vue": [ + { + "newText": "h2", + "range": { + "end": { + "character": 18, + "line": 0, + }, + "start": { + "character": 16, + "line": 0, + }, + }, + }, + { + "newText": "h2", + "range": { + "end": { + "character": 13, + "line": 0, + }, + "start": { + "character": 11, + "line": 0, + }, + }, + }, + ], + }, + } + `); }); it('CSS', async () => { - await assertRenaming('fixture.vue', 'vue', ` - + expect( + await requestRename('fixture.vue', 'vue', ` + - + - - `, 'bar'); - await assertRenaming('fixture.vue', 'vue', ` - + + `, 'bar') + ).toMatchInlineSnapshot(` + { + "changes": { + "file://\${testWorkspacePath}/fixture.vue": [ + { + "newText": "bar", + "range": { + "end": { + "character": 28, + "line": 2, + }, + "start": { + "character": 25, + "line": 2, + }, + }, + }, + { + "newText": "bar", + "range": { + "end": { + "character": 8, + "line": 7, + }, + "start": { + "character": 5, + "line": 7, + }, + }, + }, + ], + }, + } + `); + expect( + await requestRename('fixture.vue', 'vue', ` + - - `, 'bar'); - await assertRenaming('fixture.vue', 'vue', ` - + + `, 'bar') + ).toMatchInlineSnapshot(` + { + "changes": { + "file://\${testWorkspacePath}/fixture.vue": [ + { + "newText": "bar", + "range": { + "end": { + "character": 20, + "line": 2, + }, + "start": { + "character": 17, + "line": 2, + }, + }, + }, + { + "newText": "bar", + "range": { + "end": { + "character": 8, + "line": 6, + }, + "start": { + "character": 5, + "line": 6, + }, + }, + }, + ], + }, + } + `); + expect( + await requestRename('fixture.vue', 'vue', ` + - - - - `, 'bar'); + + + + `, 'bar') + ).toMatchInlineSnapshot(` + { + "changes": { + "file://\${testWorkspacePath}/fixture.vue": [ + { + "newText": "bar", + "range": { + "end": { + "character": 34, + "line": 10, + }, + "start": { + "character": 31, + "line": 10, + }, + }, + }, + { + "newText": "bar", + "range": { + "end": { + "character": 28, + "line": 10, + }, + "start": { + "character": 25, + "line": 10, + }, + }, + }, + { + "newText": "bar", + "range": { + "end": { + "character": 28, + "line": 7, + }, + "start": { + "character": 25, + "line": 7, + }, + }, + }, + { + "newText": "bar", + "range": { + "end": { + "character": 13, + "line": 2, + }, + "start": { + "character": 10, + "line": 2, + }, + }, + }, + { + "newText": "bar", + "range": { + "end": { + "character": 35, + "line": 12, + }, + "start": { + "character": 32, + "line": 12, + }, + }, + }, + { + "newText": "bar", + "range": { + "end": { + "character": 29, + "line": 12, + }, + "start": { + "character": 26, + "line": 12, + }, + }, + }, + { + "newText": "bar", + "range": { + "end": { + "character": 35, + "line": 11, + }, + "start": { + "character": 32, + "line": 11, + }, + }, + }, + { + "newText": "bar", + "range": { + "end": { + "character": 29, + "line": 11, + }, + "start": { + "character": 26, + "line": 11, + }, + }, + }, + { + "newText": "bar", + "range": { + "end": { + "character": 29, + "line": 9, + }, + "start": { + "character": 26, + "line": 9, + }, + }, + }, + { + "newText": "bar", + "range": { + "end": { + "character": 29, + "line": 8, + }, + "start": { + "character": 26, + "line": 8, + }, + }, + }, + ], + }, + } + `); }); it('Component props', async () => { await ensureGlobalTypesHolder('tsconfigProject'); - await openDocument('tsconfigProject/foo.vue', 'vue', ` - + expect( + await prepareDocument('tsconfigProject/foo.vue', 'vue', ` + - + + `) + ).toMatchInlineSnapshot(` + FullTextDocument { + "_content": " + + + + ", + "_languageId": "vue", + "_lineOffsets": undefined, + "_uri": "file:///Users/johnsonchu/Desktop/volar/vue/test-workspace/tsconfigProject/foo.vue", + "_version": 1, + } `); - await assertRenaming('tsconfigProject/fixture.vue', 'vue', ` - + expect( + await requestRename('tsconfigProject/fixture.vue', 'vue', ` + - - `, 'cccDdd'); + + `, 'cccDdd') + ).toMatchInlineSnapshot(` + { + "changes": { + "file://\${testWorkspacePath}/tsconfigProject/fixture.vue": [ + { + "newText": "cccDdd", + "range": { + "end": { + "character": 24, + "line": 6, + }, + "start": { + "character": 18, + "line": 6, + }, + }, + }, + { + "newText": "cccDdd", + "range": { + "end": { + "character": 14, + "line": 2, + }, + "start": { + "character": 8, + "line": 2, + }, + }, + }, + ], + "file://\${testWorkspacePath}/tsconfigProject/foo.vue": [ + { + "newText": "cccDdd", + "range": { + "end": { + "character": 18, + "line": 3, + }, + "start": { + "character": 12, + "line": 3, + }, + }, + }, + { + "newText": "ccc-ddd", + "range": { + "end": { + "character": 19, + "line": 2, + }, + "start": { + "character": 12, + "line": 2, + }, + }, + }, + ], + }, + } + `); }); it('Component type props', async () => { await ensureGlobalTypesHolder('tsconfigProject'); - await openDocument('tsconfigProject/foo.vue', 'vue', ` + await prepareDocument('tsconfigProject/foo.vue', 'vue', `