Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat add node ids #51

Merged
merged 11 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

strategy:
matrix:
os: [ubuntu, macos, windows]
os: [ubuntu, macos]
python-version: ['3.9', '3.10', '3.11']

steps:
Expand All @@ -27,6 +27,11 @@ jobs:
with:
submodules: true

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 20

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def build(_: Any): # one argument is passed by poetry but we don't need it
# watch out: tree-sitter might change this dir inadvertently...
# run(f"cp ~/.tree-sitter/bin/{fn} rsm/", cwd=".")
run(f"cp build/{fn} ../rsm/")
run(f"cp build/{fn} /Users/leo.torres/.emacs.d/tree-sitter/libtree-sitter-rsm.so") # for emacs
# run(f"cp build/{fn} /Users/leo.torres/.emacs.d/tree-sitter/libtree-sitter-rsm.so") # for emacs


if __name__ == "__main__":
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ markers = [
'slow: marks tests as slow (deselect with "-m \"not slow\"")',
"serial",
]
filterwarnings = [
"ignore:.*pkg_resources.*:DeprecationWarning",
]


# Poe the poet
Expand Down
1 change: 1 addition & 0 deletions rsm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def make() -> int:
cmd = " ".join(other_args)
server = livereload.Server()
server.watch(args.src, livereload.shell(cmd))
main(parser, app.make, args)
server.serve(root=".")
else:
main(parser, app.make, args)
Expand Down
8 changes: 8 additions & 0 deletions rsm/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ def __init__(
nonum: bool = False,
reftext_template: str = "",
) -> None:
self.nodeid: str | None = None
"""Node id - always exists (unlike label), automatically assigned, unique within the tree."""
self.label: str = label
"""Unique identifier."""
self.types: list[str] = types or []
Expand Down Expand Up @@ -726,6 +728,12 @@ def first_ancestor_of_type(
ancestor = ancestor.parent
return ancestor # the root node has parent None

def get_child_by_id(self, nodeid: int) -> Optional["Node"]:
for node in self.traverse(condition=lambda n: n.nodeid == nodeid):
return node
else:
return None

def replace_self(self, replacement: Union["Node", Iterable["Node"]]) -> None:
"""Replace this node in its parent's children.

Expand Down
72 changes: 69 additions & 3 deletions rsm/static/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,81 @@ export function setupClassInteractions() {
};
});

$(".tools-sidebar").mousedown(function(e) {
$("html").on("keyup", function(ev) {
const focused = document.activeElement;
const node_el = $(focused).find("[data-nodeid]");
const nodeid = node_el.data("nodeid");

switch(ev.which) {
case 74:
console.log("J");
lsp_ws.send(JSON.stringify({
"jsonrpc" : "2.0",
"method" : "workspace/executeCommand",
"id": "command-next_sibling",
"params": {
"command": "next_sibling",
"arguments": [nodeid],
}
}))
break;
case 75:
console.log("K");
lsp_ws.send(JSON.stringify({
"jsonrpc" : "2.0",
"method" : "workspace/executeCommand",
"id": "command-prev_sibling",
"params": {
"command": "prev_sibling",
"arguments": [nodeid],
}
}))
break;
}


});

$(".manuscriptwrapper").on("focusin", function(e) {
const focused = document.activeElement;
const node_el = $(focused).find("[data-nodeid]");
const nodeid = node_el.data("nodeid");
if (!nodeid) return;
console.log(`asking for ${nodeid}`);
lsp_ws.send(JSON.stringify({
"jsonrpc" : "2.0",
"method" : "workspace/executeCommand",
"id": "command-list_vars-999",
"params": {
"command": "list_vars",
"arguments": [nodeid],
}
}))
});

$(".tools-sidebar").on("mousedown", function(e) {
// This element cannot receive focus via the mouse because it needs to access
// the currently focused element - and clicking it would normally change the
// focus to it.
e.stopImmediatePropagation(); //stops event bubbling
e.preventDefault(); //stops default browser action (focus)
}).click(function() {
const src = $("body").children(".rsm-source");
console.log(document.activeElement);
let wrapper = $(".manuscriptwrapper");
if (wrapper.hasClass("manuscriptwrapper--narrow")) {
wrapper.removeClass("manuscriptwrapper--narrow");
}
else {
wrapper.addClass("manuscriptwrapper--narrow");
}

let vars_list = $(".tools-sidebar .vars-list");
if (vars_list.hasClass("hide")) {
vars_list.removeClass("hide");
}
else {
vars_list.addClass("hide");

}
});

$(".handrail").mouseleave(function () {
Expand Down
18 changes: 17 additions & 1 deletion rsm/static/onload.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export function onload(path = "/static/") {
});

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) {
Expand All @@ -48,6 +47,23 @@ export function onload(path = "/static/") {
console.log('[close] Connection died');
}
};
lsp_ws.onmessage = function(event) {
console.log(`[message] Data received from server: ${event.data}`);
const json = JSON.parse(event.data);
if (("id" in json) && (typeof(json.id) === "string") && json.id.startsWith("command-list_vars")) {
let content = "";
const vars_list = $(".vars-list-ul");
vars_list.empty();
for (let nodeid of json.result) {
content = $(`[data-nodeid=${nodeid}]`).html();
content = `<li>${content}</li>`;
vars_list.append(content);
}
};
if (("id" in json) && (typeof(json.id) === "string") && json.id.startsWith("command-next_sibling")) {
console.log(`move focus to ${json.result}`)
};
};
lsp_ws.onopen = function(e) {
console.log("[open] Connection established");
lsp_ws.send(JSON.stringify({
Expand Down
52 changes: 39 additions & 13 deletions rsm/static/rsm.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,24 @@
.tools-sidebar {
position: fixed;
top: calc(var(--h1-size));
right: 1em; }
right: 1em;
max-width: 18em;
display: flex;
flex-direction: row-reverse; }
.tools-sidebar .vars-list {
max-width: 85%;
box-shadow: 0 0 8px 4px #eee;
padding: 1em;
border-radius: 10px;
margin: auto;
font-size: 80%;
overflow-x: scroll; }
.tools-sidebar .vars-list-ul {
padding-inline-start: 1em; }
.tools-sidebar .tools-sidebar__btn:hover > svg {
background: var(--gray-900);
color: var(--gray-200);
cursor: pointer; }

.manuscriptwrapper {
border-radius: 8px;
Expand All @@ -60,6 +77,9 @@
overflow: hidden;
padding: 0 var(--side-padding) 0 var(--side-padding); }

.manuscriptwrapper--narrow {
margin: 2.5em 15em 2.5em auto; }

.manuscriptwrapper.embedded {
margin: 0;
padding-inline: 2.5rem 2.5rem;
Expand Down Expand Up @@ -110,7 +130,7 @@
.manuscriptwrapper ul.contents ul.itemize {
list-style: none;
margin-block-end: 0;
padding-inline-start: 2rem; }
padding-inline-start: 1rem; }
.manuscriptwrapper p:has(+ .mathblock) {
margin-block-end: 0; }
.manuscriptwrapper div.statement p {
Expand Down Expand Up @@ -186,6 +206,8 @@
padding: 0 0 0 var(--handrail-offset); }
.manuscriptwrapper .handrail .proof__title, .manuscriptwrapper .handrail .theorem__title {
padding-block: 1rem; }
.manuscriptwrapper .handrail .theorem__title {
border-bottom: var(--gray-200) solid 1px; }
.manuscriptwrapper .handrail--hug > p:not(.topic-title), .manuscriptwrapper .handrail--hug > .proof__title {
padding-block: 0; }
.manuscriptwrapper .handrail--offset {
Expand Down Expand Up @@ -272,21 +294,21 @@
transform: translateX(-100%); }
.manuscriptwrapper .handrail.handrail--hug > .handrail__btn-container {
top: 0; }
.manuscriptwrapper .abstract div.handrail > .handrail__btn-container,
.manuscriptwrapper .toc div.handrail > .handrail__btn-container {
.manuscriptwrapper .abstract div.handrail:first-of-type > .handrail__btn-container,
.manuscriptwrapper .toc div.handrail:first-of-type > .handrail__btn-container {
top: calc(var(--h3-size)/2 + (var(--header-line-height)*var(--h3-size) - var(--body-line-height)*1rem)/2); }
.manuscriptwrapper div.theorem > .handrail > .handrail__btn-container,
.manuscriptwrapper div.proof > .handrail > .handrail__btn-container {
.manuscriptwrapper div.theorem > .handrail:first-of-type > .handrail__btn-container,
.manuscriptwrapper div.proof > .handrail:first-of-type > .handrail__btn-container {
top: 1rem; }
.manuscriptwrapper section.level-1 > .handrail > .handrail__btn-container {
.manuscriptwrapper section.level-1 > .handrail:first-of-type > .handrail__btn-container {
top: calc(var(--h1-size)/2 + (var(--header-line-height)*var(--h1-size) - var(--body-line-height)*1rem)/2); }
.manuscriptwrapper section.level-2 > .handrail > .handrail__btn-container {
.manuscriptwrapper section.level-2 > .handrail:first-of-type > .handrail__btn-container {
top: calc(var(--h2-size)/2 + (var(--header-line-height)*var(--h2-size) - var(--body-line-height)*1rem)/2); }
.manuscriptwrapper section.level-3 > .handrail > .handrail__btn-container {
.manuscriptwrapper section.level-3 > .handrail:first-of-type > .handrail__btn-container {
top: calc(var(--h3-size)/2 + (var(--header-line-height)*var(--h3-size) - var(--body-line-height)*1rem)/2); }
.manuscriptwrapper section.level-4 > .handrail > .handrail__btn-container {
.manuscriptwrapper section.level-4 > .handrail:first-of-type > .handrail__btn-container {
top: calc(var(--h4-size)/2 + (var(--header-line-height)*var(--h4-size) - var(--body-line-height)*1rem)/2); }
.manuscriptwrapper section.level-5 > .handrail > .handrail__btn-container {
.manuscriptwrapper section.level-5 > .handrail:first-of-type > .handrail__btn-container {
top: calc(var(--h5-size)/2 + (var(--header-line-height)*var(--h5-size) - var(--body-line-height)*1rem)/2); }
.manuscriptwrapper .keyword {
color: var(--keyword-blue);
Expand All @@ -313,8 +335,8 @@
display: none;
color: var(--med-gray);
position: absolute;
left: calc(var(--handrail-offset) * 0.38);
transform: translateX(-100%) translateX(-2em);
right: 0;
transform: translateX(100%) translateX(2em);
font-family: 'Inconsolata', monospace; }
.manuscriptwrapper .step.last {
padding-block-end: 1rem; }
Expand Down Expand Up @@ -517,6 +539,8 @@
.manuscriptwrapper {
box-shadow: 0 0 8px 10px #eee;
margin: 2.5em auto; }
.manuscriptwrapper--narrow {
margin: 2.5em 20em 2.5em auto; }
a.bibitem-doi {
float: right; } }

Expand All @@ -530,6 +554,8 @@
--h6-size: 1.000rem;
--side-padding: 1.5em;
--font-size: 93.75%; }
.manuscriptwrapper--narrow {
margin: 2.5em 15em 2.5em auto; }
.options {
left: 0;
right: unset; }
Expand Down
Loading
Loading