anchor.diff:              (Rename.GetErrorMessage (Some position, Some newName) source "test.fs").Value
           raise (RefactoringFailure errorMessage)
   
  -let ExtractFunction filename (startPosition,endPosition) functionName =
  +let ExtractFunction filename range functionName =
       let source = getSource filename
  -    let tree = (Ast.Parse source).Value
  -    let expressionRange = mkRange "test.fs" startPosition endPosition
  -    let inScopeTree = DefaultInScopeTree tree expressionRange
  -    if Option.isNone (TryFindExpressionAtRange expressionRange tree) then
  -        raise (ArgumentException "No expression found at the given range")
  -    elif Option.isNone inScopeTree then
  -        raise (ArgumentException "Could not find a suitable expression to use as the function's scope")
  +    if ExtractFunction.IsValid (Some range, Some functionName) source "test.fs" then
  +        ExtractFunction.Transform (range, functionName) source "test.fs"
       else
  -        DoExtractFunction source tree (Ast.AstNode.Expression inScopeTree.Value) expressionRange functionName
  +        let errorMessage =
  +            (ExtractFunction.GetErrorMessage (Some range, Some functionName) source "test.fs").Value
  +        raise (RefactoringFailure errorMessage)
   
   let AddArgument filename position argumentName defaultValue =
       let source = getSource filename
  
positive.code:     printfn "  -oFILENAME, --output-file=FILENAME  Write result to FILENAME"
  
  
  
  let parsePos (positionString : string) =
      let m = Regex.Match(positionString, "([0-9]+):([0-9]+)")
      if m.Success then
          let line = Int32.Parse m.Groups.[1].Value
          let column = Int32.Parse m.Groups.[2].Value
          mkPos line (column-1)
      else raise (ArgumentException (sprintf "%s is not a valid position" positionString))
  
  let parsePosition (positionString : string) =
      let m = Regex.Match(positionString, "([0-9]+):([0-9]+)")
      if m.Success then
  
negative.code: open FSharpRefactor.Engine.CodeAnalysis.ScopeAnalysis
  open FSharpRefactor.Engine.Refactoring
  open FSharpRefactor.Refactorings
  open FSharpRefactor.Refactorings
  
  exception ArgumentException of string
  
  