Files
sdk/pkg/analysis_server
Danny Tuppeny b1f0b08c9b [analysis_server] When formatting, handle differences in token streams where an empty collection was unwrapped
When formatting over LSP, we run the formatter (which produces an entire new set of formatted code) and compare the unformatted/formatted code to try and produce minimal edits for the format. This allows things like breakpoints to remain stable in the editor (whereas replacing the entire content might cause them to be lost).

The algorithm we use to do this is a very simple diff on the token stream that assumes only whitespace (and commas) will change. If we find another difference, we fall back to just sending the entire document edit.

One case where this currently happens is when an empty collection contains whitespace and is collapsed (eg. `[\n]` becomes `[]`). It goes from being two tokens to a single token. This change adds support for that by stepping over the two tokens on the left and one token on the right so that we produce the right result.

Fixes https://github.com/Dart-Code/Dart-Code/issues/5198

Change-Id: Ice61ad92a372844445924cece009d31c98b38d60
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377443
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-07-24 16:49:42 +00:00
..

analysis_server

A long-running process that provides analysis results to other tools.

The analysis server is designed to provide on-going analysis of one or more code bases as those code bases are changing.

Using the server

The analysis server is not intended to be used stand-alone, and therefore does not have a human-friendly user interface.

Clients (typically tools, such as an editor) are expected to run the analysis server in a separate process and communicate with it using a JSON protocol. The original protocol is specified in the file analysis_server/doc/api.html and Language Server Protocol support is documented in tool/lsp_spec/README.md.

Features and bugs

Please file feature requests and bugs at the issue tracker.