Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connection.onDidOpenTextDocument is not a function #198

Open
rick-chou opened this issue May 24, 2023 · 0 comments
Open

connection.onDidOpenTextDocument is not a function #198

rick-chou opened this issue May 24, 2023 · 0 comments
Assignees

Comments

@rick-chou
Copy link

I tried to start the monaco-editor project under example but failed, So I rewrote the code with this repo https://github.com/TypeFox/monaco-languageclient

When I start the project, I get this error

Uncaught Exception:  TypeError: connection.onDidOpenTextDocument is not a function
TypeError: connection.onDidOpenTextDocument is not a function
    at TextDocuments.listen (/Users/rick.zhou/Desktop/monaco-lsp-demo/sql-language-server/node_modules/sql-language-server/node_modules/vscode-languageserver/lib/common/textDocuments.js:115:20)
    at createServerWithConnection (/Users/rick.zhou/Desktop/monaco-lsp-demo/sql-language-server/node_modules/sql-language-server/src/createServer.ts:44:13)
    at launch (file:///Users/rick.zhou/Desktop/monaco-lsp-demo/sql-language-server/launcher.ts:14:28)
    at file:///Users/rick.zhou/Desktop/monaco-lsp-demo/sql-language-server/main.ts:58:9
    at WebSocketServer.completeUpgrade (/Users/rick.zhou/Desktop/monaco-lsp-demo/sql-language-server/node_modules/ws/lib/websocket-server.js:431:5)
    at WebSocketServer.handleUpgrade (/Users/rick.zhou/Desktop/monaco-lsp-demo/sql-language-server/node_modules/ws/lib/websocket-server.js:339:10)
    at Server.<anonymous> (file:///Users/rick.zhou/Desktop/monaco-lsp-demo/sql-language-server/main.ts:39:9)
    at Server.emit (node:events:527:28)
    at Server.emit (node:domain:475:12)
    at onParserExecuteCommon (node:_http_server:732:14)

env

// server
    "sql-language-server": "^1.5.1",
    "vscode-languageserver": "^8.1.0",
    "vscode-ws-jsonrpc": "^3.0.0",

// frontend
    "monaco-editor": "^0.37.1",
    "monaco-editor-workers": "^0.37.0",
    "monaco-languageclient": "^6.0.1",
    "normalize-url": "^8.0.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "vscode": "npm:@codingame/monaco-vscode-api@^1.78.6",
    "vscode-languageclient": "^8.1.0",
    "vscode-ws-jsonrpc": "^3.0.0"
import { createServerWithConnection } from 'sql-language-server';
import { IWebSocket, WebSocketMessageReader, WebSocketMessageWriter } from 'vscode-ws-jsonrpc';
import { createConnection } from 'vscode-ws-jsonrpc/server';

export function launch(socket: IWebSocket) {
  const reader = new WebSocketMessageReader(socket);
  const writer = new WebSocketMessageWriter(socket);
  const socketConnection = createConnection(reader, writer, () => socket.dispose());
  createServerWithConnection(socketConnection as any);
}
import express from 'express';
import { IncomingMessage } from 'http';
import { Socket } from 'net';
import { URL } from 'url';
import { IWebSocket } from 'vscode-ws-jsonrpc';
import { WebSocketServer } from 'ws';
import { getLocalDirectory } from './fs-utils.js';
import { launch } from './launcher.js';

process.on('uncaughtException', function (err: any) {
  console.error('Uncaught Exception: ', err.toString());
  if (err.stack) {
    console.error(err.stack);
  }
});

// create the express application
const app = express();
// server the static content, i.e. index.html
app.use(express.static(getLocalDirectory()));
// start the server
const server = app.listen(3000);
// create the web socket
const wss = new WebSocketServer({
  noServer: true,
  perMessageDeflate: false
});
server.on('upgrade', (request: IncomingMessage, socket: Socket, head: Buffer) => {
  const baseURL = `http://${request.headers.host}/`;
  const pathname = request.url ? new URL(request.url, baseURL).pathname : undefined;
  if (pathname === '/sqlls') {
    wss.handleUpgrade(request, socket, head, webSocket => {
      const socket: IWebSocket = {
        send: content =>
          webSocket.send(content, error => {
            if (error) {
              throw error;
            }
          }),
        onMessage: cb =>
          webSocket.on('message', data => {
            console.log(data.toString());
            cb(data);
          }),
        onError: cb => webSocket.on('error', cb),
        onClose: cb => webSocket.on('close', cb),
        dispose: () => webSocket.close()
      };
      // launch the server when the web socket is opened
      if (webSocket.readyState === webSocket.OPEN) {
        launch(socket);
      } else {
        webSocket.on('open', () => launch(socket));
      }
    });
  }
});
@joe-re joe-re self-assigned this Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants