Open 4e6 opened 1 day 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:
Ast.syncToCode
to update the parse tree to the current source code.This way we would preserve all metadata, anywhere in the AST.
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:
IdMap
sent with theTextEdit
requestIdMap
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 theexpr
. Theexpr
can be identified using the path in the tree. We can use the following format:{method pointer}.{variable name}
. I.e.the
expr1
can be identified aslocal.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.