From 2cd8956e7faa11e75906af4cbbe91b62e1bd3676 Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Wed, 27 Dec 2023 10:57:38 -0800 Subject: [PATCH] adjust how we select the 500 completion results to return (#2774) * adjust how we select the 500 completion results to return * remove suggestion sorting --- pkgs/dart_services/lib/src/analysis.dart | 19 +++++++++---------- pkgs/dart_services/test/src/sample_code.dart | 7 ++++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pkgs/dart_services/lib/src/analysis.dart b/pkgs/dart_services/lib/src/analysis.dart index 538c842d6..ea44ba135 100644 --- a/pkgs/dart_services/lib/src/analysis.dart +++ b/pkgs/dart_services/lib/src/analysis.dart @@ -121,10 +121,13 @@ class AnalysisServerWrapper { } Future complete(String source, int offset) async { + const maxResults = 500; + final results = await _completeImpl( {kMainDart: source}, kMainDart, offset, + maxResults: maxResults, ); final suggestions = @@ -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( @@ -359,13 +354,17 @@ class AnalysisServerWrapper { } Future _completeImpl( - Map sources, String sourceName, int offset) async { + Map sources, + String sourceName, + int offset, { + required int maxResults, + }) async { await _loadSources(_getOverlayMapWithPaths(sources)); return await analysisServer.completion.getSuggestions2( _getPathFromName(sourceName), offset, - 500, + maxResults, ); } diff --git a/pkgs/dart_services/test/src/sample_code.dart b/pkgs/dart_services/test/src/sample_code.dart index b2299c8ea..329196999 100644 --- a/pkgs/dart_services/test/src/sample_code.dart +++ b/pkgs/dart_services/test/src/sample_code.dart @@ -4,7 +4,7 @@ const sampleCode = ''' void main() { - print("hello"); + print('hello'); } '''; @@ -12,7 +12,7 @@ const sampleCodeWeb = """ import 'dart:html'; void main() { - print("hello"); + print('hello'); querySelector('#foo')?.text = 'bar'; } """; @@ -114,6 +114,7 @@ class _MyHomePageState extends State { // 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; @@ -254,7 +255,7 @@ const sampleCodeFlutterDraggableCard = ''' import 'package:flutter/material.dart'; import 'package:flutter/physics.dart'; -main() { +void main() { runApp( MaterialApp( debugShowCheckedModeBanner: false,