Before exposing existing LSP methods we need to provide a way for DTD clients to always get the same format responses regardless of the client capabilities provided by the original server. Until then, add an allow-list for LSP methods that we can use to selectively enable specific methods that are not affected by client capabilities.
Change-Id: Ia1c994a50c9b94a91f4085c09f9d9d94c0fad79e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382401
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
This adds a new request `dart/connectToDtd` that lets a client pass a DTD URI to the server. The server will connect to DTD and provide a subset of LSP methods (those that are currently available over LSP-Over-Legacy, minus the `connectToDtd` method itself) to DTD clients.
This works for both LSP and Legacy servers, and the shared tests run against both (where for legacy, the `dart/connectToDtd` request uses the LSP-over-Legacy support).
This is not currently behind a flag, however it won't do much on its own because no clients will make this request. Once we're happy the functioanlity is good we can either agree an SDK version number for IDEs to gate calling this method on, or we can expose a flag in server capabilities (and some equiv for legacy) so the client knows the functionality is available.
Change-Id: I911d37745a1b2685249dd88e4b152c3196ba627c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379303
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
This adds failing tests for https://github.com/dart-lang/sdk/issues/56475.
If this CL is applied to the 3.5 release and the `singleOptionContexts` flag set back to `true` (matching 3.4 behaviour), the tests will pass. Each package in both tests will get its own context root (because they have analysis_options to enable the plugins) and each one will read the correct plugins that are enabled.
However if `singleOptionContexts` is `false` (as shipped in 3.5) or this code is applied to bleeding-edge (where the flag is gone, but behaves the same as `false`) both tests fail as follows:
`test_sentToPlugins_inNestedPackages_withPackageConfigs` fails because we read the child analysis_options for the root and try to incorrectly load plugins from the root (and include duplicates and allow more than one plugin):
```
Expected: {
'package1': ['plugin1'],
'package2': ['plugin2'],
'package3': ['plugin1']
}
Actual: {
'home': ['plugin1', 'plugin2', 'plugin1'],
'package1': ['plugin1', 'plugin2', 'plugin1'],
'package2': ['plugin1', 'plugin2', 'plugin1'],
'package3': ['plugin1']
}
```
`test_sentToPlugins_inNestedPackages_withoutPackageConfigs` fails because we now only have a context root for the root which enables all plugins from the children:
```
Expected: {
'package1': ['plugin1'],
'package2': ['plugin2'],
'package3': ['plugin1']
}
Actual: {
'home': ['plugin1', 'plugin2', 'plugin1']
}
```
Change-Id: I12f45eeb5c1848352af26ac3fdb690e51833c22a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381460
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Previously, `HintCode.UNREACHABLE_SWITCH_CASE` was marked as
deprecated, and `WarningCode.UNREACHABLE_SWITCH_CASE` was an alias to
it. This created a slightly confusing situation, because it meant that
all code referring to the diagnostic had to refer to it as
`WarningCode.UNREACHABLE_SWITCH_CASE` (to avoid a deprecation lint),
but the diagnostic still _behaved_ like it was a hint, and therefore
test runner expectations still had to treat it as a hint.
It turns out that it's not really necessary to go through the
deprecation dance when changing the kind of a diagnostic, since (a)
members of `HintCode` and `WarningCode` aren't exposed through the
analyzer public API, and (b) ignore comments don't have to specify
whether something is a hint or a warning.
So the easiest way to clear up the confusion is to just remove
`HintCode.UNREACHABLE_SWITCH_CASE` entirely, and move its implemention
into `WarningCode.UNREACHABLE_SWITCH_CASE` (so that the latter is no
longer an alias).
Change-Id: I9ff7901ad38a2c168c5e54cbe0c1c52bf7c50186
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381103
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Work towards https://github.com/dart-lang/sdk/issues/56467
Thw two assists do the following:
* Add a digit separators every 3 digits in a decimal int, a decimal
double, and a scientific notation double.
* Add a digit separators every 2 digits in a hexadecimal int.
No assists are introduced which remove digit separators.
Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: I0920fb279285963c33a78d9288317213739ae83b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380601
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This lint is the complement of 'omit_obvious_local_variable_types'
in that it flags every declaration that does _not_ specify the type
of a local variable, when it has an initializing expression whose type
is not obvious (defined as in 'omit_obvious_local_variable_types').
Change-Id: If80a961e47fed0412d0ea0bac5ac010e26fea7bc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379160
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Erik Ernst <eernst@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
This change is just some refactoring and additional flags on handlers to reduce the size of a future CL that adds DTD support.
It:
- Slightly changes the meaning of `lspInitialized` in the server (to now mean the server is in the "initialized" state where it can handle the set of requests LSP allows after a server is initialized)
- Adds an additional future for `lspUninitialized` to track when the server moves _out_ of that state
- Removes an expando in LspOverLegacyHandler that tracked handlers against a server, because they're now available in the `lspInitialized` future (for DTD support, we need access to them without the LSP-over-Legacy handler, because we need to initialize DTD at startup regardless of whether a legacy client triggers LSP initialization)
- Adds a flag `requiresTrustedCaller` to handlers to indicate whether they can only be called by the native protocol clients. Tthis must be explicitly provided for shared handlers to ensure each choice is deliberate. The flag is unused in this CL but included here to reduce noise in the next (it touches many files)
- Changes the type of `toJson()` on generated enum clases to have the native type of the value that is returned
Change-Id: I0615cf4671b84887bf56c236d82d0fa3c26e6d87
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379304
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Adds a new `@Array.variable()` to specify that the last element of
structs is a variable length inline array.
This CL does not add any checks for passing structs with variable
length inline arrays by value or directly calling them with
`AllocatorAlloc.call`. Instead, the implementation defaults to what
C does, allocate as if there are 0 elements in the variable length
inline array.
TEST=tests/ffi/*
CoreLibraryReviewExempt: VM only
Closes: https://github.com/dart-lang/sdk/issues/55964
Change-Id: I524d8a1d710b1a744b392e05fa884908c3ff1f12
Cq-Include-Trybots: dart/try:vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_x64-try,vm-aot-asan-linux-release-x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-msan-linux-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try,vm-aot-tsan-linux-release-x64-try,vm-aot-ubsan-linux-release-x64-try,vm-aot-win-debug-arm64-try,vm-aot-win-debug-x64-try,vm-aot-win-debug-x64c-try,vm-appjit-linux-debug-x64-try,vm-asan-linux-release-arm64-try,vm-asan-linux-release-x64-try,vm-checked-mac-release-arm64-try,vm-eager-optimization-linux-release-ia32-try,vm-eager-optimization-linux-release-x64-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-try,vm-fuchsia-release-arm64-try,vm-fuchsia-release-x64-try,vm-linux-debug-ia32-try,vm-linux-debug-x64-try,vm-linux-debug-x64c-try,vm-mac-debug-arm64-try,vm-mac-debug-x64-try,vm-msan-linux-release-arm64-try,vm-msan-linux-release-x64-try,vm-reload-linux-debug-x64-try,vm-reload-rollback-linux-debug-x64-try,vm-tsan-linux-release-arm64-try,vm-tsan-linux-release-x64-try,vm-ubsan-linux-release-arm64-try,vm-ubsan-linux-release-x64-try,vm-win-debug-arm64-try,vm-win-debug-x64-try,vm-win-debug-x64c-try,vm-win-release-ia32-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371960
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Also move the top-level `computeFixes` convenience function.
The `computeFixes` function is the main entrypoint that various code
uses to, well, compute all fixes with a FixProcessor and a
FixInFileProcessor. In order for plugin code to call `computeFixes`,
we need that function and FixInFileProcessor in the
analysis_server_plugin package.
Work towards https://github.com/dart-lang/sdk/issues/53402
Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: Id5f02864762eeefb92055a3534e91b60b76dfeb2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378220
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
The LSP completion mapping currently does some manipulation of values to fit better into the different fields LSP supports (to improve formatting and filtering). The code that splits the label on `=>` was also matching `==` in overrides but should not.
This is a simple fix to the regex to solve the issue, although longer-term (or at least if we see other issues as a result of this manipulation) this logic should be pushed up to the source so we have reliable fields and don't need to split things this way.
Fixes https://github.com/dart-lang/sdk/issues/56336
Change-Id: I056489df5aba417cab9162e027eb97579f71756b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378200
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
This generalizes the code that was handling `[`+`]` being replaced with a single token for `[]` to support arbitrary substitutions (and in both directions) to handle where GTs can be moved by the formatted (usually because of differences in wrapping of type parameters).
Change-Id: Ia7d75637fa5506a33db1e91111ab3b7fc060f3ce
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377647
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This is a refactor with no functional changes.
The function to compute minimal edits for formatting changes has grown a lot over time and was very long with many nested functions making it difficult to maintain. Additional fixes I'm working on (to handle token changes between consecutive GT tokens and GT_GT or GT_GT_GT) add more to it, so this is an attempt to simplify it by moving it into a class and extracting the nested helper functions to make the logic easier to follow.
I'm pushing this to Gerrit in multiple patch sets in case it's easier to review:
1. Move the function (unchanged) into a class
2. Tidy up the logic slightly to use class variables (so helpers that were using local variables can be extracted later)
3. Move the nested functions (and some private top-level functions) to the class level
Change-Id: I277b458c8e4780ea02629f8cba80db683057ae90
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377646
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Work towards https://github.com/dart-lang/sdk/issues/53402
I move them all out of static fields on FixProcessor to be instance
fields on a singleton class in a new file, fix_generators.dart. For
each one that ended in the word 'Map', I removed that.
I also move `_bulkFixableErrorCodes` and `canBulkFix` to
BulkFixProcessor, as it is the only caller, and holds onto the data.
I also correct some outdated doc comments.
I also make `_isFixableError` static.
Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: I01beccac4969f832941c75eb6d7b49b54a0b085c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377563
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
As well as commas, the formatter can remove semicolons from enums. Additionally, it can remove adjacent commas and semicolons! This adds support for both, by simplifying the check to have a set of allowed tokens, and looping to check again after it advances over any tokens.
Change-Id: I17a1172c803d579f01c801a372a69226d1dc3277
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377643
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
* Re-implement `PubspecFixRequestResult` as a Record.
This was a class with two final fields, and the class is always
immediately deconstructed, so it seems like a fine case for a
Record. That being said, if this is "surprising", we can go back to
a full class. I don't think there is a performance change; just API.
* 4 fields and 1 method on BulkFixProcessor can be private. Making one
of these private enables promotion, removing the need for local
shadowing variables.
* 2 fields on BulkFixProcessor can be visibleForTesting.
* 6 fields and 1 getter on IterativeBulkFixProcessor can be made
private.
* Update doc comments to be more idiomatic.
Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: I45ba8cbd428e281727cfc4dfba712be72d3325f7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377622
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
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.
Another place this happens is when the formatter changes whitespace within comments (removing trailing spaces). That whitespace is not between tokens, but part of the comments. This change handles that by allowing entire comments to be replaced when the contents is different (stripped of any matching prefix/suffix).
Fixes https://github.com/Dart-Code/Dart-Code/issues/5200
Change-Id: I675f2b00aaa5ea07088d653ec746524f4166598b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377424
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Instead, obtain a resolved unit and then verify the versions still match (and if not, reject the request as stale).
This doesn't eliminate the possibility of a deadlock because the completion handler still does the same - however it's much less likely that completion is running during server initialization (whereas inlay hints for an open file can happen early) and rejecting requests during typing may have more of an impact there (where the user is often typing, and the editor may be compensating for their changes, so a "stale" response may be better than constantly restarting).
If we make changes to scheduling on the server, the ability to pause incoming _requests_ without also pausing incoming _responses_ may provide the best of both worlds here.
Fixes https://github.com/dart-lang/sdk/issues/56311
Change-Id: I34412356da444e8c57f38ebe0d821c805179b0b2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377642
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
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>
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.
In the case where the request was to format a _range_ sending back an entire formatted document is never correct, so this changes the handling to return no edits at all if the request was to format a range.
Fixes https://github.com/Dart-Code/Dart-Code/issues/5169 (to not format the entire document) but does not fix the issue that formatting empty collections produces unexpected differences in token streams - that will be fixed in another CL.
Change-Id: Ibaef49a2800d300606f5132e912c9d30b33cb18a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377422
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
The `registerBuiltInProducers` function is called many times during a test run so adding producers to a `List` results in the collection getting larger and larger over time, resulting in tests taking much longer to run.
Change-Id: I7195a156e53223bc0ed9a41eb0138cff30b15aa3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377220
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
FixProcessor has to be part of the analysis_server_plugin package, so
it cannot have any dependencies on the analysis_server package. This moves one.
The word 'default' is reserved, so I changed to 'standard'.
Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: I1ee21c800203fac758f10a6fde0ea7d07eee5e7f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/374742
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>