-
-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unify python and json language server. Extract common function. Make …
…both external
- Loading branch information
Showing
16 changed files
with
127 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
ports: | ||
- port: 3000 | ||
- port: 30000 | ||
- port: 30001 | ||
- port: 8080 | ||
tasks: | ||
- before: bash scripts/auth.sh | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* -------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2018-2022 TypeFox GmbH (http://www.typefox.io). All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
* ------------------------------------------------------------------------------------------ */ | ||
import { resolve } from 'path'; | ||
import { WebSocketServer } from 'ws'; | ||
import { IncomingMessage, Server } from 'http'; | ||
import { URL } from 'url'; | ||
import { Socket } from 'net'; | ||
import { IWebSocket, WebSocketMessageReader, WebSocketMessageWriter } from 'vscode-ws-jsonrpc'; | ||
import { createConnection, createServerProcess, forward } from 'vscode-ws-jsonrpc/server'; | ||
import { Message, InitializeRequest, InitializeParams } from 'vscode-languageserver'; | ||
|
||
/** | ||
* start the language server inside the current process | ||
*/ | ||
export const launchLanguageServer = (serverName: string, socket: IWebSocket, baseDir: string, relativeDir: string) => { | ||
// start the language server as an external process | ||
const ls = resolve(baseDir, relativeDir); | ||
const serverConnection = createServerProcess(serverName, 'node', [ls, '--stdio']); | ||
|
||
const reader = new WebSocketMessageReader(socket); | ||
const writer = new WebSocketMessageWriter(socket); | ||
const socketConnection = createConnection(reader, writer, () => socket.dispose()); | ||
if (serverConnection) { | ||
forward(socketConnection, serverConnection, message => { | ||
if (Message.isRequest(message)) { | ||
console.log(`${serverName} Server received:`); | ||
console.log(message); | ||
if (message.method === InitializeRequest.type.method) { | ||
const initializeParams = message.params as InitializeParams; | ||
initializeParams.processId = process.pid; | ||
} | ||
} | ||
if (Message.isResponse(message)) { | ||
console.log(`${serverName} Server sent:`); | ||
console.log(message); | ||
} | ||
return message; | ||
}); | ||
} | ||
}; | ||
|
||
export const upgradeWsServer = (config: { | ||
serverName: string, | ||
pathName: string, | ||
server: Server, | ||
wss: WebSocketServer, | ||
baseDir: string, | ||
relativeDir: string | ||
}) => { | ||
config.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 === config.pathName) { | ||
config.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) { | ||
launchLanguageServer(config.serverName, socket, config.baseDir, config.relativeDir); | ||
} else { | ||
webSocket.on('open', () => { | ||
launchLanguageServer(config.serverName, socket, config.baseDir, config.relativeDir); | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters