Skip to content

Commit 6f359e9

Browse files
fixing F5 issue + scheme for invalidating the context+scanner caches.
1 parent 119ce13 commit 6f359e9

4 files changed

Lines changed: 38 additions & 8 deletions

File tree

src/RustAnalyzer/Debugger/DebugLaunchTargetProvider.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public bool SupportsContext(IWorkspace workspaceContext, string targetFilePath)
4545

4646
private async Task LaunchDebugTargetAsync(IWorkspace workspaceContext, IServiceProvider serviceProvider, LaunchConfigWrapper lcw, CancellationToken ct)
4747
{
48+
const string diagMessage = "Delete the .vs folder and try again. If that does not work please file a bug with the repro steps.";
4849
try
4950
{
5051
var mds = workspaceContext.GetService<IMetadataService>();
@@ -54,20 +55,20 @@ private async Task LaunchDebugTargetAsync(IWorkspace workspaceContext, IServiceP
5455
var target = package.GetTargets().FirstOrDefault(t => t.QualifiedTargetFileName == targetFQN);
5556
if (target == null)
5657
{
57-
string message = string.Format("Cannot find target '{0}' in '{1}', for profile '{2}'. This indicates a bug in the manifest parsing logic. Unable to start debugging.", targetFQN, package?.FullPath, profile);
58+
string message = string.Format("Cannot find target '{0}' in '{1}', for profile '{2}'.", targetFQN, package?.FullPath, profile);
5859
L.WriteError(message);
5960
T.TrackException(new ArgumentOutOfRangeException("target", message));
60-
await VsCommon.ShowMessageBoxAsync(message, "Try again after deleting the .vs folder. If that does not work please file a bug.");
61+
await VsCommon.ShowMessageBoxAsync(message, diagMessage);
6162
return;
6263
}
6364

6465
var processName = target.GetPath(profile);
6566
if (!File.Exists(processName))
6667
{
67-
var message = string.Format("Unable to find file: '{0}'. This indicates a bug with the Manifest parsing logic. Unable to start debugging.", processName);
68+
var message = string.Format("Unable to find file: '{0}'.", processName);
6869
L.WriteLine(message);
6970
T.TrackException(new FileNotFoundException(message, processName));
70-
await VsCommon.ShowMessageBoxAsync(message, "Try again after deleting the .vs folder. If that does not work please file a bug.");
71+
await VsCommon.ShowMessageBoxAsync(message, diagMessage);
7172
return;
7273
}
7374

src/RustAnalyzer/Editor/FileContextProviderFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ namespace KS.RustAnalyzer.Editor;
1414
supportedContextTypeGuids: new[] { BuildContextTypes.BuildContextType, BuildContextTypes.CleanContextType, })]
1515
public sealed class FileContextProviderFactory : IWorkspaceProviderFactory<IFileContextProvider>
1616
{
17-
public static readonly Guid ProviderTypeGuid = new(ProviderType);
17+
public const string ProviderType = "72D3FCEF-0001-4266-B8DD-D3ED06E35A2B";
1818

19-
private const string ProviderType = "{72D3FCEF-0000-4266-B8DD-D3ED06E35A2B}";
19+
public static readonly Guid ProviderTypeGuid = new(ProviderType);
2020

2121
[Import]
2222
public IBuildOutputSink OutputPane { get; set; }

src/RustAnalyzer/Editor/FileScanner.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Linq;
45
using System.Threading;
56
using System.Threading.Tasks;
7+
using KS.RustAnalyzer.TestAdapter;
68
using KS.RustAnalyzer.TestAdapter.Cargo;
79
using KS.RustAnalyzer.TestAdapter.Common;
810
using Microsoft.VisualStudio.Workspace;
@@ -12,7 +14,7 @@
1214

1315
namespace KS.RustAnalyzer.Editor;
1416

15-
public class FileScanner : IFileScanner
17+
public class FileScanner : IFileScanner, IFileScannerUpToDateCheck
1618
{
1719
private readonly IMetadataService _mds;
1820

@@ -46,6 +48,32 @@ public async Task<T> ScanContentAsync<T>(string filePath, CancellationToken canc
4648
}
4749
}
4850

51+
public virtual async Task<bool> IsUpToDateAsync(DateTimeOffset? lastScanTimestamp, string filePath, FileScannerType scannerType, CancellationToken cancellationToken)
52+
{
53+
if (await IsValidFileAsync(filePath))
54+
{
55+
try
56+
{
57+
var lastWrite = File.GetLastWriteTimeUtc(filePath);
58+
return lastScanTimestamp.HasValue && lastWrite < lastScanTimestamp.Value.UtcDateTime;
59+
}
60+
catch (Exception exc) when (exc is IOException || exc is UnauthorizedAccessException)
61+
{
62+
// We have already loaded the file in VS,
63+
// so any I/O related exceptions are very unlikely
64+
// and we def. don't want to crash VS on that.
65+
}
66+
}
67+
68+
return false;
69+
}
70+
71+
private Task<bool> IsValidFileAsync(string filePath)
72+
{
73+
var ext = ((PathEx)filePath).GetExtension();
74+
return (ext.Equals(Constants.RustFileExtension) || ext.Equals(Constants.ManifestFileExtension)).ToTask();
75+
}
76+
4977
private List<FileDataValue> GetFileDataValues(Workspace.Package package, PathEx filePath)
5078
{
5179
var allFileDataValues = new List<FileDataValue>();

src/RustAnalyzer/Editor/FileScannerFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ namespace KS.RustAnalyzer.Editor;
1717
priority: ProviderPriority.Normal)]
1818
public class FileScannerFactory : IWorkspaceProviderFactory<IFileScanner>
1919
{
20-
public const string ProviderType = "F5628EAD-0000-4683-B597-D8314B971ED6";
20+
public const string ProviderType = "F5628EAD-0001-4683-B597-D8314B971ED6";
21+
2122
public static readonly Guid ProviderTypeGuid = new(ProviderType);
2223

2324
[Import]

0 commit comments

Comments
 (0)