-
Hey there. I'm currently writing monaco editor support for my yaml based DSL. I want to write 'jump to definition' support, where a string in the document should refer to an earlier string: things:
- name: thing1
...
- name: thing2
...
- name: thing3
parent: thing1 It's more complex than this contrived example, but what I need to do is take my current character position (say hovering somewhere in
This way i can identify I am looking for the definition of a 'parent reference'.. I hope that's clear enough... The important part here is, id like Right now I'm using visit, looking for the pair with a key: "parent", testing if it's value's position overlaps the cursor position, and then walking the path, but it's a little brutish and inelegant. Just wondering if there was a better approach? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
In what way do you find |
Beta Was this translation helpful? Give feedback.
-
For others who might ask: no there isn't currently a fast index to find a node at a position (caret). Which should have been how I posed the question :D In my mind, a b-tree with spanning indexes (just using first-position) indexing position to a node, would work here. It would need to support live edits to the Document AST for completeness (not just create-on-parse). Finally it would probably slow down parsing, and definitely slow down insert/edits, because creating or mutating a node would necessarily require the right side of the tree to be rebuilt, so it would definitely need to be guarded by an option eg: |
Beta Was this translation helpful? Give feedback.
For others who might ask: no there isn't currently a fast index to find a node at a position (caret). Which should have been how I posed the question :D
In my mind, a b-tree with spanning indexes (just using first-position) indexing position to a node, would work here. It would need to support live edits to the Document AST for completeness (not just create-on-parse). Finally it would probably slow down parsing, and definitely slow down insert/edits, because creating or mutating a node would necessarily require the right side of the tree to be rebuilt, so it would definitely need to be guarded by an option eg:
parseDocument(doc,{createPositionIndex: true}