[analysis_server] Enable multiline element descriptions for all hovers

Change-Id: I5521cb09172b5eee639a4d3e9e21eb5871d6a86f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/202971
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Danny Tuppeny 2021-06-13 15:50:32 +00:00 committed by commit-bot@chromium.org
parent 4ce805bfa7
commit d75becf4ac
7 changed files with 37 additions and 17 deletions

View file

@ -109,7 +109,7 @@ a:focus, a:hover {
<body>
<h1>Analysis Server API Specification</h1>
<h1 style="color:#999999">Version
1.32.5
1.32.7
</h1>
<p>
This document contains a specification of the API provided by the
@ -236,6 +236,13 @@ a:focus, a:hover {
ignoring the item or treating it with some default/fallback handling.
</p>
<h3>Changelog</h3>
<h4>1.32.7</h4>
<ul>
<li><tt>HoverInformation.elementDescription</tt> may now include linebreaks to
improve formatting of functions and methods with many parameters. This is not
an API change but may be useful as a signal for clients that previously did their
own formatting.</li>
</ul>
<h4>1.32.6</h4>
<ul>
<li>Added <tt>FoldingKind.PARAMETERS</tt> for folding regions for parameters

View file

@ -6,7 +6,7 @@
// To regenerate the file, use the script
// "pkg/analysis_server/tool/spec/generate_files".
const String PROTOCOL_VERSION = '1.32.5';
const String PROTOCOL_VERSION = '1.32.7';
const String ANALYSIS_NOTIFICATION_ANALYZED_FILES = 'analysis.analyzedFiles';
const String ANALYSIS_NOTIFICATION_ANALYZED_FILES_DIRECTORIES = 'directories';

View file

@ -20,14 +20,8 @@ class DartUnitHoverComputer {
final DartdocDirectiveInfo _dartdocInfo;
final CompilationUnit _unit;
final int _offset;
final bool multilineElementDescriptions;
DartUnitHoverComputer(
this._dartdocInfo,
this._unit,
this._offset, {
this.multilineElementDescriptions = false,
});
DartUnitHoverComputer(this._dartdocInfo, this._unit, this._offset);
/// Returns the computed hover, maybe `null`.
HoverInformation? compute() {
@ -139,7 +133,7 @@ class DartUnitHoverComputer {
String? _elementDisplayString(Element? element) {
return element?.getDisplayString(
withNullability: _unit.isNonNullableByDefault,
multiline: multilineElementDescriptions,
multiline: true,
);
}

View file

@ -88,11 +88,7 @@ class HoverHandler extends MessageHandler<TextDocumentPositionParams, Hover?> {
}
final computer = DartUnitHoverComputer(
server.getDartdocDirectiveInfoFor(unit),
compilationUnit,
offset,
multilineElementDescriptions: true,
);
server.getDartdocDirectiveInfoFor(unit), compilationUnit, offset);
final hover = computer.compute();
return success(toHover(unit.lineInfo, hover));
}

View file

@ -362,6 +362,22 @@ extension E on A {}
expect(hover.propagatedType, isNull);
}
Future<void> test_function_multilineElementDescription() async {
// Functions with at least 3 params will have element descriptions formatted
// across multiple lines.
addTestFile('''
List<String> fff(int a, [String b = 'b', String c = 'c']) {
}
''');
var hover = await prepareHover('fff(int a');
expect(hover.elementDescription, '''
List<String> fff(
int a, [
String b = 'b',
String c = 'c',
])''');
}
Future<void> test_function_topLevel_declaration() async {
addTestFile('''
library my.library;

View file

@ -7,7 +7,7 @@
<body>
<h1>Analysis Server API Specification</h1>
<h1 style="color:#999999">Version
<version>1.32.5</version>
<version>1.32.7</version>
</h1>
<p>
This document contains a specification of the API provided by the
@ -134,6 +134,13 @@
ignoring the item or treating it with some default/fallback handling.
</p>
<h3>Changelog</h3>
<h4>1.32.7</h4>
<ul>
<li><tt>HoverInformation.elementDescription</tt> may now include linebreaks to
improve formatting of functions and methods with many parameters. This is not
an API change but may be useful as a signal for clients that previously did their
own formatting.</li>
</ul>
<h4>1.32.6</h4>
<ul>
<li>Added <tt>FoldingKind.PARAMETERS</tt> for folding regions for parameters

View file

@ -6,7 +6,7 @@
// To regenerate the file, use the script
// "pkg/analysis_server/tool/spec/generate_files".
const String PROTOCOL_VERSION = '1.32.5';
const String PROTOCOL_VERSION = '1.32.7';
const String ANALYSIS_NOTIFICATION_ANALYZED_FILES = 'analysis.analyzedFiles';
const String ANALYSIS_NOTIFICATION_ANALYZED_FILES_DIRECTORIES = 'directories';