enso-org / enso

Hybrid visual and textual functional programming.
https://enso.org
Apache License 2.0
7.36k stars 324 forks source link

Metadata should not depend on text spans #11304

Open 4e6 opened 1 day ago

4e6 commented 1 day ago

We want to edit source files externally without breaking the METADATA section. To do that we need to change the METADATA section format so that it does not depend on text spans.

We can think about metadata consisting of two parts:

  1. The METADATA section stored in files
  2. The IdMap sent with the TextEdit request

IdMap

We don't need to change the IdMap format because it is generated on the fly.

METADATA section

The Metadata stored in files only relates to the nodes var = expr and points to the expr. The expr can be identified using the path in the tree. We can use the following format: {method pointer}.{variable name}. I.e.

main =
    op1 = expr1

the expr1 can be identified as local.NewProject1.Main.main.op1.

And instead of [Span, UUID] pairs (span to UUID mapping), we can use [Path, UUID] pairs (pair to UUID mapping). And use UUID in the language server protocol as usual.

kazcw commented 20 hours ago

I like the idea of having symbolic source-code references, but there are a lot of syntactic cases that will each need their own solution.

The proposed path type ({method pointer}.{variable name}) can identify a binding, but we have plans to support attaching metadata to any subexpression (e.g. widget picker: #8754). Even today, not every component shown in the graph has a unique binding; a component can be:

Another thing to consider is that the LHS of a binding is not strictly an identifier; it is a pattern. I don't think the backend currently supports destructuring-bindings at all, but once that is implemented there won't always be a simple way to stringify the LHS of a binding.


If the goal is storing metadata in a way that it is resilient to external edits, there's a simpler way: We can use the module source code as a map of itself. Include a snapshot of the module alongside the serialized metadata; then to load a module from disk:

This way we would preserve all metadata, anywhere in the AST.