Skip to content

Commit 7e17ba2

Browse files
committed
fix(playground): code completion
1 parent 601a729 commit 7e17ba2

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

packages/playground/src/app/components/Editor.tsx

+16-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ import { useEffect, useRef, useState } from "react";
55
import { shikiToMonaco } from "@shikijs/monaco";
66
import { createHighlighter } from "shiki";
77

8+
const ReactSource = require.context(
9+
"!!raw-loader!../../../node_modules/@types/react",
10+
true,
11+
/^\.\/(.*\.d\.ts|package.json)$/,
12+
);
13+
814
const CCCSource = require.context(
915
"!!raw-loader!../../../../",
1016
true,
@@ -78,7 +84,7 @@ export function Editor({
7884
<div className="relative h-full w-full">
7985
<MonacoEditor
8086
className="h-[60vh] w-full lg:h-auto"
81-
defaultLanguage="tsx"
87+
defaultLanguage="typescript"
8288
defaultPath="/index.tsx"
8389
options={{
8490
padding: { top: 20 },
@@ -105,6 +111,13 @@ export function Editor({
105111
],
106112
});
107113

114+
ReactSource.keys().forEach((key: string) => {
115+
monaco.languages.typescript.typescriptDefaults.addExtraLib(
116+
ReactSource(key).default,
117+
"file:///node_modules/@types/react/" + key.replace("./", ""),
118+
);
119+
});
120+
108121
CCCSource.keys().forEach((key: string) => {
109122
monaco.languages.typescript.typescriptDefaults.addExtraLib(
110123
CCCSource(key).default,
@@ -116,10 +129,10 @@ export function Editor({
116129
"file:///node_modules/@ckb-ccc/playground/index.d.ts",
117130
);
118131

119-
monaco.languages.register({ id: "tsx" });
132+
monaco.languages.register({ id: "typescript" });
120133
createHighlighter({
121134
themes: ["github-dark"],
122-
langs: ["tsx"],
135+
langs: ["typescript"],
123136
}).then((highlighter) => {
124137
shikiToMonaco(highlighter, monaco);
125138
});

0 commit comments

Comments
 (0)