Skip to content

Commit 9a3845e

Browse files
committed
Add test for onCompletionResolve
1 parent a560611 commit 9a3845e

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

server/src/__tests__/server.test.ts

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ describe('server', () => {
524524

525525
const onCompletion = connection.onCompletion.mock.calls[0][0]
526526

527-
const result: any = await onCompletion(
527+
const result = await onCompletion(
528528
{
529529
textDocument: {
530530
uri: FIXTURE_URI.SOURCING,
@@ -540,9 +540,6 @@ describe('server', () => {
540540
)
541541

542542
// they are all variables
543-
expect(Array.from(new Set(result.map((item: any) => item.kind)))).toEqual([
544-
LSP.CompletionItemKind.Variable,
545-
])
546543
expect(result).toMatchInlineSnapshot(`
547544
Array [
548545
Object {
@@ -603,7 +600,48 @@ describe('server', () => {
603600
})
604601

605602
describe('onCompletionResolve', () => {
606-
// FIXME
603+
it('resolves documentation for buitins', async () => {
604+
const { connection } = await initializeServer({ rootPath: REPO_ROOT_FOLDER })
605+
606+
const onCompletionResolve = connection.onCompletionResolve.mock.calls[0][0]
607+
608+
const item = {
609+
data: {
610+
type: CompletionItemDataType.Builtin,
611+
},
612+
kind: LSP.CompletionItemKind.Function,
613+
label: 'echo',
614+
}
615+
const result = await onCompletionResolve(item, {} as any)
616+
617+
expect(result).toEqual({
618+
...item,
619+
documentation: {
620+
kind: 'markdown',
621+
value: expect.stringContaining('Write arguments to the standard output'),
622+
},
623+
})
624+
})
625+
626+
it('ignores unknown items', async () => {
627+
const { connection } = await initializeServer({ rootPath: REPO_ROOT_FOLDER })
628+
629+
const onCompletionResolve = connection.onCompletionResolve.mock.calls[0][0]
630+
631+
const item = {
632+
data: {
633+
type: CompletionItemDataType.Symbol,
634+
},
635+
kind: LSP.CompletionItemKind.Function,
636+
label: 'foobar',
637+
}
638+
const result = await onCompletionResolve(item, {} as any)
639+
640+
expect(result).toEqual({
641+
...item,
642+
documentation: undefined,
643+
})
644+
})
607645
})
608646

609647
describe('onDefinition', () => {

0 commit comments

Comments
 (0)