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

fix(codefix): correct hover information for type signatures with callbacks #415

Merged
merged 1 commit into from
Dec 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/test/typescript-service-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
[
Expand Down Expand Up @@ -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<void> {
const result: Hover = await this.service
.textDocumentHover({
textDocument: {
uri: rootUri + 'local_callback.ts',
},
position: {
line: 0,
character: 36,
},
})
.reduce<Operation, Hover>(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<void> {
const result: Hover = await this.service
.textDocumentHover({
Expand Down
2 changes: 1 addition & 1 deletion src/typescript-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down