Track type spans in ToStringResult to support decomposition #2163
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements a new
typeSpansfield on ToStringResult to record which TypeId produced parts of the substring in the stringified output. This enables tooling to decompose the result and map positions in the type string back to their source types, powering features such as Go-To-Definition in Inlay Hints.typeSpansis a vector of{startOffset, endOffset, typeId}within the string. We only populate spans for named types, i.e. extern types and named table / metatable types. The rest of the type kinds are ignored.Special attention needs to be given for
UnionTypeandIntersectionType. When stringifying these compound types, it works by resetting thestate.result.nameto an empty string before stringifying the part, then recomposing all the parts back to the full string. This can also include a sorting step.We need to correct the typeSpans during this approach. We introduce a new
ElementResultthat stores the resulting string and set of spans for each part. Then when reconstructing, we offset each span by the current size ofstate.result.name.These changes are gated behind the FFlag
LuauToStringDecompositionCloses #1591