Skip to content

Commit e45fb59

Browse files
authored
Merge pull request #1150 from nojaf/remove-paste-as
Remove registerDocumentPasteEditProvider
2 parents 3cf127d + 0fc9776 commit e45fb59

File tree

4 files changed

+21
-90
lines changed

4 files changed

+21
-90
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#### :bug: Bug fix
1616

17+
- 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
1718
- Only paste objects/arrays are JSON.t https://github.com/rescript-lang/rescript-vscode/pull/1148
1819

1920
## 1.68.0

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ Even if the pre-release channel seems too experimental to you, we still suggest
9393
| ReScript: Open the compiled JS file for this implementation file | Opens the compiled JS file for the current ReScript file. |
9494
| 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`. |
9595
| ReScript: Start Code Analyzer | This will start code analysis in the ReScript project of the file you run the command from. |
96+
| 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.<br><br>![Kapture 2025-11-11 at 09 31 40](https://github.com/user-attachments/assets/ae543a04-1a97-4202-aaf0-15bf6e55aa71) |
97+
| 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. |
9698

9799
## 🔨 Settings
98100

client/src/extension.ts

Lines changed: 8 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import {
1313
WorkspaceEdit,
1414
CodeActionKind,
1515
Diagnostic,
16-
DocumentDropOrPasteEditKind,
17-
DocumentPasteEdit,
1816
} from "vscode";
1917
import { ThemeColor } from "vscode";
2018

@@ -31,11 +29,8 @@ import {
3129
DiagnosticsResultCodeActionsMap,
3230
statusBarItem,
3331
} from "./commands/code_analysis";
34-
import {
35-
convertPlainTextToJsonT,
36-
buildInsertionText,
37-
} from "./commands/paste_as_rescript_json";
38-
import { convertPlainTextToRescriptJsx } from "./commands/paste_as_rescript_jsx";
32+
import { pasteAsRescriptJson } from "./commands/paste_as_rescript_json";
33+
import { pasteAsRescriptJsx } from "./commands/paste_as_rescript_jsx";
3934

4035
let client: LanguageClient;
4136

@@ -394,90 +389,13 @@ export function activate(context: ExtensionContext) {
394389
customCommands.dumpDebugRetrigger();
395390
});
396391

397-
const pasteJsonEditKind = DocumentDropOrPasteEditKind.Text.append(
398-
"rescript",
399-
"json",
400-
);
401-
const pasteJsxEditKind = DocumentDropOrPasteEditKind.Text.append(
402-
"rescript",
403-
"jsx",
404-
);
392+
commands.registerCommand("rescript-vscode.paste_as_rescript_json", () => {
393+
pasteAsRescriptJson();
394+
});
405395

406-
context.subscriptions.push(
407-
languages.registerDocumentPasteEditProvider(
408-
{ language: "rescript" },
409-
{
410-
async provideDocumentPasteEdits(
411-
document,
412-
ranges,
413-
dataTransfer,
414-
_context,
415-
token,
416-
) {
417-
if (token.isCancellationRequested) {
418-
return;
419-
}
420-
421-
const candidateItem =
422-
dataTransfer.get("text/plain") ??
423-
dataTransfer.get("application/json");
424-
if (!candidateItem) {
425-
return;
426-
}
427-
428-
const text = await candidateItem.asString();
429-
const targetRange = ranges[0];
430-
if (!targetRange) {
431-
return;
432-
}
433-
434-
const edits: DocumentPasteEdit[] = [];
435-
436-
const jsonConversion = convertPlainTextToJsonT(text);
437-
if (jsonConversion.kind === "success") {
438-
const insertText = buildInsertionText(
439-
document,
440-
targetRange.start,
441-
jsonConversion.formatted,
442-
);
443-
edits.push(
444-
new DocumentPasteEdit(
445-
insertText,
446-
"Paste as ReScript JSON.t",
447-
pasteJsonEditKind,
448-
),
449-
);
450-
}
451-
452-
const jsxConversion = convertPlainTextToRescriptJsx(text);
453-
if (jsxConversion.kind === "success") {
454-
const insertText = buildInsertionText(
455-
document,
456-
targetRange.start,
457-
jsxConversion.formatted,
458-
);
459-
edits.push(
460-
new DocumentPasteEdit(
461-
insertText,
462-
"Paste as ReScript JSX",
463-
pasteJsxEditKind,
464-
),
465-
);
466-
}
467-
468-
if (edits.length === 0) {
469-
return;
470-
}
471-
472-
return edits;
473-
},
474-
},
475-
{
476-
providedPasteEditKinds: [pasteJsonEditKind, pasteJsxEditKind],
477-
pasteMimeTypes: ["text/plain", "application/json"],
478-
},
479-
),
480-
);
396+
commands.registerCommand("rescript-vscode.paste_as_rescript_jsx", () => {
397+
pasteAsRescriptJsx();
398+
});
481399

482400
commands.registerCommand(
483401
"rescript-vscode.go_to_location",

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@
9292
{
9393
"command": "rescript-vscode.dump-server-state",
9494
"title": "DEBUG ReScript: Dump LSP Server State"
95+
},
96+
{
97+
"command": "rescript-vscode.paste_as_rescript_json",
98+
"category": "ReScript",
99+
"title": "Paste as ReScript JSON.t"
100+
},
101+
{
102+
"command": "rescript-vscode.paste_as_rescript_jsx",
103+
"category": "ReScript",
104+
"title": "Paste as ReScript JSX"
95105
}
96106
],
97107
"keybindings": [

0 commit comments

Comments
 (0)