Skip to content

Commit

Permalink
adjust how we select the 500 completion results to return (#2774)
Browse files Browse the repository at this point in the history
* adjust how we select the 500 completion results to return

* remove suggestion sorting
  • Loading branch information
devoncarew committed Dec 27, 2023
1 parent 16a54ac commit 2cd8956
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
19 changes: 9 additions & 10 deletions pkgs/dart_services/lib/src/analysis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,13 @@ class AnalysisServerWrapper {
}

Future<api.CompleteResponse> complete(String source, int offset) async {
const maxResults = 500;

final results = await _completeImpl(
{kMainDart: source},
kMainDart,
offset,
maxResults: maxResults,
);

final suggestions =
Expand All @@ -149,14 +152,6 @@ class AnalysisServerWrapper {
}

return false;
}).toList();

suggestions.sort((CompletionSuggestion x, CompletionSuggestion y) {
if (x.relevance == y.relevance) {
return x.completion.compareTo(y.completion);
} else {
return y.relevance.compareTo(x.relevance);
}
});

return api.CompleteResponse(
Expand Down Expand Up @@ -359,13 +354,17 @@ class AnalysisServerWrapper {
}

Future<Suggestions2Result> _completeImpl(
Map<String, String> sources, String sourceName, int offset) async {
Map<String, String> sources,
String sourceName,
int offset, {
required int maxResults,
}) async {
await _loadSources(_getOverlayMapWithPaths(sources));

return await analysisServer.completion.getSuggestions2(
_getPathFromName(sourceName),
offset,
500,
maxResults,
);
}

Expand Down
7 changes: 4 additions & 3 deletions pkgs/dart_services/test/src/sample_code.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

const sampleCode = '''
void main() {
print("hello");
print('hello');
}
''';

const sampleCodeWeb = """
import 'dart:html';
void main() {
print("hello");
print('hello');
querySelector('#foo')?.text = 'bar';
}
""";
Expand Down Expand Up @@ -114,6 +114,7 @@ class _MyHomePageState extends State<MyHomePage> {
// From https://gist.github.com/RedBrogdon/e0a2e942e85fde2cd39b2741ff0c49e5
const sampleCodeFlutterSunflower = r'''
import 'dart:math' as math;
import 'package:flutter/material.dart';
const Color primaryColor = Colors.orange;
Expand Down Expand Up @@ -254,7 +255,7 @@ const sampleCodeFlutterDraggableCard = '''
import 'package:flutter/material.dart';
import 'package:flutter/physics.dart';
main() {
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
Expand Down

0 comments on commit 2cd8956

Please sign in to comment.