fix: resolve DocumentDropOrPasteEditKind undefined error in older VS Code versions
Fixes a critical runtime error that prevented tinymist from loading in Cursor and other editors using older VS Code versions.
Problem
The extension was failing with TypeError: Cannot read properties of undefined (reading 'Empty') in drop-paste.def.ts when running on VS Code versions prior to 1.97.0 (including Cursor). This occurred because the code was directly accessing vscode.DocumentDropOrPasteEditKind.Empty at module import time, before any runtime compatibility checks could execute.
// This failed in older VS Code versions
export const typstPasteLinkEditKind = vscode.DocumentDropOrPasteEditKind.Empty.append("typst", "link");
Solution
Implemented lazy evaluation of DocumentDropOrPasteEditKind constants using getter functions:
// New approach with runtime detection
function hasDocumentDropOrPasteEditKind(): boolean {
return typeof (vscode as any).DocumentDropOrPasteEditKind !== "undefined";
}
export function getTypstPasteLinkEditKind() {
return getEditKinds().typstPasteLinkEditKind; // Returns null for older versions
}
Changes Made
- Lazy Evaluation: Converted immediate constant evaluation to lazy getter functions that check API availability at runtime
-
Graceful Degradation: Return
nullvalues for edit kinds when the API is unavailable, allowing the existing paste API checks to work correctly - Caching: Added a caching layer to avoid repeated computation of edit kinds
-
Updated References: Modified all usage sites in
drop-paste.tsto use the new getter functions
Result
- ✅ Cursor and other older VS Code versions now load tinymist without errors
- ✅ Full paste API functionality preserved for VS Code 1.97+
- ✅ Graceful degradation for older versions (paste features disabled with warning)
- ✅ No behavioral changes for modern VS Code installations
This enables Cursor users to access tinymist's language server features while maintaining full functionality for users with newer VS Code versions.
Fixes #1657.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.
Fix error in editors/vscode/src/features/drop-paste.def.ts:
TypeError: Cannot read properties of undefined (reading 'Empty')
TypeError: Cannot read properties of undefined (reading 'Empty')
Fix error in editors/vscode/src/features/drop-paste.def.ts:
TypeError: Cannot read properties of undefined (reading 'Empty')
TypeError: Cannot read properties of undefined (reading 'Empty')
Fix error in editors/vscode/src/features/drop-paste.def.ts:
TypeError: Cannot read properties of undefined (reading 'Empty')
...
Fixed the TypeError in drop-paste.def.ts by implementing lazy evaluation of DocumentDropOrPasteEditKind constants. The error was caused by accessing vscode.DocumentDropOrPasteEditKind.Empty when DocumentDropOrPasteEditKind is undefined in older VS Code versions like Cursor. The fix converts the problematic constants to getter functions that safely handle missing APIs. Commit: 9ce7a9b
Fix error in editors/vscode/src/features/drop-paste.def.ts:
TypeError: Cannot read properties of undefined (reading 'Empty')
...
Fixed the TypeError in drop-paste.def.ts by implementing lazy evaluation of DocumentDropOrPasteEditKind constants. The error occurred when accessing .Empty on undefined DocumentDropOrPasteEditKind in older VS Code versions. The solution uses getter functions that gracefully handle missing APIs. Commit: 9ce7a9b