Skip to content

Commit

Permalink
fix rename file inside folder
Browse files Browse the repository at this point in the history
closes dotnet#40
fixes dotnet#259

commit ba30762
Author: enricosada <enrico@sada.io>
Date:   Fri Apr 3 15:15:34 2015 +0200

    add test

commit 732b1b5
Author: enricosada <enrico@sada.io>
Date:   Thu Apr 2 00:52:13 2015 +0200

    fix rename file inside folder
  • Loading branch information
enricosada authored and latkin committed Apr 8, 2015
1 parent f237018 commit b748533
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
2 changes: 1 addition & 1 deletion vsintegration/src/unittests/TestLib.ProjectSystem.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 62 additions & 0 deletions vsintegration/src/unittests/Tests.ProjectSystem.Project.fs
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,68 @@ type Project() =
File.Delete(absFilePath)
))

[<Test>] //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)
))

[<Test>]
member public this.``RenameFile.BuildActionIsResetBasedOnFilenameExtension``() =
let GetTextFromBuildAction (action:VSLangProj.prjBuildAction) =
Expand Down
4 changes: 2 additions & 2 deletions vsintegration/src/vs/FsPkgs/FSharp.Project/FS/Project.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ) =
Expand Down

0 comments on commit b748533

Please sign in to comment.