亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將 monaco-editor 和 monaco-languageclient 包裝為 React

將 monaco-editor 和 monaco-languageclient 包裝為 React

慕少森 2021-06-29 17:43:25
我需要創建一個 React 組件,它集成了 Microsoft 的 Monaco 編輯器和 TypeFox 的 monaco-languageclient。目標是讓該組件能夠通過語言服務器協議與語言服務器進行通信。import React, { useEffect, useRef, useState } from 'react'import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';import _ from 'lodash'import { listen } from 'vscode-ws-jsonrpc';import {  CloseAction,  createConnection,  ErrorAction,  MonacoLanguageClient,  MonacoServices} from 'monaco-languageclient';import normalizeUrl from 'normalize-url';import ReconnectingWebSocket from 'reconnecting-websocket';function createLanguageClient(connection) {  return new MonacoLanguageClient({    name: "Sample Language Client",    clientOptions: {      // use a language id as a document selector      documentSelector: [ 'json' ],      // disable the default error handler      errorHandler: {        error: () => ErrorAction.Continue,        closed: () => CloseAction.DoNotRestart      }    },    // create a language client connection from the JSON RPC connection on demand    connectionProvider: {      get: (errorHandler, closeHandler) => {        return Promise.resolve(createConnection(connection, errorHandler, closeHandler))      }    }  });}function createUrl(path) {  // const protocol = 'ws';  return normalizeUrl("ws://localhost:3000/sampleServer")  // return normalizeUrl(`${protocol}://${location.host}${location.pathname}${path}`);}function createWebSocket(url) {  const socketOptions = {    maxReconnectionDelay: 10000,    minReconnectionDelay: 1000,    reconnectionDelayGrowFactor: 1.3,    connectionTimeout: 10000,    maxRetries: Infinity,    debug: false  };  return new ReconnectingWebSocket(url, undefined, socketOptions);}
查看完整描述

3 回答

  • 3 回答
  • 0 關注
  • 680 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號