6
6
using System . Collections . Immutable ;
7
7
using System . Threading ;
8
8
using System . Threading . Tasks ;
9
+ using Microsoft . CodeAnalysis . Razor . Logging ;
9
10
using Microsoft . CodeAnalysis . Razor . ProjectSystem ;
10
11
using Microsoft . CodeAnalysis . Razor . Utilities ;
11
12
using Microsoft . CodeAnalysis . Razor . Workspaces ;
@@ -29,14 +30,16 @@ internal partial class OpenDocumentGenerator : IRazorStartupService, IDisposable
29
30
private readonly ImmutableArray < IDocumentProcessedListener > _listeners ;
30
31
private readonly IProjectSnapshotManager _projectManager ;
31
32
private readonly LanguageServerFeatureOptions _options ;
33
+ private readonly ILogger _logger ;
32
34
33
35
private readonly AsyncBatchingWorkQueue < IDocumentSnapshot > _workQueue ;
34
36
private readonly CancellationTokenSource _disposeTokenSource ;
35
37
36
38
public OpenDocumentGenerator (
37
39
IEnumerable < IDocumentProcessedListener > listeners ,
38
40
IProjectSnapshotManager projectManager ,
39
- LanguageServerFeatureOptions options )
41
+ LanguageServerFeatureOptions options ,
42
+ ILoggerFactory loggerFactory )
40
43
{
41
44
_listeners = listeners . ToImmutableArray ( ) ;
42
45
_projectManager = projectManager ;
@@ -49,6 +52,7 @@ public OpenDocumentGenerator(
49
52
_disposeTokenSource . Token ) ;
50
53
51
54
_projectManager . Changed += ProjectManager_Changed ;
55
+ _logger = loggerFactory . GetOrCreateLogger < OpenDocumentGenerator > ( ) ;
52
56
}
53
57
54
58
public void Dispose ( )
@@ -88,6 +92,8 @@ private void ProjectManager_Changed(object? sender, ProjectChangeEventArgs args)
88
92
return ;
89
93
}
90
94
95
+ _logger . LogDebug ( $ "Got a project change of type { args . Kind } for { args . ProjectKey . Id } ") ;
96
+
91
97
switch ( args . Kind )
92
98
{
93
99
case ProjectChangeKind . ProjectChanged :
@@ -106,25 +112,11 @@ private void ProjectManager_Changed(object? sender, ProjectChangeEventArgs args)
106
112
}
107
113
108
114
case ProjectChangeKind . DocumentAdded :
109
- {
110
- var newProject = args . Newer . AssumeNotNull ( ) ;
111
- var documentFilePath = args . DocumentFilePath . AssumeNotNull ( ) ;
112
-
113
- if ( newProject . TryGetDocument ( documentFilePath , out var document ) )
114
- {
115
- // We don't enqueue the current document because added documents are initially closed.
116
-
117
- foreach ( var relatedDocument in newProject . GetRelatedDocuments ( document ) )
118
- {
119
- EnqueueIfNecessary ( relatedDocument ) ;
120
- }
121
- }
122
-
123
- break ;
124
- }
125
-
126
115
case ProjectChangeKind . DocumentChanged :
127
116
{
117
+ // Most of the time Add will be called on closed files, but when migrating files to/from the misc files
118
+ // project they could already be open, but with a different generated C# path
119
+
128
120
var newProject = args . Newer . AssumeNotNull ( ) ;
129
121
var documentFilePath = args . DocumentFilePath . AssumeNotNull ( ) ;
130
122
@@ -178,6 +170,8 @@ void EnqueueIfNecessary(IDocumentSnapshot document)
178
170
return ;
179
171
}
180
172
173
+ _logger . LogDebug ( $ "Enqueuing generation of { document . FilePath } in { document . Project . Key . Id } ") ;
174
+
181
175
_workQueue . AddWork ( document ) ;
182
176
}
183
177
}
0 commit comments