Skip to content

Commit

Permalink
don't exit process when failed to notification
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-re committed Jul 15, 2020
1 parent c9e2987 commit 3e09145
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 41 deletions.
79 changes: 42 additions & 37 deletions example/monaco_editor/src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,49 @@ process.on("uncaughtException", function (err: any) {
}
});

const app = express();
app.use(express.static(`${process.cwd()}/dist`));
let server: http.Server

function startServer() {
const app = express();
app.use(express.static(`${process.cwd()}/dist`));
server = app.listen(3000);

const server = app.listen(3000);

const wss = new ws.Server({
noServer: true,
perMessageDeflate: false,
});

server.on(
"upgrade",
(request: http.IncomingMessage, socket: net.Socket, head: Buffer) => {
const path = request.url ? url.parse(request.url).pathname : undefined;
if (path === "/server") {
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(),
};
if (webSocket.readyState === webSocket.OPEN) {
console.log("ready to launch server");
launchServer(socket);
} else {
webSocket.on("open", () => {
const wss = new ws.Server({
noServer: true,
perMessageDeflate: false,
});

server.on(
"upgrade",
(request: http.IncomingMessage, socket: net.Socket, head: Buffer) => {
const path = request.url ? url.parse(request.url).pathname : undefined;
if (path === "/server") {
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(),
};
if (webSocket.readyState === webSocket.OPEN) {
console.log("ready to launch server");
launchServer(socket);
});
}
});
} else {
webSocket.on("open", () => {
console.log("ready to launch server");
launchServer(socket);
});
}
});
}
}
}
);
);
}

startServer()
12 changes: 8 additions & 4 deletions packages/server/src/createServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ export function createServerWithConnection(connection: IConnection) {
logger.debug('onInitialize: receive change event from SettingStore')
try {
setTimeout(() => {
connection.sendNotification('sqlLanguageServer.finishSetup', {
personalConfig: SettingStore.getInstance().getPersonalConfig(),
config: SettingStore.getInstance().getSetting()
})
try {
connection.sendNotification('sqlLanguageServer.finishSetup', {
personalConfig: SettingStore.getInstance().getPersonalConfig(),
config: SettingStore.getInstance().getSetting()
})
} catch (e) {
logger.error(e)
}
}, 1000) // TODO: Need to think about better way to sendNotification
try {
const client = getDatabaseClient(
Expand Down

0 comments on commit 3e09145

Please sign in to comment.