Skip to content

Commit 8cb6739

Browse files
CsCherrYYdatho7561
authored andcommitted
add try-catch for potential errors
Signed-off-by: Shi Chen <[email protected]>
1 parent 7738468 commit 8cb6739

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/pasteEventHandler.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,19 @@ class PasteEditProvider implements DocumentPasteEditProvider {
8989
}
9090
};
9191

92-
const pasteResponse: PDocumentPasteEdit = await commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.HANDLE_PASTE_EVENT, JSON.stringify(pasteEventParams));
93-
94-
if (pasteResponse) {
95-
return {
96-
insertText: pasteResponse.insertText,
97-
additionalEdit: pasteResponse.additionalEdit ? this.languageClient.protocol2CodeConverter.asWorkspaceEdit(pasteResponse.additionalEdit) : undefined
98-
} as VDocumentPasteEdit;
92+
try {
93+
const pasteResponse: PDocumentPasteEdit = await commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.HANDLE_PASTE_EVENT, JSON.stringify(pasteEventParams));
94+
if (pasteResponse) {
95+
return {
96+
insertText: pasteResponse.insertText,
97+
additionalEdit: pasteResponse.additionalEdit ? this.languageClient.protocol2CodeConverter.asWorkspaceEdit(pasteResponse.additionalEdit) : undefined
98+
} as VDocumentPasteEdit;
99+
}
100+
} catch (e) {
101+
// Do nothing
99102
}
103+
// either the handler returns null or encounters problems, fall back to return undefined to let VS Code ignore this handler
104+
return undefined;
100105
}
101106

102107
}

0 commit comments

Comments
 (0)