From be4d21e3963ed4b5779b8110412839f55b10b26a Mon Sep 17 00:00:00 2001 From: nojaf Date: Tue, 25 Nov 2025 14:22:38 +0100 Subject: [PATCH 1/2] Remove registerDocumentPasteEditProvider --- README.md | 2 + client/src/extension.ts | 98 ++++------------------------------------- package.json | 10 +++++ 3 files changed, 20 insertions(+), 90 deletions(-) diff --git a/README.md b/README.md index 1227ab8ae..e897f08d4 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,8 @@ Even if the pre-release channel seems too experimental to you, we still suggest | ReScript: Open the compiled JS file for this implementation file | Opens the compiled JS file for the current ReScript file. | | ReScript: Switch implementation/interface | Switches between the implementation and interface file. If you're in a `.res` file, the command will open the corresponding `.resi` file (if it exists), and if you're in a `.resi` file the command will open the corresponding `.res` file. This can also be triggered with the keybinding `Alt+O`. | | ReScript: Start Code Analyzer | This will start code analysis in the ReScript project of the file you run the command from. | +| ReScript: Paste as ReScript JSON.t | Converts JSON from the clipboard and pastes it as ReScript `JSON.t` format. Automatically handles indentation based on cursor position.

![Kapture 2025-11-11 at 09 31 40](https://github.com/user-attachments/assets/ae543a04-1a97-4202-aaf0-15bf6e55aa71) | +| ReScript: Paste as ReScript JSX | Converts vanilla JSX from the clipboard and pastes it as ReScript JSX format. Automatically handles indentation based on cursor position. | ## 🔨 Settings diff --git a/client/src/extension.ts b/client/src/extension.ts index 89fe28b80..cd4fee0f8 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -13,8 +13,6 @@ import { WorkspaceEdit, CodeActionKind, Diagnostic, - DocumentDropOrPasteEditKind, - DocumentPasteEdit, } from "vscode"; import { ThemeColor } from "vscode"; @@ -31,11 +29,8 @@ import { DiagnosticsResultCodeActionsMap, statusBarItem, } from "./commands/code_analysis"; -import { - convertPlainTextToJsonT, - buildInsertionText, -} from "./commands/paste_as_rescript_json"; -import { convertPlainTextToRescriptJsx } from "./commands/paste_as_rescript_jsx"; +import { pasteAsRescriptJson } from "./commands/paste_as_rescript_json"; +import { pasteAsRescriptJsx } from "./commands/paste_as_rescript_jsx"; let client: LanguageClient; @@ -394,90 +389,13 @@ export function activate(context: ExtensionContext) { customCommands.dumpDebugRetrigger(); }); - const pasteJsonEditKind = DocumentDropOrPasteEditKind.Text.append( - "rescript", - "json", - ); - const pasteJsxEditKind = DocumentDropOrPasteEditKind.Text.append( - "rescript", - "jsx", - ); + commands.registerCommand("rescript-vscode.paste_as_rescript_json", () => { + pasteAsRescriptJson(); + }); - context.subscriptions.push( - languages.registerDocumentPasteEditProvider( - { language: "rescript" }, - { - async provideDocumentPasteEdits( - document, - ranges, - dataTransfer, - _context, - token, - ) { - if (token.isCancellationRequested) { - return; - } - - const candidateItem = - dataTransfer.get("text/plain") ?? - dataTransfer.get("application/json"); - if (!candidateItem) { - return; - } - - const text = await candidateItem.asString(); - const targetRange = ranges[0]; - if (!targetRange) { - return; - } - - const edits: DocumentPasteEdit[] = []; - - const jsonConversion = convertPlainTextToJsonT(text); - if (jsonConversion.kind === "success") { - const insertText = buildInsertionText( - document, - targetRange.start, - jsonConversion.formatted, - ); - edits.push( - new DocumentPasteEdit( - insertText, - "Paste as ReScript JSON.t", - pasteJsonEditKind, - ), - ); - } - - const jsxConversion = convertPlainTextToRescriptJsx(text); - if (jsxConversion.kind === "success") { - const insertText = buildInsertionText( - document, - targetRange.start, - jsxConversion.formatted, - ); - edits.push( - new DocumentPasteEdit( - insertText, - "Paste as ReScript JSX", - pasteJsxEditKind, - ), - ); - } - - if (edits.length === 0) { - return; - } - - return edits; - }, - }, - { - providedPasteEditKinds: [pasteJsonEditKind, pasteJsxEditKind], - pasteMimeTypes: ["text/plain", "application/json"], - }, - ), - ); + commands.registerCommand("rescript-vscode.paste_as_rescript_jsx", () => { + pasteAsRescriptJsx(); + }); commands.registerCommand( "rescript-vscode.go_to_location", diff --git a/package.json b/package.json index 2e8c7647b..b531cde09 100644 --- a/package.json +++ b/package.json @@ -92,6 +92,16 @@ { "command": "rescript-vscode.dump-server-state", "title": "DEBUG ReScript: Dump LSP Server State" + }, + { + "command": "rescript-vscode.paste_as_rescript_json", + "category": "ReScript", + "title": "Paste as ReScript JSON.t" + }, + { + "command": "rescript-vscode.paste_as_rescript_jsx", + "category": "ReScript", + "title": "Paste as ReScript JSX" } ], "keybindings": [ From 0fc9776fd1117044ea3f59697eafa47c4ae5ff55 Mon Sep 17 00:00:00 2001 From: nojaf Date: Tue, 25 Nov 2025 14:25:45 +0100 Subject: [PATCH 2/2] Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 538950df9..238c66d83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ #### :bug: Bug fix +- Remove automatic paste provider that interfered with default paste behavior. Paste as ReScript JSON/JSX commands are now explicit commands only. https://github.com/rescript-lang/rescript-vscode/pull/1150 - Only paste objects/arrays are JSON.t https://github.com/rescript-lang/rescript-vscode/pull/1148 ## 1.68.0