anchor.diff:  
                         {
                           Kind = "helptext"
  -                        Data =
  -                          {
  -                            HelpText = [ for d in decls.Items do
  -                                           yield d.Name, TipFormatter.formatTip d.DescriptionText ]
  -                                       |> Map.ofList
  -                          }
  +                        Data = [ for d in decls.Items do
  +                                   yield d.Name, TipFormatter.formatTip d.DescriptionText ]
  +                               |> Map.ofList
                         }
                         |> JsonConvert.SerializeObject
                         |> Console.WriteLine
                         
  -              | None -> printfn "ERROR: Could not get type information\n<<EOF>>"
  +              | None -> 
  +                  printMsg "ERROR" "Could not get type information"
   
             | ToolTip ->
                 let tipopt = agent.GetToolTip(opts, pos, state.Files.[file].[line], timeout)
   
                 match tipopt with
  -              | None -> printfn "INFO: Could not fetch tooltip\n<<EOF>>"
  +              | None -> printMsg "INFO" "No tooltip information"
                 | Some tip ->
                 match tip with
                 | DataTipText(elems) when elems |> List.forall (function
                   DataTipElementNone -> true | _ -> false) ->
  -                printfn "ERROR: No tooltip information\n<<EOF>>"
  +                printMsg "INFO" "No tooltip information"
                 | _ ->
  -                  Console.WriteLine("DATA: tooltip")
  -                  Console.WriteLine(TipFormatter.formatTip tip)
  -                  Console.WriteLine("<<EOF>>")
  +                  match state.OutputMode with
  +                  | Text ->
  +                    Console.WriteLine("DATA: tooltip")
  +                    Console.WriteLine(TipFormatter.formatTip tip)
  +                    Console.WriteLine("<<EOF>>")
  +                  | Json -> { Kind = "tooltip"; Data = TipFormatter.formatTip tip }
  +                            |> JsonConvert.SerializeObject
  +                            |> Console.WriteLine
             
             | FindDeclaration ->
   
               match agent.FindDeclaration(opts, pos, state.Files.[file].[line], timeout) with
               | None
  -            | Some (DeclNotFound _) -> printfn "ERROR: Could not get find declaration\n<<EOF>>"
  +            | Some (DeclNotFound _) -> printMsg "ERROR" "Could not find declaration"
               | Some (DeclFound ((line,col),file)) ->
                 
                 printfn "DATA: finddecl\n%s:%d:%d\n<<EOF>>" file line col
  
positive.code:                      file,
                       text)
  
  
      // Debug.print "main state is:\nproject: %b\nfiles: %A\nmode: %A"
      //             (Option.isSome state.Project)
  
negative.code:                                     file,
                                      text)
            agent.TriggerParseRequest(opts, full)
            printMsg "INFO" "Background parsing started"
            main { state with Files = Map.add file lines state.Files }
          else
            printMsg "ERROR" (sprintf "File '%s' does not exist" file)
            main state
  
      | Project file ->
          // Load project file and store in state
          if File.Exists file then
            match ProjectParser.load file with
            | Some p -> 
                let files =
                  [ for f in ProjectParser.getFiles p do
                      yield IO.Path.Combine(ProjectParser.getDirectory p, f) ]
                match state.OutputMode with
                | Text ->
                    printfn "DATA: project\n%s\n<<EOF>>" (String.concat "\n" files)
                | Json ->
                    { Kind = "project"; Data = files }
                    |> JsonConvert.SerializeObject |> Console.WriteLine
                main { state with Project = Some p }
            | None   -> printMsg "ERROR" (sprintf "Project file '%s' is invalid" file)
                        main state
          else
            printMsg "ERROR" (sprintf "File '%s' does not exist" file)
            main state
  
      | Declarations file ->
          let file = Path.GetFullPath file
          if parsed file then
            let decls = agent.GetDeclarations(getoptions file)
            let declstrings =
              [ for tld in decls do
                  let (s1, e1), (s2, e2) = tld.Declaration.Range
                  yield sprintf "[%d:%d-%d:%d] %s" e1 s1 e2 s2 tld.Declaration.Name
                  for d in tld.Nested do
                    let (s1, e1), (s2, e2) = d.Range
                    yield sprintf "  - [%d:%d-%d:%d] %s" e1 s1 e2 s2 d.Name ]
            match state.OutputMode with
            | Text -> printfn "DATA: declarations\n%s\n<<EOF>>" (String.concat "\n" declstrings)
            | Json -> { Kind = "declarations"; Data = decls }
                      |> JsonConvert.SerializeObject |> Console.WriteLine
          main state
  
      | PosCommand(cmd, file, ((line, col) as pos), timeout) ->
  