mirror of
https://github.com/dart-lang/sdk
synced 2024-09-19 21:01:50 +00:00
Add CiderCompletionResult.performance
Change-Id: I5df913afc99fc253282611472dc3ff48b9abb8c8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/149785 Reviewed-by: Keerti Parthasarathy <keertip@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
155ebfa92a
commit
5c0c41cc68
|
@ -26,7 +26,6 @@ import 'package:meta/meta.dart';
|
|||
/// example types and elements.
|
||||
class CiderCompletionCache {
|
||||
final Map<String, _CiderImportedLibrarySuggestions> _importedLibraries = {};
|
||||
_LastCompletionResult _lastResult;
|
||||
}
|
||||
|
||||
class CiderCompletionComputer {
|
||||
|
@ -56,30 +55,23 @@ class CiderCompletionComputer {
|
|||
@required int line,
|
||||
@required int column,
|
||||
}) async {
|
||||
var getFileTimer = Stopwatch()..start();
|
||||
var fileContext = _logger.run('Get file $path', () {
|
||||
return _fileResolver.getFileContext(path);
|
||||
try {
|
||||
return _fileResolver.getFileContext(path);
|
||||
} finally {
|
||||
getFileTimer.stop();
|
||||
}
|
||||
});
|
||||
|
||||
var file = fileContext.file;
|
||||
|
||||
var resolvedSignature = _logger.run('Get signature', () {
|
||||
return file.resolvedSignature;
|
||||
});
|
||||
|
||||
var lineInfo = file.lineInfo;
|
||||
var offset = lineInfo.getOffsetOfLine(line) + column;
|
||||
|
||||
// If the same file, in the same state as the last time, reuse the result.
|
||||
var lastResult = _cache._lastResult;
|
||||
if (lastResult != null &&
|
||||
lastResult.path == path &&
|
||||
lastResult.signature == resolvedSignature &&
|
||||
lastResult.offset == offset) {
|
||||
_logger.writeln('Use the last completion result.');
|
||||
return lastResult.result;
|
||||
}
|
||||
|
||||
var resolutionTimer = Stopwatch()..start();
|
||||
var resolvedUnit = _fileResolver.resolve(path);
|
||||
resolutionTimer.stop();
|
||||
|
||||
var completionRequest = CompletionRequestImpl(
|
||||
resolvedUnit,
|
||||
|
@ -129,10 +121,13 @@ class CiderCompletionComputer {
|
|||
});
|
||||
|
||||
var result = CiderCompletionResult._(
|
||||
suggestions, CiderPosition(line, column - filter._pattern.length));
|
||||
|
||||
_cache._lastResult =
|
||||
_LastCompletionResult(path, resolvedSignature, offset, result);
|
||||
suggestions: suggestions,
|
||||
performance: CiderCompletionPerformance(
|
||||
file: getFileTimer.elapsed,
|
||||
resolution: resolutionTimer.elapsed,
|
||||
),
|
||||
prefixStart: CiderPosition(line, column - filter._pattern.length),
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -196,15 +191,34 @@ class CiderCompletionComputer {
|
|||
}
|
||||
}
|
||||
|
||||
class CiderCompletionPerformance {
|
||||
/// The elapsed time for file access.
|
||||
final Duration file;
|
||||
|
||||
/// The elapsed time for resolution.
|
||||
final Duration resolution;
|
||||
|
||||
CiderCompletionPerformance({
|
||||
@required this.file,
|
||||
@required this.resolution,
|
||||
});
|
||||
}
|
||||
|
||||
class CiderCompletionResult {
|
||||
final List<CompletionSuggestion> suggestions;
|
||||
|
||||
final CiderCompletionPerformance performance;
|
||||
|
||||
/// The start of the range that should be replaced with the suggestion. This
|
||||
/// position always precedes or is the same as the cursor provided in the
|
||||
/// completion request.
|
||||
final CiderPosition prefixStart;
|
||||
|
||||
CiderCompletionResult._(this.suggestions, this.prefixStart);
|
||||
CiderCompletionResult._({
|
||||
@required this.suggestions,
|
||||
@required this.performance,
|
||||
@required this.prefixStart,
|
||||
});
|
||||
}
|
||||
|
||||
class CiderPosition {
|
||||
|
@ -289,12 +303,3 @@ class _FuzzyScoredSuggestion {
|
|||
|
||||
_FuzzyScoredSuggestion(this.suggestion, this.score);
|
||||
}
|
||||
|
||||
class _LastCompletionResult {
|
||||
final String path;
|
||||
final String signature;
|
||||
final int offset;
|
||||
final CiderCompletionResult result;
|
||||
|
||||
_LastCompletionResult(this.path, this.signature, this.offset, this.result);
|
||||
}
|
||||
|
|
|
@ -75,21 +75,6 @@ import 'dart:math';
|
|||
expect(_completionResult.prefixStart.column, 0);
|
||||
}
|
||||
|
||||
Future<void> test_compute_sameSignature_sameResult() async {
|
||||
await _compute(r'''
|
||||
var a = ^;
|
||||
''');
|
||||
var lastResult = _completionResult;
|
||||
|
||||
// Ask for completion using new resolver and computer.
|
||||
// But the file signature is the same, so the same result.
|
||||
_createFileResolver();
|
||||
await _compute(r'''
|
||||
var a = ^;
|
||||
''');
|
||||
expect(_completionResult, same(lastResult));
|
||||
}
|
||||
|
||||
Future<void> test_compute_updateImportedLibrary() async {
|
||||
var aPath = convertPath('/workspace/dart/test/lib/a.dart');
|
||||
newFile(aPath, content: r'''
|
||||
|
|
Loading…
Reference in a new issue