@@ -59,49 +59,45 @@ private async Task AddDocumentToMiscProjectNeedsLocksAsync(string filePath, Canc
59
59
60
60
_logger . LogDebug ( $ "Adding { filePath } to the miscellaneous files project, because we don't have project info (yet?)") ;
61
61
var miscFilesProject = await _snapshotResolver . GetMiscellaneousProjectAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
62
- await AddDocumentToProjectAsync ( miscFilesProject , textDocumentPath , cancellationToken ) . ConfigureAwait ( false ) ;
63
62
64
- async Task AddDocumentToProjectAsync ( IProjectSnapshot projectSnapshot , string textDocumentPath , CancellationToken cancellationToken )
63
+ if ( miscFilesProject . GetDocument ( FilePathNormalizer . Normalize ( textDocumentPath ) ) is not null )
65
64
{
66
- if ( projectSnapshot . GetDocument ( FilePathNormalizer . Normalize ( textDocumentPath ) ) is not null )
67
- {
68
- // Document already added. This usually occurs when VSCode has already pre-initialized
69
- // open documents and then we try to manually add all known razor documents.
70
- return ;
71
- }
65
+ // Document already added. This usually occurs when VSCode has already pre-initialized
66
+ // open documents and then we try to manually add all known razor documents.
67
+ return ;
68
+ }
72
69
73
- var targetFilePath = textDocumentPath ;
74
- var projectDirectory = FilePathNormalizer . GetNormalizedDirectoryName ( projectSnapshot . FilePath ) ;
75
- if ( targetFilePath . StartsWith ( projectDirectory , FilePathComparison . Instance ) )
76
- {
77
- // Make relative
78
- targetFilePath = textDocumentPath [ projectDirectory . Length ..] ;
79
- }
70
+ var targetFilePath = textDocumentPath ;
71
+ var projectDirectory = FilePathNormalizer . GetNormalizedDirectoryName ( miscFilesProject . FilePath ) ;
72
+ if ( targetFilePath . StartsWith ( projectDirectory , FilePathComparison . Instance ) )
73
+ {
74
+ // Make relative
75
+ targetFilePath = textDocumentPath [ projectDirectory . Length ..] ;
76
+ }
80
77
81
- // Representing all of our host documents with a re-normalized target path to workaround GetRelatedDocument limitations.
82
- var normalizedTargetFilePath = targetFilePath . Replace ( '/' , '\\ ' ) . TrimStart ( '\\ ' ) ;
78
+ // Representing all of our host documents with a re-normalized target path to workaround GetRelatedDocument limitations.
79
+ var normalizedTargetFilePath = targetFilePath . Replace ( '/' , '\\ ' ) . TrimStart ( '\\ ' ) ;
83
80
84
- var hostDocument = new HostDocument ( textDocumentPath , normalizedTargetFilePath ) ;
85
- var textLoader = _remoteTextLoaderFactory . Create ( textDocumentPath ) ;
81
+ var hostDocument = new HostDocument ( textDocumentPath , normalizedTargetFilePath ) ;
82
+ var textLoader = _remoteTextLoaderFactory . Create ( textDocumentPath ) ;
86
83
87
- _logger . LogInformation ( $ "Adding document '{ filePath } ' to project '{ projectSnapshot . Key } '.") ;
84
+ _logger . LogInformation ( $ "Adding document '{ filePath } ' to project '{ miscFilesProject . Key } '.") ;
88
85
89
- await _projectManager
90
- . UpdateAsync (
91
- static ( updater , state ) => updater . DocumentAdded ( state . key , state . hostDocument , state . textLoader ) ,
92
- state : ( key : projectSnapshot . Key , hostDocument , textLoader ) ,
93
- cancellationToken )
94
- . ConfigureAwait ( false ) ;
86
+ await _projectManager
87
+ . UpdateAsync (
88
+ static ( updater , state ) => updater . DocumentAdded ( state . key , state . hostDocument , state . textLoader ) ,
89
+ state : ( key : miscFilesProject . Key , hostDocument , textLoader ) ,
90
+ cancellationToken )
91
+ . ConfigureAwait ( false ) ;
95
92
96
- // Adding a document to a project could also happen because a target was added to a project, or we're moving a document
97
- // from Misc Project to a real one, and means the newly added document could actually already be open.
98
- // If it is, we need to make sure we start generating it so we're ready to handle requests that could start coming in.
99
- if ( _projectManager . IsDocumentOpen ( textDocumentPath ) &&
100
- _projectManager . TryGetLoadedProject ( projectSnapshot . Key , out var project ) &&
101
- project . GetDocument ( textDocumentPath ) is { } document )
102
- {
103
- _ = document . GetGeneratedOutputAsync ( ) ;
104
- }
93
+ // Adding a document to a project could also happen because a target was added to a project, or we're moving a document
94
+ // from Misc Project to a real one, and means the newly added document could actually already be open.
95
+ // If it is, we need to make sure we start generating it so we're ready to handle requests that could start coming in.
96
+ if ( _projectManager . IsDocumentOpen ( textDocumentPath ) &&
97
+ _projectManager . TryGetLoadedProject ( miscFilesProject . Key , out var project ) &&
98
+ project . GetDocument ( textDocumentPath ) is { } document )
99
+ {
100
+ _ = document . GetGeneratedOutputAsync ( ) ;
105
101
}
106
102
}
107
103
0 commit comments