Skip to content

Instantly share code, notes, and snippets.

@marvinborner
Created January 20, 2024 23:08
Show Gist options
  • Select an option

  • Save marvinborner/ddc72b214352a485d308a7b1c157230b to your computer and use it in GitHub Desktop.

Select an option

Save marvinborner/ddc72b214352a485d308a7b1c157230b to your computer and use it in GitHub Desktop.
Effekt #366
const { spawn } = require("child_process");
const net = require("net");
const {
createProtocolConnection,
HoverRequest,
NullLogger,
InitializeRequest,
DidOpenTextDocumentNotification,
DidCloseTextDocumentNotification,
InitializedNotification,
} = require("vscode-languageserver-protocol");
const port = 5006; // some free port
const process = spawn("effekt.sh", ["-s", "--debug", "--debugPort", port]);
process.stderr.on("data", (data) => {
console.log(`stderr: ${data}`);
});
setTimeout(() => {
const socket = net.createConnection({ port }, () => {
console.log("connected to server!");
});
const connection = createProtocolConnection(socket, socket, NullLogger);
connection.listen();
let count = 0;
function sendHover() {
const didOpenParams = {
textDocument: {
uri: `file:///hover${count}.effekt`,
languageId: "effekt",
version: count,
text: "effect Exc(msg: String): Unit",
},
};
connection
.sendNotification(DidOpenTextDocumentNotification.type, didOpenParams)
.then((result) => {
console.log("opened file");
const hoverParams = {
textDocument: {
uri: `file:///hover${count}.effekt`,
},
position: {
line: 0,
character: 8, // hover on "Exc"
},
};
connection
.sendRequest(HoverRequest.type, hoverParams)
.then((result) => {
// `result` is sometimes null, sometimes correct!
console.log("hover done, result:", result);
connection
.sendNotification(DidCloseTextDocumentNotification.type, {
textDocument: {
uri: `file:///hover${count}.effekt`,
},
})
.then((result) => {
console.log("closed file\n");
count++;
setTimeout(sendHover, 200);
});
});
});
}
connection
.sendRequest(InitializeRequest.type, {
initializationOptions: {
showIR: "none",
showTree: false,
},
})
.then((result) => {
console.log(result);
sendHover();
});
}, 1000);
const exit = () => process.exit();
process.on("SIGINT", exit);
process.on("SIGTERM", exit);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment