-
-
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
117ce52
commit 1c864d3
Showing
16 changed files
with
352 additions
and
346 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
80 changes: 80 additions & 0 deletions
80
packages/language-server/tests/__snapshots__/inlayHints.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,80 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`Definitions > Destructured props 1`] = ` | ||
" | ||
<script setup lang="ts"> | ||
import { watch } from 'vue'; | ||
const { foo, bar, ...props } = defineProps<{ | ||
foo: string; | ||
bar: string; | ||
baz: string; | ||
}>(); | ||
type foo = foo[string] & typeof [props.]foo; | ||
interface foo extends (typeof [props.]foo) { | ||
foo: string; | ||
foo(foo: string): void; | ||
foo: (foo: string) => void; | ||
} | ||
const obj = { | ||
foo: [props.]foo, | ||
[[props.]foo]: '', | ||
foo[: props.foo], | ||
foo(foo) { }, | ||
foo: function (foo) { }, | ||
get bar() { return this.foo; }, | ||
set bar(val) { this.foo = val; } | ||
}; | ||
function func(foo) { } | ||
class cls { | ||
foo: string = [props.]foo; | ||
constructor(foo) { } | ||
} | ||
for (const char of [props.]foo) { } | ||
try { } catch (foo) { } | ||
watch(() => [props.]foo, (foo) => { | ||
console.log(foo, [props.]bar, props.baz); | ||
}); | ||
</script> | ||
" | ||
`; | ||
|
||
exports[`Definitions > Inline handler leading 1`] = ` | ||
" | ||
<script setup lang="ts"> | ||
let a = 0; | ||
</script> | ||
<template> | ||
<div @click="[$event =>]a = 1"></div> | ||
</template> | ||
" | ||
`; | ||
exports[`Definitions > Missing props 1`] = ` | ||
" | ||
<script setup lang="ts"> | ||
import Foo from './foo.vue'; | ||
</script> | ||
<template> | ||
<Foo[foo!]></Foo> | ||
</template> | ||
" | ||
`; | ||
|
||
exports[`Definitions > Options wrapper 1`] = ` | ||
" | ||
<script> | ||
export default [(await import('vue')).defineComponent(]{}[)]; | ||
</script> | ||
" | ||
`; |
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,143 @@ | ||
import { TextDocument } from '@volar/language-server'; | ||
import { afterEach, describe, expect, it } from 'vitest'; | ||
import { URI } from 'vscode-uri'; | ||
import { getLanguageServer, testWorkspacePath } from './server.js'; | ||
|
||
describe('Definitions', async () => { | ||
|
||
it('Inline handler leading', async () => { | ||
await ensureGlobalTypesHolder('tsconfigProject'); | ||
await assertInlayHints('tsconfigProject/fixture.vue', 'vue', ` | ||
<script setup lang="ts"> | ||
let a = 0; | ||
</script> | ||
<template> | ||
<div @click="a = 1"></div> | ||
</template> | ||
`); | ||
}); | ||
|
||
it('Missing props', async () => { | ||
await ensureGlobalTypesHolder('tsconfigProject'); | ||
openDocument('tsconfigProject/foo.vue', 'vue', ` | ||
<script setup lang="ts"> | ||
defineProps<{ | ||
foo: number; | ||
}>(); | ||
</script> | ||
`); | ||
await assertInlayHints('tsconfigProject/fixture.vue', 'vue', ` | ||
<script setup lang="ts"> | ||
import Foo from './foo.vue'; | ||
</script> | ||
<template> | ||
<Foo></Foo> | ||
</template> | ||
`); | ||
}); | ||
|
||
it('Options wrapper', async () => { | ||
await ensureGlobalTypesHolder('tsconfigProject'); | ||
await assertInlayHints('tsconfigProject/fixture.vue', 'vue', ` | ||
<script> | ||
export default {}; | ||
</script> | ||
`); | ||
}); | ||
|
||
it('Destructured props', async () => { | ||
await ensureGlobalTypesHolder('tsconfigProject'); | ||
await assertInlayHints('tsconfigProject/fixture.vue', 'vue', ` | ||
<script setup lang="ts"> | ||
import { watch } from 'vue'; | ||
const { foo, bar, ...props } = defineProps<{ | ||
foo: string; | ||
bar: string; | ||
baz: string; | ||
}>(); | ||
type foo = foo[string] & typeof foo; | ||
interface foo extends (typeof foo) { | ||
foo: string; | ||
foo(foo: string): void; | ||
foo: (foo: string) => void; | ||
} | ||
const obj = { | ||
foo: foo, | ||
[foo]: '', | ||
foo, | ||
foo(foo) { }, | ||
foo: function (foo) { }, | ||
get bar() { return this.foo; }, | ||
set bar(val) { this.foo = val; } | ||
}; | ||
function func(foo) { } | ||
class cls { | ||
foo: string = foo; | ||
constructor(foo) { } | ||
} | ||
for (const char of foo) { } | ||
try { } catch (foo) { } | ||
watch(() => foo, (foo) => { | ||
console.log(foo, bar, props.baz); | ||
}); | ||
</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 assertInlayHints(fileName: string, languageId: string, content: string) { | ||
const server = await getLanguageServer(); | ||
let document = await openDocument(fileName, languageId, content); | ||
|
||
const inlayHints = await server.sendInlayHintRequest(document.uri, { start: document.positionAt(0), end: document.positionAt(content.length) }); | ||
expect(inlayHints).toBeDefined(); | ||
expect(inlayHints!.length).greaterThan(0); | ||
|
||
let text = document.getText(); | ||
for (const hint of inlayHints!.sort((a, b) => document.offsetAt(b.position) - document.offsetAt(a.position))) { | ||
const offset = document.offsetAt(hint.position); | ||
text = text.slice(0, offset) + '[' + hint.label + ']' + text.slice(offset); | ||
} | ||
|
||
expect(text).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 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 was deleted.
Oops, something went wrong.
Oops, something went wrong.