1919 */
2020
2121using System . ComponentModel . Composition ;
22+ using System . Reflection ;
2223using Microsoft . VisualStudio . Threading ;
24+ using Newtonsoft . Json ;
25+ using Newtonsoft . Json . Serialization ;
2326using SonarLint . VisualStudio . Core ;
2427using SonarLint . VisualStudio . Core . ConfigurationScope ;
2528using SonarLint . VisualStudio . SLCore ;
3033
3134namespace 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 ) ]
3553public 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}
0 commit comments