Skip to content

Commit bb609cd

Browse files
committed
feat(special-command): New command: copyFullType to copy title from hover to your clipboard without truncation!
1 parent 7ed2c15 commit bb609cd

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
"command": "insertNameOfCompletion",
5656
"title": "Insert Name of Completion",
5757
"category": "TS Essentials"
58+
},
59+
{
60+
"command": "copyFullType",
61+
"title": "Copy Full Type"
5862
}
5963
],
6064
"keybindings": [

typescript/src/ipcTypes.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// should-not contain other typescript/* imports that use globals as is imported in extension code (src/)
22

3-
export const passthroughExposedApiCommands = ['getNodePath', 'getSpanOfEnclosingComment', 'getNodeAtPosition'] as const
3+
export const passthroughExposedApiCommands = ['getNodePath', 'getSpanOfEnclosingComment', 'getNodeAtPosition', 'getFullType'] as const
44

55
export const triggerCharacterCommands = [
66
...passthroughExposedApiCommands,
@@ -82,6 +82,9 @@ export type RequestResponseTypes = {
8282
name: string
8383
range?: TsRange
8484
}
85+
getFullType: {
86+
text: string
87+
}
8588
}
8689

8790
// INPUT

typescript/src/specialCommands/handle.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,15 @@ export default (
254254
if (specialCommand === 'getLastResolvedCompletion') {
255255
return lastResolvedCompletion.value
256256
}
257+
if (specialCommand === 'getFullType') {
258+
const node = findChildContainingExactPosition(sourceFile, position)
259+
if (!node) return
260+
const checker = languageService.getProgram()!.getTypeChecker()!
261+
const type = checker.getTypeAtLocation(node)
262+
return {
263+
text: checker.typeToString(type, undefined, ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.NoTypeReduction),
264+
}
265+
}
257266

258267
return null
259268
}

0 commit comments

Comments
 (0)