Skip to content

Commit 272d3a4

Browse files
File System Investigation
1 parent 486b396 commit 272d3a4

File tree

4 files changed

+69
-21
lines changed

4 files changed

+69
-21
lines changed

src/Integration.Vsix/AsmRef_Integration.Vsix_Baseline_WithStrongNames.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
################################
33
# Assembly references report
4-
# Report date/time: 2025-11-26T14:59:38.5744338Z
4+
# Report date/time: 2025-12-04T15:25:02.0854015Z
55
################################
66
#
77
# Generated by Devtility CheckAsmRefs v0.11.0.223
@@ -322,6 +322,7 @@ Relative path: 'SonarLint.VisualStudio.SLCore.Listeners.dll'
322322

323323
Referenced assemblies:
324324
- 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
325+
- 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
325326
- 'SonarLint.VisualStudio.ConnectedMode, Version=9.2.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'
326327
- 'SonarLint.VisualStudio.Core, Version=9.2.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'
327328
- 'SonarLint.VisualStudio.IssueVisualization, Version=9.2.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'
@@ -332,7 +333,7 @@ Referenced assemblies:
332333
- 'System.Collections.Immutable, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
333334
- 'System.ComponentModel.Composition, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
334335
- 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
335-
# Number of references: 11
336+
# Number of references: 12
336337

337338
---
338339
Assembly: 'SonarQube.Client, Version=9.2.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244'

src/Integration.Vsix/AsmRef_Integration.Vsix_Baseline_WithoutStrongNames.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
################################
33
# Assembly references report
4-
# Report date/time: 2025-11-26T14:59:38.5744338Z
4+
# Report date/time: 2025-12-04T15:25:02.0854015Z
55
################################
66
#
77
# Generated by Devtility CheckAsmRefs v0.11.0.223
@@ -322,6 +322,7 @@ Relative path: 'SonarLint.VisualStudio.SLCore.Listeners.dll'
322322

323323
Referenced assemblies:
324324
- 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
325+
- 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
325326
- 'SonarLint.VisualStudio.ConnectedMode, Version=9.2.0.0, Culture=neutral, PublicKeyToken=null'
326327
- 'SonarLint.VisualStudio.Core, Version=9.2.0.0, Culture=neutral, PublicKeyToken=null'
327328
- 'SonarLint.VisualStudio.IssueVisualization, Version=9.2.0.0, Culture=neutral, PublicKeyToken=null'
@@ -332,7 +333,7 @@ Referenced assemblies:
332333
- 'System.Collections.Immutable, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
333334
- 'System.ComponentModel.Composition, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
334335
- 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
335-
# Number of references: 11
336+
# Number of references: 12
336337

337338
---
338339
Assembly: 'SonarQube.Client, Version=9.2.0.0, Culture=neutral, PublicKeyToken=null'

src/Integration/LocalServices/FileTracker.cs

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
*/
2020

2121
using System.ComponentModel.Composition;
22+
using System.Reflection;
2223
using Microsoft.VisualStudio.Threading;
24+
using Newtonsoft.Json;
25+
using Newtonsoft.Json.Serialization;
2326
using SonarLint.VisualStudio.Core;
2427
using SonarLint.VisualStudio.Core.ConfigurationScope;
2528
using SonarLint.VisualStudio.SLCore;
@@ -30,10 +33,27 @@
3033

3134
namespace SonarLint.VisualStudio.Integration.LocalServices;
3235

