Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 0de2455

Browse files
DanTupcommit-bot@chromium.org
authored andcommitted
Fix modifications stamps for modified files
Bug: Dart-Code/Dart-Code#2286 (comment) Change-Id: Ibb49a3b244ca40da5018fd705adffdbe6e0ce880 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/154960 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Danny Tuppeny <[email protected]>
1 parent 2e6dd67 commit 0de2455

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ class LspAnalysisServer extends AbstractAnalysisServer {
336336
}
337337

338338
void onOverlayCreated(String path, String content) {
339-
resourceProvider.setOverlay(path, content: content, modificationStamp: 0);
339+
resourceProvider.setOverlay(path,
340+
content: content, modificationStamp: overlayModificationStamp++);
340341

341342
_afterOverlayChanged(path, plugin.AddContentOverlay(content));
342343
}
@@ -361,7 +362,7 @@ class LspAnalysisServer extends AbstractAnalysisServer {
361362
}
362363

363364
resourceProvider.setOverlay(path,
364-
content: newContent, modificationStamp: 0);
365+
content: newContent, modificationStamp: overlayModificationStamp++);
365366

366367
_afterOverlayChanged(path, plugin.ChangeContentOverlay(edits));
367368
}

pkg/analysis_server/test/lsp/completion_test.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,41 @@ main() {
976976
'''));
977977
}
978978

979+
/// This test reproduces a bug where the pathKey hash used in
980+
/// available_declarations.dart would not change with the contents of the file
981+
/// (as it always used 0 as the modification stamp) which would prevent
982+
/// completion including items from files that were open (had overlays).
983+
/// https://github.com/Dart-Code/Dart-Code/issues/2286#issuecomment-658597532
984+
Future<void> test_suggestionSets_modifiedFiles() async {
985+
final otherFilePath = join(projectFolderPath, 'lib', 'other_file.dart');
986+
final otherFileUri = Uri.file(otherFilePath);
987+
988+
final mainFileContent = 'MyOtherClass^';
989+
final initialAnalysis = waitForAnalysisComplete();
990+
await initialize(
991+
workspaceCapabilities:
992+
withApplyEditSupport(emptyWorkspaceClientCapabilities));
993+
await openFile(mainFileUri, withoutMarkers(mainFileContent));
994+
await initialAnalysis;
995+
996+
// Start with a blank file.
997+
newFile(otherFilePath, content: '');
998+
await openFile(otherFileUri, '');
999+
await pumpEventQueue(times: 5000);
1000+
1001+
// Reopen the file with a class definition.
1002+
await closeFile(otherFileUri);
1003+
await openFile(otherFileUri, 'class MyOtherClass {}');
1004+
await pumpEventQueue(times: 5000);
1005+
1006+
// Ensure the class appears in completion.
1007+
final completions =
1008+
await getCompletion(mainFileUri, positionFromMarker(mainFileContent));
1009+
final matching =
1010+
completions.where((c) => c.label == 'MyOtherClass').toList();
1011+
expect(matching, hasLength(1));
1012+
}
1013+
9791014
Future<void> test_suggestionSets_namedConstructors() async {
9801015
newFile(
9811016
join(projectFolderPath, 'other_file.dart'),

0 commit comments

Comments
 (0)