diff --git a/vsintegration/src/unittests/TestLib.ProjectSystem.fs b/vsintegration/src/unittests/TestLib.ProjectSystem.fs index 1a6acd05da8c27c31265b119575754c60666a7c9..491298f3c8209bc9cc6efcfa2b570841fe11ca28 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 31bc9df77b03c7c09c847ba63167038319ed5d74..0c2024705255b013401d657004fdaca45125c444 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 316360f1f939e12fface807a8ac80360cbf0d05d..b39523bbff43bc0d0c29ec468501de8c41d22d04 100644 --- a/vsintegration/src/vs/FsPkgs/FSharp.Project/FS/Project.fs +++ b/vsintegration/src/vs/FsPkgs/FSharp.Project/FS/Project.fs @@ -2658,7 +2658,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 @@ -2677,7 +2677,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 ) =