Skip to content

Commit

Permalink
clean up README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodingwizard committed Jul 3, 2024
1 parent 9ee80b8 commit 8698726
Showing 1 changed file with 0 additions and 164 deletions.
164 changes: 0 additions & 164 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,170 +54,6 @@ If you have any questions, please open an issue or reach out to us at usacoguide

## Misc Notes

### LSP Installation

We used Ubuntu 20.04 on Azure, B2s. Open port 3000 on the Azure firewall rules.

#### 1. Install `clangd-12`

```
sudo apt update
sudo apt install clangd-12
```

#### 2. Install node

```
sudo apt install nodejs npm
sudo npm install -g n
sudo n install lts
sudo n # choose v16 or whatever lts is
```

#### 3. Setup Server

```
git clone https://github.com/TypeFox/monaco-languageclient.git
cd packages/examples/node
```

Modify `server.ts`:

```ts
import * as rpc from 'vscode-ws-jsonrpc/cjs';
import { launch } from './json-server-launcher';
import fs from 'fs';
import * as https from 'https';

const privateKey = fs.readFileSync(
'/etc/letsencrypt/live/lsp.usaco.guide/privkey.pem',
'utf8'
);
const certificate = fs.readFileSync(
'/etc/letsencrypt/live/lsp.usaco.guide/fullchain.pem',
'utf8'
);

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(__dirname));
// start the server
//const server = app.listen(3000);
const httpsServer = https.createServer(
{ key: privateKey, cert: certificate },
app
);
httpsServer.listen(3000);
// create the web socket
const wss = new ws.Server({
noServer: true,
perMessageDeflate: false,
});
httpsServer.on(
'upgrade',
(request: http.IncomingMessage, socket: net.Socket, head: Buffer) => {
// eslint-disable-next-line n/no-deprecated-api
const pathname = request.url ? url.parse(request.url).pathname : undefined;
if (pathname === '/sampleServer') {
wss.handleUpgrade(request, socket, head, webSocket => {
const socket: rpc.IWebSocket = {
send: content =>
webSocket.send(content, error => {
if (error) {
throw error;
}
}),
onMessage: cb => webSocket.on('message', cb),
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));
}
});
}
}
);
```

Modify `json-server-launcher.ts`:

```ts
//import * as path from 'path';
import * as rpc from 'vscode-ws-jsonrpc/cjs';
import * as server from 'vscode-ws-jsonrpc/cjs/server';
import * as lsp from 'vscode-languageserver';
import { start } from './json-server';
import { Message } from 'vscode-languageserver';

export function launch(socket: rpc.IWebSocket) {
const reader = new rpc.WebSocketMessageReader(socket);
const writer = new rpc.WebSocketMessageWriter(socket);
const asExternalProccess =
process.argv.findIndex(value => value === '--external') !== -1;
if (asExternalProccess) {
// start the language server as an external process
//const extJsonServerPath = path.resolve(__dirname, 'ext-json-server.js');
const socketConnection = server.createConnection(reader, writer, () =>
socket.dispose()
);
//const serverConnection = server.createServerProcess('JSON', 'node', [extJsonServerPath]);
const serverConnection = server.createServerProcess('CPP', 'clangd-12');
if (serverConnection) {
server.forward(socketConnection, serverConnection, message => {
if (Message.isRequest(message)) {
if (message.method === lsp.InitializeRequest.type.method) {
const initializeParams = message.params as lsp.InitializeParams;
initializeParams.processId = process.pid;
}
}
return message;
});
}
} else {
// start the language server inside the current process
start(reader, writer);
}
}
```

Then:

```
# "cannot find module 'semver' error when running npm install?
# See https://stackoverflow.com/questions/33870520/npm-install-cannot-find-module-semver
npm install
npm run build
node dist/server.js --external
```

To keep the server running:

```
sudo apt install tmux
tmux
node dist/server.js --external
# https://askubuntu.com/questions/8653/how-to-keep-processes-running-after-ending-ssh-session
ctrl+b d
# later, to get back into the session
tmux attach -t 0
```

### Firepad / YJS Browser Incompatibility

See https://github.com/FirebaseExtended/firepad/issues/315 and https://github.com/yjs/y-monaco/issues/6.
Expand Down

0 comments on commit 8698726

Please sign in to comment.