Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@
"type": "string",
"default": "node_modules/babel-plugin-react-compiler",
"description": "Path to the babel-plugin-react-compiler in your project. By default it's 'node_modules/babel-plugin-react-compiler'"
},
"reactCompilerMarker.errorEmoji": {
"type": "string",
"nullable": true,
"default": "🚫",
"description": "Emoji to display next to components that failed to be memoized"
},
"reactCompilerMarker.successEmoji": {
"type": "string",
"nullable": true,
"default": "✨",
"description": "Emoji to display next to components that were successfully memoized"
}
}
}
Expand Down
42 changes: 31 additions & 11 deletions src/decorations.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import * as vscode from "vscode";
import { checkReactCompiler, LoggerEvent } from "./checkReactCompiler";

let successDecoration: vscode.TextEditorDecorationType;
let errorDecoration: vscode.TextEditorDecorationType;
let currentSuccessEmoji: string | null | undefined;
let currentErrorEmoji: string | null | undefined;

function createDecorationType(
contentText: string
): vscode.TextEditorDecorationType {
Expand Down Expand Up @@ -91,14 +96,14 @@ async function updateDecorations(
if (log.kind === "CompileSuccess") {
// Use hoverMessage for displaying Markdown tooltips
hoverMessage.appendMarkdown(
"✨ This component has been auto-memoized by React Compiler.\n\n"
`${currentSuccessEmoji} This component has been auto-memoized by React Compiler.\n\n`
);
hoverMessage.appendMarkdown(
`**[Preview compiled output 📄](command:react-compiler-marker.previewCompiled)**`
);
} else {
hoverMessage.appendMarkdown(
"**🚫 This component hasn't been memoized by React Compiler.**\n\n"
`**${currentErrorEmoji} This component hasn't been memoized by React Compiler.**\n\n`
);

const { startLine, endLine, startChar, endChar, reason, description } =
Expand Down Expand Up @@ -148,9 +153,28 @@ async function updateDecorations(
editor.setDecorations(decorationType, decorations);
}

// Decorations for successful and failed compilations
const magicSparksDecoration = createDecorationType(" ✨");
const blockIndicatorDecoration = createDecorationType(" 🚫");
// Function to load initial decorations
export function loadDecorations() {
const config = vscode.workspace.getConfiguration("reactCompilerMarker");
currentSuccessEmoji = config.get<string | null>("successEmoji");
currentErrorEmoji = config.get<string | null>("errorEmoji");

if (successDecoration) {
successDecoration.dispose();
}
if (errorDecoration) {
errorDecoration.dispose();
}

successDecoration = createDecorationType(
currentSuccessEmoji ? " " + currentSuccessEmoji : ""
);
errorDecoration = createDecorationType(
currentErrorEmoji ? " " + currentErrorEmoji : ""
);
}

loadDecorations();

// Function to update decorations dynamically
async function updateDecorationsForEditor(editor: vscode.TextEditor) {
Expand All @@ -165,12 +189,8 @@ async function updateDecorationsForEditor(editor: vscode.TextEditor) {
);

// Update decorations for successful and failed compilations
await updateDecorations(
editor,
magicSparksDecoration,
successfulCompilations
);
await updateDecorations(editor, blockIndicatorDecoration, failedCompilations);
await updateDecorations(editor, successDecoration, successfulCompilations);
await updateDecorations(editor, errorDecoration, failedCompilations);
}

export { createDecorationType, updateDecorations, updateDecorationsForEditor };
13 changes: 12 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from "vscode";
import { updateDecorationsForEditor } from "./decorations";
import { updateDecorationsForEditor, loadDecorations } from "./decorations";
import { getThrottledFunction, isVSCode } from "./utils";
import { logError, logMessage } from "./logger";
import { getCompiledOutput } from "./checkReactCompiler";
Expand Down Expand Up @@ -304,5 +304,16 @@ function registerListeners(
}
});

// Listener for emoji config changes
vscode.workspace.onDidChangeConfiguration((event) => {
if (event.affectsConfiguration("reactCompilerMarker")) {
loadDecorations();
const editor = vscode.window.activeTextEditor;
if (getIsActivated() && editor) {
throttledUpdateDecorations(editor);
}
}
});

logMessage("React Compiler Marker ✨: Event listeners registered.");
}