Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 71f103d

Browse files
Dan Rosénfelixfbecker
Dan Rosén
authored andcommitted
fix(hover): correct hover information for type signatures with callbacks (#415)
Fixes #413
1 parent d1f55da commit 71f103d

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/test/typescript-service-helpers.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ export function describeTypeScriptService(
124124
[rootUri + 'foo/b.ts', ['/* This is class Foo */', 'export class Foo {}'].join('\n')],
125125
[rootUri + 'foo/c.ts', 'import {Foo} from "./b";'],
126126
[rootUri + 'd.ts', ['export interface I {', ' target: string;', '}'].join('\n')],
127+
[
128+
rootUri + 'local_callback.ts',
129+
'function local(): void { function act(handle: () => void): void { handle() } }',
130+
],
127131
[
128132
rootUri + 'e.ts',
129133
[
@@ -322,6 +326,38 @@ export function describeTypeScriptService(
322326
contents: [{ language: 'typescript', value: 'const abc: 1' }, '**const**'],
323327
})
324328
})
329+
specify('local function with callback argument', async function(
330+
this: TestContext & ITestCallbackContext
331+
): Promise<void> {
332+
const result: Hover = await this.service
333+
.textDocumentHover({
334+
textDocument: {
335+
uri: rootUri + 'local_callback.ts',
336+
},
337+
position: {
338+
line: 0,
339+
character: 36,
340+
},
341+
})
342+
.reduce<Operation, Hover>(applyReducer, null as any)
343+
.toPromise()
344+
assert.deepEqual(result, {
345+
range: {
346+
start: {
347+
line: 0,
348+
character: 34,
349+
},
350+
end: {
351+
line: 0,
352+
character: 37,
353+
},
354+
},
355+
contents: [
356+
{ language: 'typescript', value: 'act(handle: () => void): void' },
357+
'**local function**',
358+
],
359+
})
360+
})
325361
specify('in other file', async function(this: TestContext & ITestCallbackContext): Promise<void> {
326362
const result: Hover = await this.service
327363
.textDocumentHover({

src/typescript-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ export class TypeScriptService {
609609
}
610610
const contents: (MarkedString | string)[] = []
611611
// Add declaration without the kind
612-
const declaration = ts.displayPartsToString(info.displayParts).replace(/^\(.+\)\s+/, '')
612+
const declaration = ts.displayPartsToString(info.displayParts).replace(/^\(.+?\)\s+/, '')
613613
contents.push({ language: 'typescript', value: declaration })
614614
// Add kind with modifiers, e.g. "method (private, ststic)", "class (exported)"
615615
if (info.kind) {

0 commit comments

Comments
 (0)