36+
public class IgnoreContent : DefaultContractResolver
37+
{
38+
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
39+
{
40+
var property = base.CreateProperty(member, memberSerialization);
41+
if (property.PropertyName?.ToLower().Contains("content") ?? false)
42+
{
43+
property.ShouldSerialize = i => false;
44+
property.Ignored = true;
45+
}
46+
47+
return property;
48+
}
49+
}
50+
3351
[Export(typeof(IFileTracker))]
3452
[PartCreationPolicy(CreationPolicy.Shared)]
3553
public class FileTracker : IFileTracker
3654
{
55+
private JsonSerializerSettings settings = new JsonSerializerSettings() { ContractResolver = new IgnoreContent() };
56+
3757
private readonly ISLCoreServiceProvider serviceProvider;
3858
private readonly IActiveConfigScopeTracker activeConfigScopeTracker;
3959
private readonly IThreadHandling threadHandling;
@@ -52,7 +72,7 @@ public FileTracker(
5272
this.activeConfigScopeTracker = activeConfigScopeTracker;
5373
this.threadHandling = threadHandling;
5474
this.clientFileDtoFactory = clientFileDtoFactory;
55-
this.logger = logger.ForContext(SLCoreStrings.SLCoreName, SLCoreStrings.FileSubsystem_LogContext, SLCoreStrings.FileTracker_LogContext);
75+
this.logger = logger.ForContext(SLCoreStrings.SLCoreName, SLCoreStrings.FileSubsystem_LogContext, SLCoreStrings.FileTracker_LogContext).ForVerboseContext("FILE SYSTEM INVESTIGATION");
5676
}
5777

5878
public void AddFiles(params SourceFile[] addedFiles)
@@ -73,27 +93,39 @@ public void RenameFiles(string[] beforeRenameFiles, SourceFile[] afterRenameFile
7393

7494
private void NotifySlCoreFilesChanged(string[] removedFiles, SourceFile[] addedOrChangedFiles)
7595
{
76-
if (!serviceProvider.TryGetTransientService(out IFileRpcSLCoreService fileRpcSlCoreService))
96+
try
7797
{
78-
logger.LogVerbose(SLCoreStrings.ServiceProviderNotInitialized);
79-
return;
80-
}
98+
logger.LogVerbose(new MessageLevelContext {VerboseContext = [nameof(addedOrChangedFiles)]}, JsonConvert.SerializeObject(addedOrChangedFiles, Formatting.Indented, settings));
99+
logger.LogVerbose(new MessageLevelContext {VerboseContext = [nameof(removedFiles)]}, JsonConvert.SerializeObject(removedFiles, Formatting.Indented, settings));
81100

82-
if (activeConfigScopeTracker.Current is not { RootPath: not null } configScope)
83-
{
84-
logger.LogVerbose(SLCoreStrings.ConfigScopeNotInitialized);
85-
return;
86-
}
101+
if (!serviceProvider.TryGetTransientService(out IFileRpcSLCoreService fileRpcSlCoreService))
102+
{
103+
logger.LogVerbose(SLCoreStrings.ServiceProviderNotInitialized);
104+
return;
105+
}
106+
107+
if (activeConfigScopeTracker.Current is not { RootPath: not null } configScope)
108+
{
109+
logger.LogVerbose(SLCoreStrings.ConfigScopeNotInitialized);
110+
return;
111+
}
87112

88-
var clientFiles = addedOrChangedFiles.Select(sourceFile => clientFileDtoFactory.CreateOrNull(configScope.Id, configScope.RootPath, sourceFile)).Where(x => x is not null).ToList();
89-
var removedFileUris = removedFiles.Select(f => new FileUri(f)).ToList();
113+
var clientFiles = addedOrChangedFiles.Select(sourceFile => clientFileDtoFactory.CreateOrNull(configScope.Id, configScope.RootPath, sourceFile)).Where(x => x is not null).ToList();
114+
var removedFileUris = removedFiles.Select(f => new FileUri(f)).ToList();
90115

91-
/* we're only sending changed files here as it is complicated to implement the proper tracking of added files
116+
/* we're only sending changed files here as it is complicated to implement the proper tracking of added files
92117
AND `changed` files that were actually added are recognized as added by SLCore
93118
https://github.com/SonarSource/sonarlint-core/pull/1163/files#diff-070e6ef952d4a71245d92ea8f281c5a56050e8992179cde3955d4b1530dff664R152 */
94-
if (removedFileUris.Any() || clientFiles.Any())
119+
if (removedFileUris.Any() || clientFiles.Any())
120+
{
121+
var didUpdateFileSystemParams = new DidUpdateFileSystemParams(removedFileUris, [], clientFiles);
122+
logger.LogVerbose(new MessageLevelContext {VerboseContext = [nameof(didUpdateFileSystemParams)]}, JsonConvert.SerializeObject(didUpdateFileSystemParams, Formatting.Indented, settings));
123+
fileRpcSlCoreService.DidUpdateFileSystem(didUpdateFileSystemParams);
124+
}
125+
}
126+
catch (Exception e)
95127
{
96-
fileRpcSlCoreService.DidUpdateFileSystem(new DidUpdateFileSystemParams(removedFileUris, [], clientFiles));
128+
logger.LogVerbose(e.ToString());
97129
}
98130
}
99131
}

src/SLCore.Listeners/Implementation/ListFilesListener.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
using System.ComponentModel.Composition;
2222
using System.IO;
23+
using Newtonsoft.Json;
2324
using SonarLint.VisualStudio.ConnectedMode.Shared;
2425
using SonarLint.VisualStudio.Core;
2526
using SonarLint.VisualStudio.Core.ConfigurationScope;
@@ -43,9 +44,22 @@ public class ListFilesListener(
4344
ILogger logger)
4445
: IListFilesListener
4546
{
46-
private readonly ILogger logger = logger.ForContext(SLCoreStrings.SLCoreName, SLCoreStrings.FileSubsystem_LogContext, SLCoreStrings.ListFiles_LogContext);
47+
private readonly ILogger logger = logger.ForContext(SLCoreStrings.SLCoreName, SLCoreStrings.FileSubsystem_LogContext, SLCoreStrings.ListFiles_LogContext).ForVerboseContext("FILE SYSTEM INVESTIGATION");
4748

48-
public Task<ListFilesResponse> ListFilesAsync(ListFilesParams parameters) => Task.FromResult(new ListFilesResponse(GetFilesList(parameters)));
49+
public Task<ListFilesResponse> ListFilesAsync(ListFilesParams parameters)
50+
{
51+
try
52+
{
53+
var listFilesResponse = new ListFilesResponse(GetFilesList(parameters));
54+
logger.LogVerbose(JsonConvert.SerializeObject(listFilesResponse, Formatting.Indented));
55+
return Task.FromResult(listFilesResponse);
56+
}
57+
catch (Exception e)
58+
{
59+
logger.LogVerbose(e.ToString());
60+
throw;
61+
}
62+
}
4963

5064
private List<ClientFileDto> GetFilesList(ListFilesParams parameters)
5165
{

0 commit comments

Comments
 (0)