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
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.
 |
+| 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": [