[PATCH] D70633: clang-format-vs : Fix Unicode formatting

2019-11-25 Thread empty2fill via Phabricator via cfe-commits
empty2fill added a comment.

In D70633#1758372 , @hans wrote:

> klimek, What do you think?
>
> empty2fill: Do you have an example input that I could use to hit the 
> "Specified argument was out of the range of valid values." error?


F10867396: Main.cpp 

Encoded Windows code page 949 for the Korean language.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70633/new/

https://reviews.llvm.org/D70633



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70632: clang-format-vs : Fix typo NUGET_EXE_DIR on README

2019-11-25 Thread empty2fill via Phabricator via cfe-commits
empty2fill added a comment.

In D70632#1758572 , @hans wrote:

> Thanks!
>
> Do you have commit access, or if not would you like me to commit on your 
> behalf?


Commit on my behalf please. Thank you.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70632/new/

https://reviews.llvm.org/D70632



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70633: clang-format-vs : Fix Unicode Replacements

2019-11-23 Thread empty2fill via Phabricator via cfe-commits
empty2fill created this revision.
empty2fill added reviewers: clang-format, hans.
empty2fill added a project: clang-format.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Use UTF-8 for communication with clang-format and convert the replacements 
offset/length to characters position/count.

Internally VisualStudio.Text.Editor.IWpfTextView use sequence of Unicode 
characters encoded using UTF-16 and use characters position/count for 
manipulating text.

Resolved "Error while running clang-format: Specified argument was out of the 
range of valid values. Parameter name: replaceSpan".


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70633

Files:
  clang/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs

Index: clang/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs
===
--- clang/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs
+++ clang/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs
@@ -24,6 +24,7 @@
 using System.Runtime.InteropServices;
 using System.Xml.Linq;
 using System.Linq;
+using System.Text;
 
 namespace LLVM.ClangFormat
 {
@@ -292,8 +293,7 @@
 string text = view.TextBuffer.CurrentSnapshot.GetText();
 int start = view.Selection.Start.Position.GetContainingLine().Start.Position;
 int end = view.Selection.End.Position.GetContainingLine().End.Position;
-int length = end - start;
-
+
 // clang-format doesn't support formatting a range that starts at the end
 // of the file.
 if (start >= text.Length && text.Length > 0)
@@ -301,7 +301,7 @@
 string path = Vsix.GetDocumentParent(view);
 string filePath = Vsix.GetDocumentPath(view);
 
-RunClangFormatAndApplyReplacements(text, start, length, path, filePath, options, view);
+RunClangFormatAndApplyReplacements(text, start, end, path, filePath, options, view);
 }
 
 /// 
@@ -336,11 +336,11 @@
 RunClangFormatAndApplyReplacements(text, 0, text.Length, path, filePath, options, view);
 }
 
-private void RunClangFormatAndApplyReplacements(string text, int offset, int length, string path, string filePath, OptionPageGrid options, IWpfTextView view)
+private void RunClangFormatAndApplyReplacements(string text, int start, int end, string path, string filePath, OptionPageGrid options, IWpfTextView view)
 {
 try
 {
-string replacements = RunClangFormat(text, offset, length, path, filePath, options);
+string replacements = RunClangFormat(text, start, end, path, filePath, options);
 ApplyClangFormatReplacements(replacements, view);
 }
 catch (Exception e)
@@ -363,9 +363,9 @@
 /// 
 /// Runs the given text through clang-format and returns the replacements as XML.
 /// 
-/// Formats the text range starting at offset of the given length.
+/// Formats the text in range start and end.
 /// 
-private static string RunClangFormat(string text, int offset, int length, string path, string filePath, OptionPageGrid options)
+private static string RunClangFormat(string text, int start, int end, string path, string filePath, OptionPageGrid options)
 {
 string vsixPath = Path.GetDirectoryName(
 typeof(ClangFormatPackage).Assembly.Location);
@@ -373,6 +373,9 @@
 System.Diagnostics.Process process = new System.Diagnostics.Process();
 process.StartInfo.UseShellExecute = false;
 process.StartInfo.FileName = vsixPath + "\\clang-format.exe";
+char[] chars = text.ToCharArray();
+int offset = Encoding.UTF8.GetByteCount(chars, 0, start);
+int length = Encoding.UTF8.GetByteCount(chars, 0, end) - offset;
 // Poor man's escaping - this will not work when quotes are already escaped
 // in the input (but we don't need more).
 string style = options.Style.Replace("\"", "\\\"");
@@ -413,10 +416,11 @@
 // 2. We write everything to the standard output - this cannot block, as clang-format
 //reads the full standard input before analyzing it without writing anything to the
 //standard output.
-process.StandardInput.Write(text);
+StreamWriter utf8Writer = new StreamWriter(process.StandardInput.BaseStream, new UTF8Encoding(false));
+utf8Writer.Write(text);
 // 3. We notify clang-format that the input is done - after this point clang-format
 //will start analyzing the input and eventually write the output.
-process.StandardInput.Close();
+utf8Writer.Close();
 // 4. We must read clang-format's output before waiting for it to exit; clang-fo

[PATCH] D70632: clang-format-vs : Fix typo NUGET_EXE_DIR on README

2019-11-22 Thread empty2fill via Phabricator via cfe-commits
empty2fill created this revision.
empty2fill added a reviewer: hans.
empty2fill added a project: clang-format.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Match with the CMake variable.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70632

Files:
  clang/tools/clang-format-vs/README.txt


Index: clang/tools/clang-format-vs/README.txt
===
--- clang/tools/clang-format-vs/README.txt
+++ clang/tools/clang-format-vs/README.txt
@@ -10,12 +10,12 @@
 
 - BUILD_CLANG_FORMAT_VS_PLUGIN=ON
 
-- NUGET_EXE_PATH=path/to/nuget_dir (unless nuget.exe is already available in 
PATH)
+- NUGET_EXE_DIR=path/to/nuget_dir (unless nuget.exe is already available in 
PATH)
 
 example:
   cd /d C:\code\llvm
   mkdir build & cd build
-  cmake -DBUILD_CLANG_FORMAT_VS_PLUGIN=ON -DNUGET_EXE_PATH=C:\nuget ..
+  cmake -DBUILD_CLANG_FORMAT_VS_PLUGIN=ON -DNUGET_EXE_DIR=C:\nuget ..
 
 Once LLVM.sln is generated, build the clang_format_vsix target, which will 
build
 ClangFormat.sln, the C# extension application.


Index: clang/tools/clang-format-vs/README.txt
===
--- clang/tools/clang-format-vs/README.txt
+++ clang/tools/clang-format-vs/README.txt
@@ -10,12 +10,12 @@
 
 - BUILD_CLANG_FORMAT_VS_PLUGIN=ON
 
-- NUGET_EXE_PATH=path/to/nuget_dir (unless nuget.exe is already available in PATH)
+- NUGET_EXE_DIR=path/to/nuget_dir (unless nuget.exe is already available in PATH)
 
 example:
   cd /d C:\code\llvm
   mkdir build & cd build
-  cmake -DBUILD_CLANG_FORMAT_VS_PLUGIN=ON -DNUGET_EXE_PATH=C:\nuget ..
+  cmake -DBUILD_CLANG_FORMAT_VS_PLUGIN=ON -DNUGET_EXE_DIR=C:\nuget ..
 
 Once LLVM.sln is generated, build the clang_format_vsix target, which will build
 ClangFormat.sln, the C# extension application.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits