Skip to content

Commit 6a94c61

Browse files
DanTupCommit Queue
authored andcommitted
[analysis_server] Minor LSP refactors + fix
Some minor fixes/tweaks extracted from another CL 1. Fix tool/lsp_spec/codegen_dart to set `options` on `CodeStyleOptions` (a late field that needs to be set to the owning options file) 2. Fix a wrapped TODO to be indented so it's detected correctly 3. Move the custom `DartTextDocumentContentProviderHandler` handler into the `custom` folder 4. Merge `LspHandlerHelperMixin ` into `HandlerHelperMixin` since the APIs it uses are no longer LSP-specific and exist on the base server Change-Id: Ie1b3a8057575346cf9bfb98465c0a3e330c28a82 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392909 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Phil Quitslund <[email protected]> Reviewed-by: Phil Quitslund <[email protected]>
1 parent 1033027 commit 6a94c61

File tree

11 files changed

+45
-52
lines changed

11 files changed

+45
-52
lines changed

pkg/analysis_server/lib/src/lsp/constants.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ abstract final class CustomMethods {
144144
Method('dart/textDocumentContentDidChange');
145145

146146
// TODO(dantup): Remove custom AnalyzerStatus status method soon as no clients
147-
// should be relying on it as we now support proper $/progress events.
147+
// should be relying on it as we now support proper $/progress events.
148148
static const analyzerStatus = Method(r'$/analyzerStatus');
149149

150150
/// Semantic tokens are dynamically registered using a single string

pkg/analysis_server/lib/src/lsp/handlers/commands/fix_all.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import 'package:analysis_server/src/lsp/temporary_overlay_operation.dart';
1616
import 'package:analysis_server/src/services/correction/bulk_fix_processor.dart';
1717
import 'package:analysis_server/src/utilities/source_change_merger.dart';
1818

19-
class FixAllCommandHandler extends SimpleEditCommandHandler
20-
with LspHandlerHelperMixin {
19+
class FixAllCommandHandler extends SimpleEditCommandHandler {
2120
FixAllCommandHandler(super.server);
2221

2322
@override

pkg/analysis_server/lib/src/lsp/handlers/commands/perform_refactor.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import 'package:analysis_server/src/lsp/progress.dart';
1414
import 'package:analysis_server/src/protocol_server.dart';
1515
import 'package:meta/meta.dart';
1616

17-
class PerformRefactorCommandHandler extends AbstractRefactorCommandHandler
18-
with LspHandlerHelperMixin {
17+
class PerformRefactorCommandHandler extends AbstractRefactorCommandHandler {
1918
/// A [Future] used by tests to allow inserting a delay between resolving
2019
/// the initial unit and the refactor running.
2120
@visibleForTesting

pkg/analysis_server/lib/src/lsp/handlers/handler_completion.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ typedef _ScoredCompletionItem = ({CompletionItem item, double score});
4141

4242
class CompletionHandler
4343
extends LspMessageHandler<CompletionParams, CompletionList>
44-
with LspPluginRequestHandlerMixin, LspHandlerHelperMixin {
44+
with LspPluginRequestHandlerMixin {
4545
/// A [Future] used by tests to allow inserting a delay between resolving
4646
/// the initial unit and the completion code running.
4747
@visibleForTesting
@@ -528,7 +528,7 @@ class CompletionHandler
528528
for (var suggestion in candidateSuggestions.suggestions) {
529529
var item = await candidateSuggestionToCompletionItem(suggestion);
530530
if (item != null) {
531-
completionItems.add((item: item, score: suggestion.matcherScore));
531+
completionItems.add((item: item, score: suggestion.matcherScore));
532532
}
533533
}
534534
return completionItems;

pkg/analysis_server/lib/src/lsp/handlers/handler_inlay_hint.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ typedef StaticOptions
1313
= Either3<bool, InlayHintOptions, InlayHintRegistrationOptions>;
1414

1515
class InlayHintHandler
16-
extends LspMessageHandler<InlayHintParams, List<InlayHint>>
17-
with LspHandlerHelperMixin {
16+
extends LspMessageHandler<InlayHintParams, List<InlayHint>> {
1817
InlayHintHandler(super.server);
1918
@override
2019
Method get handlesMessage => Method.textDocument_inlayHint;

pkg/analysis_server/lib/src/lsp/handlers/handler_rename.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ class PrepareRenameHandler extends LspMessageHandler<TextDocumentPositionParams,
9999
}
100100
}
101101

102-
class RenameHandler extends LspMessageHandler<RenameParams, WorkspaceEdit?>
103-
with LspHandlerHelperMixin {
102+
class RenameHandler extends LspMessageHandler<RenameParams, WorkspaceEdit?> {
104103
RenameHandler(super.server);
105104

106105
LspGlobalClientConfiguration get config =>

pkg/analysis_server/lib/src/lsp/handlers/handler_states.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:analysis_server/src/lsp/error_or.dart';
1111
import 'package:analysis_server/src/lsp/handlers/custom/handler_augmentation.dart';
1212
import 'package:analysis_server/src/lsp/handlers/custom/handler_augmented.dart';
1313
import 'package:analysis_server/src/lsp/handlers/custom/handler_connect_to_dtd.dart';
14+
import 'package:analysis_server/src/lsp/handlers/custom/handler_dart_text_document_content_provider.dart';
1415
import 'package:analysis_server/src/lsp/handlers/custom/handler_diagnostic_server.dart';
1516
import 'package:analysis_server/src/lsp/handlers/custom/handler_reanalyze.dart';
1617
import 'package:analysis_server/src/lsp/handlers/custom/handler_super.dart';
@@ -20,7 +21,6 @@ import 'package:analysis_server/src/lsp/handlers/handler_code_actions.dart';
2021
import 'package:analysis_server/src/lsp/handlers/handler_code_lens.dart';
2122
import 'package:analysis_server/src/lsp/handlers/handler_completion.dart';
2223
import 'package:analysis_server/src/lsp/handlers/handler_completion_resolve.dart';
23-
import 'package:analysis_server/src/lsp/handlers/handler_dart_text_document_content_provider.dart';
2424
import 'package:analysis_server/src/lsp/handlers/handler_definition.dart';
2525
import 'package:analysis_server/src/lsp/handlers/handler_document_color.dart';
2626
import 'package:analysis_server/src/lsp/handlers/handler_document_color_presentation.dart';

pkg/analysis_server/lib/src/lsp/handlers/handlers.dart

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,41 @@ mixin HandlerHelperMixin<S extends AnalysisServer> {
8383
ErrorOr<T> analysisFailedError<T>(String path) => error<T>(
8484
ServerErrorCodes.FileAnalysisFailed, 'Analysis failed for file', path);
8585

86+
/// Extracts the current document version from [textDocument] if available,
87+
/// or uses the version that the server has via
88+
/// [LspAnalysisServer.getVersionedDocumentIdentifier].
89+
OptionalVersionedTextDocumentIdentifier extractDocumentVersion(
90+
TextDocumentIdentifier textDocument,
91+
String path,
92+
) {
93+
return switch (textDocument) {
94+
OptionalVersionedTextDocumentIdentifier() => textDocument,
95+
VersionedTextDocumentIdentifier() =>
96+
OptionalVersionedTextDocumentIdentifier(
97+
uri: textDocument.uri, version: textDocument.version),
98+
_ => server.getVersionedDocumentIdentifier(path),
99+
};
100+
}
101+
102+
bool fileHasBeenModified(String path, int? clientVersion) {
103+
var serverDocumentVersion = server.getDocumentVersion(path);
104+
return clientVersion != null && clientVersion != serverDocumentVersion;
105+
}
106+
86107
ErrorOr<T> fileNotAnalyzedError<T>(String path) => error<T>(
87108
ServerErrorCodes.FileNotAnalyzed, 'File is not being analyzed', path);
88109

110+
ErrorOr<LineInfo> getLineInfo(String path) {
111+
var lineInfo = server.getLineInfo(path);
112+
113+
if (lineInfo == null) {
114+
return error(ServerErrorCodes.InvalidFilePath,
115+
'Unable to obtain line information for file', path);
116+
} else {
117+
return success(lineInfo);
118+
}
119+
}
120+
89121
/// Returns whether [doc] is a user-editable document or not.
90122
///
91123
/// Only editable documents have overlays and can be modified by the client.
@@ -254,44 +286,6 @@ mixin HandlerHelperMixin<S extends AnalysisServer> {
254286
}
255287
}
256288

257-
/// Provides some helpers for request handlers to produce common errors or
258-
/// obtain resolved results after waiting for in-progress analysis.
259-
mixin LspHandlerHelperMixin {
260-
LspAnalysisServer get server;
261-
262-
/// Extracts the current document version from [textDocument] if available,
263-
/// or uses the version that the server has via
264-
/// [LspAnalysisServer.getVersionedDocumentIdentifier].
265-
OptionalVersionedTextDocumentIdentifier extractDocumentVersion(
266-
TextDocumentIdentifier textDocument,
267-
String path,
268-
) {
269-
return switch (textDocument) {
270-
OptionalVersionedTextDocumentIdentifier() => textDocument,
271-
VersionedTextDocumentIdentifier() =>
272-
OptionalVersionedTextDocumentIdentifier(
273-
uri: textDocument.uri, version: textDocument.version),
274-
_ => server.getVersionedDocumentIdentifier(path),
275-
};
276-
}
277-
278-
bool fileHasBeenModified(String path, int? clientVersion) {
279-
var serverDocumentVersion = server.getDocumentVersion(path);
280-
return clientVersion != null && clientVersion != serverDocumentVersion;
281-
}
282-
283-
ErrorOr<LineInfo> getLineInfo(String path) {
284-
var lineInfo = server.getLineInfo(path);
285-
286-
if (lineInfo == null) {
287-
return error(ServerErrorCodes.InvalidFilePath,
288-
'Unable to obtain line information for file', path);
289-
} else {
290-
return success(lineInfo);
291-
}
292-
}
293-
}
294-
295289
/// A base class for LSP handlers that require an LSP analysis server and are
296290
/// not supported over the legacy protocol.
297291
abstract class LspMessageHandler<P, R>

pkg/analysis_server/lib/src/lsp/registration/feature_registration.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
import 'package:analysis_server/lsp_protocol/protocol.dart';
66
import 'package:analysis_server/src/lsp/client_capabilities.dart';
77
import 'package:analysis_server/src/lsp/client_configuration.dart';
8+
import 'package:analysis_server/src/lsp/handlers/custom/handler_dart_text_document_content_provider.dart';
89
import 'package:analysis_server/src/lsp/handlers/handler_call_hierarchy.dart';
910
import 'package:analysis_server/src/lsp/handlers/handler_change_workspace_folders.dart';
1011
import 'package:analysis_server/src/lsp/handlers/handler_code_actions.dart';
1112
import 'package:analysis_server/src/lsp/handlers/handler_code_lens.dart';
1213
import 'package:analysis_server/src/lsp/handlers/handler_completion.dart';
13-
import 'package:analysis_server/src/lsp/handlers/handler_dart_text_document_content_provider.dart';
1414
import 'package:analysis_server/src/lsp/handlers/handler_definition.dart';
1515
import 'package:analysis_server/src/lsp/handlers/handler_document_color.dart';
1616
import 'package:analysis_server/src/lsp/handlers/handler_document_highlights.dart';

0 commit comments

Comments
 (0)