Skip to content

Commit

Permalink
[analysis_server] Enable "EditArgument" request to work over the lega…
Browse files Browse the repository at this point in the history
…cy protocol

+ move all related tests to a shared mixin so they run for both servers.

Change-Id: I853e8f24948c07fdde2a5d6a64ddc65962357b6d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/404841
Commit-Queue: Brian Wilkerson <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
Reviewed-by: Phil Quitslund <[email protected]>
  • Loading branch information
DanTup authored and Commit Queue committed Jan 18, 2025
1 parent b908274 commit dd9a061
Show file tree
Hide file tree
Showing 8 changed files with 767 additions and 724 deletions.
5 changes: 5 additions & 0 deletions pkg/analysis_server/lib/src/analysis_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,11 @@ abstract class AnalysisServer {
/// 'lsp.notification' notification.
void sendLspNotification(lsp.NotificationMessage notification);

/// Sends an LSP request with the given [params] to the client and waits for a
/// response. Completes with the raw [lsp.ResponseMessage] which could be an
/// error response.
Future<lsp.ResponseMessage> sendLspRequest(lsp.Method method, Object params);

/// Sends an error notification to the user.
void sendServerErrorNotification(
String message,
Expand Down
1 change: 1 addition & 0 deletions pkg/analysis_server/lib/src/legacy_analysis_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,7 @@ class LegacyAnalysisServer extends AnalysisServer {

/// Sends an LSP request to the server (wrapped in 'lsp.handle') and unwraps
/// the LSP response from the result of the legacy response.
@override
Future<lsp.ResponseMessage> sendLspRequest(
lsp.Method method,
Object params,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:analysis_server/src/lsp/constants.dart';
import 'package:analysis_server/src/lsp/error_or.dart';
import 'package:analysis_server/src/lsp/handlers/custom/editable_arguments/editable_arguments_mixin.dart';
import 'package:analysis_server/src/lsp/handlers/handlers.dart';
import 'package:analysis_server/src/lsp/lsp_analysis_server.dart';
import 'package:analysis_server/src/lsp/mapping.dart';
import 'package:analysis_server/src/lsp/source_edits.dart';
import 'package:analyzer/dart/analysis/results.dart';
Expand Down Expand Up @@ -286,14 +285,6 @@ class EditArgumentHandler extends SharedMessageHandler<EditArgumentParams, Null>
/// Sends [workspaceEdit] to the client and returns `null` if applied
/// successfully or an error otherwise.
Future<ErrorOr<Null>> _sendEditToClient(WorkspaceEdit workspaceEdit) async {
var server = this.server;
if (server is! LspAnalysisServer) {
return error(
ErrorCodes.RequestFailed,
'Sending edits is currently only supported for clients using LSP directly',
);
}

var editDescription = 'Edit argument';
var editResponse = await server.sendLspRequest(
Method.workspace_applyEdit,
Expand Down
4 changes: 1 addition & 3 deletions pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -861,9 +861,7 @@ class LspAnalysisServer extends AnalysisServer {
channel.sendNotification(notification);
}

/// Sends a request with the given [params] to the client and wait for a
/// response. Completes with the raw [ResponseMessage] which could be an
/// error response.
@override
Future<ResponseMessage> sendLspRequest(Method method, Object params) {
var requestId = nextRequestId++;
var completer = Completer<ResponseMessage>();
Expand Down
Loading

0 comments on commit dd9a061

Please sign in to comment.