Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br><br>![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

Expand Down
98 changes: 8 additions & 90 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import {
WorkspaceEdit,
CodeActionKind,
Diagnostic,
DocumentDropOrPasteEditKind,
DocumentPasteEdit,
} from "vscode";
import { ThemeColor } from "vscode";

Expand All @@ -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;

Expand Down Expand Up @@ -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",
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down