public static XDocument FormatXml(string text, uint offset, uint length, uint cursor, ClangFormatSettings settings)
{
var startInfo = new ProcessStartInfo();
var resultText = string.Empty;
startInfo.FileName = Path.Combine(Platform.PluginsDirectory, "clang-format" + Platform.ExecutableExtension);
startInfo.Arguments = string.Format("-offset={0} -length={1} -cursor={2} -style=\"{3}\" -output-replacements-xml",
offset, length, cursor, settings);
// Hide console window
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true; //we can get the erros text now.
startInfo.RedirectStandardInput = true;
startInfo.CreateNoWindow = true;
using (var process = Process.Start(startInfo))
{
using (var streamWriter = process.StandardInput)
{
streamWriter.Write(text);
streamWriter.Close();
using (var streamReader = process.StandardOutput)
{
resultText = streamReader.ReadToEnd();
}
}
}
return XDocument.Parse(resultText);
}
}