GithubHelp home page GithubHelp logo

caphyon / clang-format-editor Goto Github PK

View Code? Open in Web Editor NEW
39.0 39.0 7.0 58.14 MB

Clang-Format Editor is a tool that helps you find the best Clang-Format Style for your C++, C#, Java, JavaScript, and Objective-C code.

Home Page: https://clangpowertools.com/clang-format-editor.html

License: Apache License 2.0

C# 100.00%
clang clang-format cpp csharp formatter java javascript llvm objective-c

clang-format-editor's People

Contributors

cpp-red-lion avatar heartacker avatar hprica avatar mariru27 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

clang-format-editor's Issues

Configurator crash

  1. Insert this code into the Configurator.
  2. Turn on any option.
  3. Application crashes in few seconds.
#include "pch.h"
#include "CppUnitTest.h"
#include "../HelloWorldUnitTestCPP/HelloWorldUnitTestCPP.cpp"   // Update using your project name

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace HelloWorldTests
{
   TEST_CLASS(HelloWorldTests)
   {
   public:

      TEST_METHOD(TestMethod)
      {
         std::string expected = "Hello World!\n";

         std::stringstream buffer;
         std::streambuf* sbuf = std::cout.rdbuf(); // Save cout's buffer
         std::cout.rdbuf(buffer.rdbuf()); // Redirect cout to the stringstream buffer

         // Call main() in your test
         int result = main();

         // When finished, redirect cout to the original buffer 
         std::cout.rdbuf(sbuf);
         std::cout << "std original buffer: \n";
         std::cout << buffer.get();

         // Test
         Assert::AreEqual(expected, buffer.str());
      }
   };
}

Struct declaration with weird comments can crash the editor

Example

//comment
EmptyStruct emptyStruct = EmptyStruct{}; //1 space after ';'' otherwise: ;//1 space after...

Description

Crashes upon trying to format. Removing either //comment or //1 space after ';'' otherwise: ;//1 space after... will not crash.

Crash info

image

System.ArgumentOutOfRangeException
  HResult=0x80131502
  Message=Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
  Source=System.Private.CoreLib
  StackTrace:
   at System.ThrowHelper.ThrowArgumentOutOfRange_IndexException()
   at System.Collections.Generic.List`1.get_Item(Int32 index)
   at ClangFormatEditor.DiffMatchPatchWrapper.DetectOperationPerLine(String input, String output, List`1 inputOperationPerLine, List`1 outputOperationPerLine) in C:\Users\Lucy\Downloads\clang-format-editor\ClangFormatEditor\DiffStyle\DiffMatchPatchWrapper.cs:line 209
   at ClangFormatEditor.DiffMatchPatchWrapper.DiffAsFlowDocuments(String input, String output) in C:\Users\Lucy\Downloads\clang-format-editor\ClangFormatEditor\DiffStyle\DiffMatchPatchWrapper.cs:line 153
   at ClangFormatEditor.MVVM.Controllers.DiffController.<CreateFlowDocumentAsync>d__13.MoveNext() in C:\Users\Lucy\Downloads\clang-format-editor\ClangFormatEditor\MVVM\Controllers\DiffController.cs:line 78
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at ClangFormatEditor.ConfiguratorViewModel.<RunFormatAsync>d__77.MoveNext() in C:\Users\Lucy\Downloads\clang-format-editor\ClangFormatEditor\MVVM\ViewModel\ConfiguratorViewModel.cs:line 301
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
   at ClangFormatEditor.TaskExtensions.<SafeFireAndForget>d__0.MoveNext() in C:\Users\Lucy\Downloads\clang-format-editor\ClangFormatEditor\Extensions\TaskExtensions.cs:line 25

  This exception was originally thrown at this call stack:
    [External Code]
    ClangFormatEditor.DiffMatchPatchWrapper.DetectOperationPerLine(string, string, System.Collections.Generic.List<(object, ClangFormatEditor.DiffMatchPatchWrapper.LineChanges)>, System.Collections.Generic.List<(object, ClangFormatEditor.DiffMatchPatchWrapper.LineChanges)>) in DiffMatchPatchWrapper.cs
    ClangFormatEditor.DiffMatchPatchWrapper.DiffAsFlowDocuments(string, string) in DiffMatchPatchWrapper.cs
    ClangFormatEditor.MVVM.Controllers.DiffController.CreateFlowDocumentAsync(string, ClangFormatEditor.Enums.FormatStyle, System.Collections.Generic.List<ClangFormatEditor.Interfaces.IFormatOption>, System.Threading.CancellationToken) in DiffController.cs
    [External Code]
    ClangFormatEditor.ConfiguratorViewModel.RunFormatAsync() in ConfiguratorViewModel.cs
    [External Code]
    ClangFormatEditor.TaskExtensions.SafeFireAndForget(System.Threading.Tasks.Task, bool, System.Action<System.Exception>) in TaskExtensions.cs

Autos

  Name Value Type
  continueOnCapturedContext true bool
task Id = 748, Status = Faulted, Method = "{null}", Result = "{Not yet computed}" System.Threading.Tasks.Task {System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.AsyncStateMachineBox<ClangFormatEditor.ConfiguratorViewModel.d__77>}
  AsyncState null object
  CancellationPending false bool
  CreationOptions None System.Threading.Tasks.TaskCreationOptions
  ▶ Exception Count = 1 System.Exception {System.AggregateException}
  Id 748 int
  Result {System.Threading.Tasks.VoidTaskResult} System.Threading.Tasks.VoidTaskResult
  Status Faulted System.Threading.Tasks.TaskStatus
  ◢ Raw View    
  AsyncState null object
  ▶ Context null System.Threading.ExecutionContext
  CreationOptions None System.Threading.Tasks.TaskCreationOptions
  ▶ Exception Count = 1 System.AggregateException
  Id 748 int
  IsCanceled false bool
  IsCompleted true bool
  IsCompletedSuccessfully false bool
  IsFaulted true bool
  ▶ MoveNextAction {Method = {Void MoveNext()}} System.Action
  StateMachine null ClangFormatEditor.ConfiguratorViewModel.d__77
  Status Faulted System.Threading.Tasks.TaskStatus
  ◢ Static members    
  ◢ CompletedTask Id = 764, Status = RanToCompletion, Method = "{null}", Result = "System.Threading.Tasks.VoidTaskResult" System.Threading.Tasks.Task {System.Threading.Tasks.Task<System.Threading.Tasks.VoidTaskResult>}
  AsyncState null object
  CancellationPending false bool
  CreationOptions None System.Threading.Tasks.TaskCreationOptions
  ▶ Exception null System.Exception
  Id 764 int
  Result {System.Threading.Tasks.VoidTaskResult} System.Threading.Tasks.VoidTaskResult
  Status RanToCompletion System.Threading.Tasks.TaskStatus
  ▶ Raw View    
  CurrentId null int?
  ▶ Factory (System.Threading.Tasks.Task) {System.Threading.Tasks.TaskFactory} System.Threading.Tasks.TaskFactory
  ▶ Factory {System.Threading.Tasks.TaskFactory<System.Threading.Tasks.VoidTaskResult>} System.Threading.Tasks.TaskFactory<System.Threading.Tasks.VoidTaskResult>
  ▶ Non-Public members    
  ◢ Non-Public members    
  ▶ CancellationToken IsCancellationRequested = false System.Threading.CancellationToken
  ▶ CapturedContext {System.Threading.ExecutionContext} System.Threading.ExecutionContext
  ▶ CompletedEvent Set = true System.Threading.ManualResetEventSlim
  DebuggerDisplayMethodDescription (System.Threading.Tasks.Task) "{null}" string
  DebuggerDisplayMethodDescription "{null}" string
  DebuggerDisplayResultDescription "{Not yet computed}" string
  ExceptionRecorded true bool
  ▶ ExecutingTaskScheduler null System.Threading.Tasks.TaskScheduler
  IsCancellationAcknowledged false bool
  IsCancellationRequested false bool
  IsDelegateInvoked false bool
  IsExceptionObservedByParent false bool
  IsWaitNotificationEnabled false bool
  IsWaitNotificationEnabledOrNotRanToCompletion true bool
  Options 1024 System.Threading.Tasks.TaskCreationOptions
  ▶ ParentForDebugger null System.Threading.Tasks.Task
  ResultOnSuccess {System.Threading.Tasks.VoidTaskResult} System.Threading.Tasks.VoidTaskResult
  ShouldNotifyDebuggerOfWaitCompletion false bool
  StateFlagsForDebugger 102761472 int
  ▶ System.IAsyncResult.AsyncWaitHandle {System.Threading.ManualResetEvent} System.Threading.WaitHandle {System.Threading.ManualResetEvent}
  System.IAsyncResult.CompletedSynchronously false bool
  ▶ _moveNextAction {Method = {Void MoveNext()}} System.Action
  m_action null System.Delegate
  ▶ m_contingentProperties {System.Threading.Tasks.Task.ContingentProperties} System.Threading.Tasks.Task.ContingentProperties
  m_continuationObject {object} object
  m_result {System.Threading.Tasks.VoidTaskResult} System.Threading.Tasks.VoidTaskResult
  m_stateFlags 102761472 int
  m_stateObject null object
  m_taskId 748 int
  ▶ m_taskScheduler null System.Threading.Tasks.TaskScheduler

tabsize in style detector

Is it possible to change the default tabsize (8) to an other value. My sources use a tabsize of 4 and I can't get a usable result.

Enable format detector's diff view in format editor

I would like to use the diff view from the clang format detector also in the clang format editor.

The current view in the format editor with two separate tabs for unformatted and reformatted file makes it really hard to discuss changes to format settings on an existing code project with your colleagues.
You cannot even show the two tabs side by side. Therefore you have to continuously switch between tabs to figure out all the differences that your change to the format file caused. The diff view would solve that problem.

Error message when switching between predefined styles

I'm not sure if it only happens to me or not, to reproduce this, type something in the Quick search input field at the top left, for example, Align. then try to switch between Google and LLVM in the Select Style dropdown. You'll get a strange error message box that doesn't make sense:

Object reference not set to an instance of an object
Alt: Object reference not set to an instance of an object.

Offtopic: What's the timeline like, for upgrading to .NET 7 and LLVM/ClangFormat 15?

Crash when input lines exceeded max padding

Nice app, thanks for it!

I got a crash when some lines exceeded 600 chars or so: then I tried a quick fix into DaPa@b511cd2

Then I also made a change to avoid padding, as I saw it unnecessary (just my taste) so instead I opted to trim ending white spaces (DaPa@3e170ed): but not sure if there are side effects (not sure if this padding is required in certain scenarios).

Improved usability for Detector - user feedback

The splitter in the two pane view can't be moved, it would be better if the two sections were resizable. There are no legends to indicate what the different colours mean. It would be nice if you clicked inside one of the coloured areas and then this synchronised the Style Option that is producing the change. It would be nice if we could change the text font that the code is using, I prefer Consolas There are so many clang-format options that it is hard to know which one is doing what (obviously the many options are from the Clang-Format codebase rather than your editor, it is just to point out it is hard to know what to change without being able to synchronise the change to the style option. Its a great start, thanks guys for producing this software

Crash due to EqualizeDocumentLength() sometimes result in unequal lengths

The function DetectOperationPerLine() tries to equalize the length of the incoming document strings if their length is unequal.

bool equalTexts = inputLines.Count == outputLines.Count;
if (equalTexts == false)
{
// Both inputLines and outputLines must be equal. The method is run on both
// This is done my adding lines that contain just Environment.NewLine to the inputLines and outputLines
try
{
inputLines = EqualizeDocumentLength(output, input);
outputLines = EqualizeDocumentLength(input, output);
}
catch (Exception e)
{
MessageBox.Show(e.Message, "Clang-Format Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
for (int index = 0; index < outputLines.Count; index++)
{
var lineDiffs = GetDiff(inputLines[index], outputLines[index]);

However, there is no check to make sure that resulting strings are actually equal after the functions EqualizeDocumentLength have been run.

If the resulting list outputLines have more elements than then resulting list inputLines this will cause a crash inside the for-loop, since the GetDiff() function will try to index the inputLines variable outside outside the available list range.

My temporary fix was to skip elements outside the list range inside the for-loop:

      for (int index = 0; index < outputLines.Count; index++)
      {
        if (index >= inputLines.Count)
        {
            continue;
        }
        ...

However, the issue should probably be fixed inside the EqualizeDocumentLength() function.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.