diff --git a/src/test/typescript-service-helpers.ts b/src/test/typescript-service-helpers.ts index 3bc7bbc4a..01813a0fc 100644 --- a/src/test/typescript-service-helpers.ts +++ b/src/test/typescript-service-helpers.ts @@ -124,6 +124,10 @@ export function describeTypeScriptService( [rootUri + 'foo/b.ts', ['/* This is class Foo */', 'export class Foo {}'].join('\n')], [rootUri + 'foo/c.ts', 'import {Foo} from "./b";'], [rootUri + 'd.ts', ['export interface I {', ' target: string;', '}'].join('\n')], + [ + rootUri + 'local_callback.ts', + 'function local(): void { function act(handle: () => void): void { handle() } }', + ], [ rootUri + 'e.ts', [ @@ -322,6 +326,38 @@ export function describeTypeScriptService( contents: [{ language: 'typescript', value: 'const abc: 1' }, '**const**'], }) }) + specify('local function with callback argument', async function( + this: TestContext & ITestCallbackContext + ): Promise { + const result: Hover = await this.service + .textDocumentHover({ + textDocument: { + uri: rootUri + 'local_callback.ts', + }, + position: { + line: 0, + character: 36, + }, + }) + .reduce(applyReducer, null as any) + .toPromise() + assert.deepEqual(result, { + range: { + start: { + line: 0, + character: 34, + }, + end: { + line: 0, + character: 37, + }, + }, + contents: [ + { language: 'typescript', value: 'act(handle: () => void): void' }, + '**local function**', + ], + }) + }) specify('in other file', async function(this: TestContext & ITestCallbackContext): Promise { const result: Hover = await this.service .textDocumentHover({ diff --git a/src/typescript-service.ts b/src/typescript-service.ts index 69ccca3a5..a81bd068a 100644 --- a/src/typescript-service.ts +++ b/src/typescript-service.ts @@ -609,7 +609,7 @@ export class TypeScriptService { } const contents: (MarkedString | string)[] = [] // Add declaration without the kind - const declaration = ts.displayPartsToString(info.displayParts).replace(/^\(.+\)\s+/, '') + const declaration = ts.displayPartsToString(info.displayParts).replace(/^\(.+?\)\s+/, '') contents.push({ language: 'typescript', value: declaration }) // Add kind with modifiers, e.g. "method (private, ststic)", "class (exported)" if (info.kind) {