-
-
Notifications
You must be signed in to change notification settings - Fork 416
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
705cd4b
commit c2e54b9
Showing
11 changed files
with
150 additions
and
359 deletions.
There are no files selected for viewing
124 changes: 0 additions & 124 deletions
124
packages/language-server/tests/__snapshots__/completions.spec.ts.snap
This file was deleted.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
packages/language-server/tests/__snapshots__/definitions.spec.ts.snap
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,61 @@ | ||
// 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, | ||
}, | ||
} | ||
`; |
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,89 @@ | ||
import { Location, TextDocument } from '@volar/language-server'; | ||
import * as path from 'path'; | ||
import { afterEach, describe, expect, it } from 'vitest'; | ||
import { URI } from 'vscode-uri'; | ||
import { getLanguageServer, testWorkspacePath } from './server.js'; | ||
|
||
describe('Definitions', async () => { | ||
|
||
it('TS to vue', async () => { | ||
await ensureGlobalTypesHolder('tsconfigProject'); | ||
await assertDefinition('tsconfigProject/fixture1.ts', 'typescript', `import C|omponent from './empty.vue';`); | ||
await assertDefinition('tsconfigProject/fixture2.ts', 'typescript', `import Component from '|./empty.vue';`); | ||
}); | ||
|
||
it('Alias path', async () => { | ||
await ensureGlobalTypesHolder('tsconfigProject'); | ||
await openDocument('tsconfigProject/foo.ts', 'typescript', `export const foo = 'foo';`); | ||
await assertDefinition('tsconfigProject/fixture.vue', 'vue', ` | ||
<script setup lang="ts"> | ||
import { foo| } from '@/foo'; | ||
</script> | ||
`); | ||
}); | ||
|
||
it('#2600', async () => { | ||
await ensureGlobalTypesHolder('tsconfigProject'); | ||
await openDocument('tsconfigProject/foo.vue', 'vue', ` | ||
<template> | ||
<h1>{{ msg }}</h1> | ||
</template> | ||
<script lang="ts"> | ||
export default defineProps<{ msg: string }>() | ||
</script> | ||
`); | ||
await assertDefinition('tsconfigProject/fixture.vue', 'vue', ` | ||
<script setup lang="ts"> | ||
import Foo from '|@/foo.vue'; | ||
</script> | ||
`); | ||
}); | ||
|
||
const openedDocuments: TextDocument[] = []; | ||
|
||
afterEach(async () => { | ||
const server = await getLanguageServer(); | ||
for (const document of openedDocuments) { | ||
await server.closeTextDocument(document.uri); | ||
} | ||
openedDocuments.length = 0; | ||
}); | ||
|
||
/** | ||
* @deprecated Remove this when #4717 fixed. | ||
*/ | ||
async function ensureGlobalTypesHolder(folderName: string) { | ||
const document = await openDocument(`${folderName}/globalTypesHolder.vue`, 'vue', ''); | ||
const server = await getLanguageServer(); | ||
await server.sendDocumentDiagnosticRequest(document.uri); | ||
} | ||
|
||
async function assertDefinition(fileName: string, languageId: string, content: string) { | ||
const offset = content.indexOf('|'); | ||
content = content.slice(0, offset) + content.slice(offset + 1); | ||
|
||
const server = await getLanguageServer(); | ||
let document = await openDocument(fileName, languageId, content); | ||
|
||
const position = document.positionAt(offset); | ||
const definition = await server.sendDefinitionRequest(document.uri, position) as Location[] | null; | ||
expect(definition).toBeDefined(); | ||
expect(definition!.length).greaterThan(0); | ||
|
||
for (const loc of definition!) { | ||
expect(path.relative(testWorkspacePath, URI.parse(loc.uri).fsPath)).toMatchSnapshot(); | ||
expect(loc.range).toMatchSnapshot(); | ||
} | ||
} | ||
|
||
async function openDocument(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); | ||
if (openedDocuments.every(d => d.uri !== document.uri)) { | ||
openedDocuments.push(document); | ||
} | ||
return document; | ||
} | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.