[syntax-coloring] Rework the syntax map to use offset + length and simplify the delta logic #10289
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 patch changes the syntax map data structure to be offset based rather than line/col based in order to avoid calling
getLineAndColumn
for the start and end offset of every token. This removes the 30% of time spent ingetLineAndColumn
during this request for large files (rdar://problem/28965123).The logic for returning the affected range and the token ranges to highlight following an edit also made several assumptions that no longer hold. This patch changes it to compare the syntax maps from before and after the edit, find the first mismtaching tokens from the start and end of the syntax maps
and return the tokens in that range (adjusted to line boundaries). This fixes syntax highlighting issues with interpolated multi-line strings (rdar://problem/32148117) and block comments.
With the above changes the per-keystroke time spent for syntax highlighting (with sematic info disabled) drops from ~80ms to just under 50ms for a 12KLOC file.
This patch also changes unterminated/invalid regular and multi-line strings to now be highlighted as strings.
Resolves rdar://problem/28965123 and rdar://problem/32148117.