Skip to content

Commit

Permalink
make a connection to the language server and expose it to the entire …
Browse files Browse the repository at this point in the history
…window by returning it
  • Loading branch information
leotrs committed May 5, 2024
1 parent f520c29 commit b9189d6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rsm/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def make_html_header(self) -> str:
<script src="static/tooltipster.bundle.js"></script>
<script type="module">
import { onload } from '/static/onload.js';
window.addEventListener('load', (ev) => {onload();});
window.addEventListener('load', (ev) => {window.lsp_ws = onload();});
</script>
<title>{some_title}</title>
Expand Down
43 changes: 42 additions & 1 deletion rsm/static/onload.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
// Function to run when the entire document finishes loading
//



export function onload(path = "/static/") {
let lsp_ws;
import(path + 'libraries.js').then((libs) => {
libs.loadMathJax().then(() => {
console.log('MathJax loaded!');
Expand Down Expand Up @@ -33,5 +36,43 @@ export function onload(path = "/static/") {
console.error('Loading MathJax FAILED!');
console.error(err);
})
})
});

lsp_ws = new WebSocket("ws://127.0.0.1:1234");
lsp_ws.onmessage = function(event) {console.log(`[message] Data received from server: ${event.data}`)};
lsp_ws.onerror = function(error) {console.log(`[error]`)};
lsp_ws.onclose = function(event) {
if (event.wasClean) {
console.log(`[close] Connection closed cleanly, code=${event.code} reason=${event.reason}`);
} else {
console.log('[close] Connection died');
}
};
lsp_ws.onopen = function(e) {
console.log("[open] Connection established");
lsp_ws.send(JSON.stringify({
"jsonrpc": "2.0",
"method": "initialize",
"id": 1,
"params": {
"processId": null,
"capabilities": {}
}
}));
const src = $("body").children(".rsm-source");
lsp_ws.send(JSON.stringify({
"jsonrpc" : "2.0",
"method" : "textDocument/didOpen",
"params": {
"textDocument": {
"languageId": "rsm",
"text": src.text(),
"uri": "file://src/hello.rsm",
"version": 1
}
}
}))
};

return lsp_ws;
}

0 comments on commit b9189d6

Please sign in to comment.