feat(code-editor): add editor state handling to CodeEditor component

This commit is contained in:
cfngc4594 2025-02-24 13:22:12 +08:00
parent 5cabdda667
commit c0d0021b6c

View File

@ -33,7 +33,7 @@ const Editor = dynamic(
export default function CodeEditor() {
const { resolvedTheme } = useTheme();
const { fontSize, lineHeight } = useCodeEditorOption();
const { language, languageClient, setLanguageClient } = useCodeEditorState();
const { language, languageClient, setEditor, setLanguageClient } = useCodeEditorState();
useEffect(() => {
if (languageClient) {
@ -44,7 +44,9 @@ export default function CodeEditor() {
const serverConfig = SUPPORTED_LANGUAGE_SERVERS.find((s) => s.id === language);
if (serverConfig) {
const lspUrl = `${serverConfig.protocol}://${serverConfig.hostname}${serverConfig.port ? `:${serverConfig.port}` : ''}${serverConfig.path || ''}`
const lspUrl = `${serverConfig.protocol}://${serverConfig.hostname}${
serverConfig.port ? `:${serverConfig.port}` : ""
}${serverConfig.path || ""}`;
const url = normalizeUrl(lspUrl);
const webSocket = new WebSocket(url);
@ -107,6 +109,9 @@ export default function CodeEditor() {
beforeMount={(monaco) => {
shikiToMonaco(highlighter, monaco);
}}
onMount={(editor, monaco) => {
setEditor(editor);
}}
// onValidate={(markers) => {
// markers.forEach((marker) => {
// console.log(marker.severity);