@@ -320,23 +320,18 @@ internal void RemoveDocument(DocumentId documentId)
320320 OnDocumentRemoved ( documentId ) ;
321321 }
322322
323- /// <summary>
324- /// Razor (.cshtml) needs to be able to add C# documents to a project that are not backed by a file on disk.
325- /// As these don't come from the project system, we need to keep track of these documents to readd them
326- /// manually every time the project is reloaded from disk.
327- /// </summary>
328- internal ProjectInfo AddVirtualDocuments ( ProjectInfo projectInfo )
329- {
330- lock ( virtualDocuments ) {
331- var virtualDocumentsToAdd = virtualDocuments . Where ( d => d . Id . ProjectId == projectInfo . Id ) ;
332- if ( virtualDocumentsToAdd . Any ( ) ) {
333- projectInfo = projectInfo . WithDocuments ( projectInfo . Documents . Concat ( virtualDocumentsToAdd ) ) ;
334- }
335- }
336-
337- return projectInfo ;
338- }
339-
323+ /// <summary>
324+ /// Razor (.cshtml) needs to be able to add C# documents to a project that are not backed by a file on disk.
325+ /// As these don't come from the project system, we need to keep track of these documents to readd them
326+ /// manually every time the project is loaded from disk.
327+ /// </summary>
328+ internal IEnumerable < DocumentInfo > GetVirtualDocuments ( ProjectId projectId )
329+ {
330+ lock ( virtualDocuments ) {
331+ return virtualDocuments . Where ( d => d . Id . ProjectId == projectId ) . ToList ( ) ;
332+ }
333+ }
334+
340335 // This is called by OnProjectRemoved.
341336 protected override void ClearProjectData ( ProjectId projectId )
342337 {
@@ -513,7 +508,6 @@ async Task ReloadProjects (CancellationToken cancellationToken)
513508 OnProjectAdded ( projectInfo ) ;
514509 } else {
515510 lock ( projectModifyLock ) {
516- projectInfo = AddVirtualDocuments ( projectInfo ) ;
517511 OnProjectReloaded ( projectInfo ) ;
518512 }
519513 }
@@ -1514,8 +1508,6 @@ void OnProjectModified (object sender, MonoDevelop.Projects.SolutionItemModified
15141508 try {
15151509 lock ( projectModifyLock ) {
15161510 ProjectInfo newProjectContents = t . Result ;
1517- newProjectContents = WithDynamicDocuments ( project , newProjectContents ) ;
1518- newProjectContents = AddVirtualDocuments ( newProjectContents ) ;
15191511 OnProjectReloaded ( newProjectContents ) ;
15201512 foreach ( var docId in GetOpenDocumentIds ( newProjectContents . Id ) . ToArray ( ) ) {
15211513 if ( CurrentSolution . GetDocument ( docId ) == null ) {
@@ -1538,11 +1530,28 @@ void OnProjectModified (object sender, MonoDevelop.Projects.SolutionItemModified
15381530 }
15391531 }
15401532
1541- internal ProjectInfo WithDynamicDocuments ( MonoDevelop . Projects . DotNetProject project , ProjectInfo projectInfo )
1533+ internal ProjectInfo WithDynamicDocuments ( MonoDevelop . Projects . Project project , ProjectInfo projectInfo )
15421534 {
1543- var contentItems = project . MSBuildProject . EvaluatedItems . Where ( item => item . Name == "Content" && item . Include . EndsWith ( ".razor" , StringComparison . OrdinalIgnoreCase ) ) . Select ( item => item . Include ) ;
1535+ var projectDirectory = Path . GetDirectoryName ( project . FileName ) ;
1536+
1537+ var contentItems = project . MSBuildProject . EvaluatedItems
1538+ . Where ( item => item . Name == "Content" && item . Include . EndsWith ( ".razor" , StringComparison . OrdinalIgnoreCase ) )
1539+ . Select ( item => GetAbsolutePath ( item . Include ) )
1540+ . ToList ( ) ;
15441541
1545- return dynamicFileManager ? . UpdateDynamicFiles ( projectInfo , contentItems , this ) ;
1542+ return dynamicFileManager ? . UpdateDynamicFiles ( projectInfo , contentItems , this ) ;
1543+
1544+ string GetAbsolutePath ( string relativePath )
1545+ {
1546+ if ( ! Path . IsPathRooted ( relativePath ) ) {
1547+ relativePath = Path . Combine ( projectDirectory , relativePath ) ;
1548+ }
1549+
1550+ // normalize the path separator characters in case they're mixed
1551+ relativePath = relativePath . Replace ( '\\ ' , Path . DirectorySeparatorChar ) ;
1552+
1553+ return relativePath ;
1554+ }
15461555 }
15471556
15481557 internal override void SetDocumentContext ( DocumentId documentId )
0 commit comments