diff --git a/vsintegration/src/unittests/TestLib.ProjectSystem.fs b/vsintegration/src/unittests/TestLib.ProjectSystem.fs index 1a6acd05da8..491298f3c82 100644 --- a/vsintegration/src/unittests/TestLib.ProjectSystem.fs +++ b/vsintegration/src/unittests/TestLib.ProjectSystem.fs @@ -170,7 +170,7 @@ type TheTests() = | x -> x match TryFind node with | Some(x) -> x - | None -> failwith "did not find node with caption %s" caption + | None -> failwithf "did not find node with caption %s" caption static member MoveDown(node : HierarchyNode) = match node with diff --git a/vsintegration/src/unittests/Tests.ProjectSystem.Project.fs b/vsintegration/src/unittests/Tests.ProjectSystem.Project.fs index a26c17afa78..9f35257c3c0 100644 --- a/vsintegration/src/unittests/Tests.ProjectSystem.Project.fs +++ b/vsintegration/src/unittests/Tests.ProjectSystem.Project.fs @@ -695,6 +695,68 @@ type Project() = File.Delete(absFilePath) )) + [] //ref bug https://github.com/Microsoft/visualfsharp/issues/259 + member public this.``RenameFile.InFolder``() = + this.MakeProjectAndDo(["file1.fs"; @"Folder1\file2.fs"; @"Folder1\nested1.fs"], [], "", (fun project -> + let absFilePath = Path.Combine(project.ProjectFolder, "Folder1", "nested1.fs") + try + Directory.CreateDirectory(Path.GetDirectoryName(absFilePath)) |> ignore; + File.AppendAllText(absFilePath, "#light") + let orig1 = TheTests.FindNodeWithCaption(project, "nested1.fs") + let folder1 = TheTests.FindNodeWithCaption(project, "Folder1") + VsMocks.vsRunningDocumentTableFindAndLockDocumentVsHierarchyMock <- project + + let added, deleted = ResizeArray(), ResizeArray() + + let sink = + { new IVsHierarchyEvents with + member x.OnInvalidateIcon _hicon = VSConstants.S_OK + member x.OnInvalidateItems _itemidParent = VSConstants.S_OK + member x.OnItemAdded (itemidParent, itemidSiblingPrev, itemidAdded) = + added.Add(itemidParent, itemidSiblingPrev, itemidAdded) + VSConstants.S_OK + member x.OnItemDeleted (itemid) = + deleted.Add(itemid) + VSConstants.S_OK + member x.OnItemsAppended (itemidParent) = + VSConstants.S_OK + member x.OnPropertyChanged (itemid, propid, flags) = + VSConstants.S_OK } + + let cookie = ref 0u + project.AdviseHierarchyEvents(sink, cookie) |> ErrorHandler.ThrowOnFailure |> ignore + + // rename the file + orig1.SetEditLabel("renamedNested2.fs") |> ErrorHandler.ThrowOnFailure |> ignore + + SaveProject project + + let file2 = TheTests.FindNodeWithCaption (project, "file2.fs") + let renamedNested2 = TheTests.FindNodeWithCaption (project, "renamedNested2.fs") + + AssertEqual [ folder1.ID, file2.ID, renamedNested2.ID ] (added |> Seq.distinct |> List.ofSeq) + AssertEqual [ orig1.ID ] (deleted |> Seq.distinct |> List.ofSeq) + + // TODO ensure IVsTrackProjectDocumentsEvents Renamed was fired + + // ensure right in .fsproj + let msbuildInfo = TheTests.MsBuildCompileItems(project.BuildProject) + AssertEqual ["file1.fs"; @"Folder1\file2.fs"; @"Folder1\renamedNested2.fs"] msbuildInfo + + // ensure right in solution explorer + let expect = + Tree("References", ANYTREE, + Tree("file1.fs", Nil, + Tree("Folder1", + Tree("file2.fs", Nil, + Tree("renamedNested2.fs", Nil, Nil)), + Nil))) + TheTests.AssertSameTree (expect, project.FirstChild) + + finally + if File.Exists(absFilePath) then File.Delete(absFilePath) + )) + [] member public this.``RenameFile.BuildActionIsResetBasedOnFilenameExtension``() = let GetTextFromBuildAction (action:VSLangProj.prjBuildAction) = diff --git a/vsintegration/src/vs/FsPkgs/FSharp.Project/FS/Project.fs b/vsintegration/src/vs/FsPkgs/FSharp.Project/FS/Project.fs index 17181fe6540..512a7d441e7 100644 --- a/vsintegration/src/vs/FsPkgs/FSharp.Project/FS/Project.fs +++ b/vsintegration/src/vs/FsPkgs/FSharp.Project/FS/Project.fs @@ -2663,7 +2663,7 @@ See also ...\SetupAuthoring\FSharp\Registry\FSProjSys_Registration.wxs, e.g. nodeBeforeMe.NextSibling <- lastNode lastNode.NextSibling <- thisNode - root.OnItemAdded(root, lastNode) + root.OnItemAdded(lastNode.Parent, lastNode) lastNode :?> FSharpFileNode /// In solution explorer, move the last of my siblings to just below me, return the moved FSharpFileNode @@ -2682,7 +2682,7 @@ See also ...\SetupAuthoring\FSharp\Registry\FSProjSys_Registration.wxs, e.g. let tmp = target.NextSibling target.NextSibling <- lastNode lastNode.NextSibling <- tmp - root.OnItemAdded(root, lastNode) + root.OnItemAdded(lastNode.Parent, lastNode) lastNode :?> FSharpFileNode override x.ExecCommandOnNode(guidCmdGroup:Guid, cmd:uint32, nCmdexecopt:uint32, pvaIn:IntPtr, pvaOut:IntPtr ) =