bitst0rm-pub / Formatter

🧜‍♀️ A Sublime Text plugin to beautify, minify, convert code: CSS, SCSS, Sass, HTML, XML, SVG,JS,JavaScript, JSON, GraphQL, Markdown, TypeScript, Vue, Lua, YAML, Go, Perl, PHP, Python, Ruby, Rust, Haskell, Dart, Swift, Crystal, Bash, Shell, SQL, CSV, C, C++, C#, Objective-C, D, Java, Pawn, Julia, Blade, LaTeX, D2, Graphviz, Mermaid, PlantUML, etc
Other
105 stars 22 forks source link

The formatter is using dummy than the actual file #44

Closed h2110100 closed 9 months ago

h2110100 commented 9 months ago

Firstly. Here is the error from the debug console

"StatementAttributeLikeMacros": ["Q_EMIT"], "StatementMacros": ["Q_UNUSED", "QT_REQUIRE_VERSION"], "TabWidth": 8, "UseCRLF": false, "UseTab": "Never", "WhitespaceSensitiveMacros": ["STRINGIZE", "PP_STRINGIZE", "BOOST_PP_STRINGIZE", "NS_SWIFT_NAME", "CF_SWIFT_NAME"]}', '--assume-filename', 'dummy.cpp'] Formatter: [ERROR] File not formatted due to an error (exitcode=255): "The filename, directory name, or volume label syntax is incorrect.

Here is my settings.js: `{ // Enable debug mode to view errors in the console. "debug": true,

// Auto open the console panel whenever formatting failed.
// This is useful when combined with "debug": true
"open_console_on_failure": true,

// Display results in the status bar.
// The displayed abbreviation for the current settings mode:
// PUS: Persistent User Settings
// PQO: Persistent Quick Options
// TQO: Temporary Quick Options
"show_statusbar": true,

// Display a real-time word and character count in the status bar.
// By default, whitespace is not included in the character count.
"show_words_count": {
    "enable": true,
    "ignore_whitespace_char": true
},

// Remember and restore cursor position, selections and bookmarks
// each time a file is closed and re-opened.
// This is helpful to resume your work from where you left off.
// It does not remember the whole session as one might assume.
"remember_session": true,
// THIRD-PARTY PLUGINS LEVEL
"formatters": {
    "clangformat": {
        "info": "https://clang.llvm.org/docs/ClangFormat.html",
        "disable": false,
        "format_on_save": true,
        "format_on_paste": true,
        "new_file_on_format": false,
        "recursive_folder_format": {
            "enable": false,
            "exclude_folders_regex": [],
            "exclude_files_regex": [],
            "exclude_extensions": [],
            "exclude_syntaxes": []
        },
        "syntaxes": ["c", "cs", "c++", "cpp", "css", "objc", "objc++", "js", "tsx", "jsx", "json", "java", "proto", "protodevel", "td", "sv", "svh", "v", "vh"],
        "executable_path": "C:\\Program Files\\Clang\\clang-format\\clang-format.exe",
        "config_path": {
            "default": "${packages}\\User\\formatter.assets\\config\\clang_format_google_rc.yaml"
        }
    },
    "yapf": {
        "info": "https://github.com/google/yapf",
        "disable": false,
        "format_on_save": true,
        "format_on_paste": true,
        "new_file_on_format": false,
        "recursive_folder_format": {
            "enable": false,
            "exclude_folders_regex": [],
            "exclude_files_regex": [],
            "exclude_extensions": [],
            "exclude_syntaxes": []
        },
        "syntaxes": ["python"],
        "executable_path": "Program Files\\miniconda\\Scripts\\yapf.exe",
        "config_path": {
            "default": "${packages}\\User\\formatter.assets\\config\\yapf_rc.yapf"
        }
    }
}

}`

Secondly, everytime I save and exit sublime text, the settings file return back to the demo one.

h2110100 commented 9 months ago

Here's is the full error

[Formatter](Thread-4:common.py#L709): [INFO] Current mode: Quick Options: 
{
    "debug": true,
    "format_on_unique": true,
    "format_on_paste": [
        "clangformat"
    ],
    "format_on_save": [
        "clangformat"
    ]
}
▋[Formatter](Thread-4:formatter.py#L36): [DEBUG] Target: D:\IO\Code\codebreaker.cpp
▋[Formatter](Thread-4:formatter.py#L37): [DEBUG] Scope: source.c++ meta.preprocessor.include.c++ keyword.control.import.include.c++ 
▋[Formatter](Thread-4:formatter.py#L38): [DEBUG] Syntax: c++
▋[Formatter](Thread-4:formatter.py#L39): [DEBUG] Formatter ID: clangformat
▋[Formatter](Thread-4:common.py#L291): [DEBUG] User executable found: C:\Program Files\Clang\clang-format\clang-format.exe
▋[Formatter](Thread-4:common.py#L402): [DEBUG] Config [default]: C:\Users\The Fool\AppData\Roaming\Sublime Text\Packages\User\formatter.assets\config\clang_format_google_rc.yaml
▋[Formatter](Thread-4:formatter_clangformat.py#L83): [DEBUG] Current arguments: ['C:\\Program Files\\Clang\\clang-format\\clang-format.exe', '--style', '{"AccessModifierOffset": -1, "AlignAfterOpenBracket": "Align", "AlignArrayOfStructures": "None", "AlignConsecutiveAssignments": {"Enabled": false, "AcrossEmptyLines": false, "AcrossComments": false, "AlignCompound": false, "PadOperators": true}, "AlignConsecutiveBitFields": {"Enabled": false, "AcrossEmptyLines": false, "AcrossComments": false, "AlignCompound": false, "PadOperators": false}, "AlignConsecutiveDeclarations": {"Enabled": false, "AcrossEmptyLines": false, "AcrossComments": false, "AlignCompound": false, "PadOperators": false}, "AlignConsecutiveMacros": {"Enabled": false, "AcrossEmptyLines": false, "AcrossComments": false, "AlignCompound": false, "PadOperators": false}, "AlignEscapedNewlines": "Left", "AlignOperands": "Align", "AlignTrailingComments": true, "AllowAllArgumentsOnNextLine": true, "AllowAllParametersOfDeclarationOnNextLine": true, "AllowShortEnumsOnASingleLine": true, "AllowShortBlocksOnASingleLine": "Never", "AllowShortCaseLabelsOnASingleLine": false, "AllowShortFunctionsOnASingleLine": "All", "AllowShortLambdasOnASingleLine": "All", "AllowShortIfStatementsOnASingleLine": "WithoutElse", "AllowShortLoopsOnASingleLine": true, "AlwaysBreakAfterDefinitionReturnType": "None", "AlwaysBreakAfterReturnType": "None", "AlwaysBreakBeforeMultilineStrings": true, "AlwaysBreakTemplateDeclarations": true, "AttributeMacros": ["__capability"], "BinPackArguments": true, "BinPackParameters": true, "BraceWrapping": {"AfterCaseLabel": false, "AfterClass": false, "AfterControlStatement": "Never", "AfterEnum": false, "AfterFunction": false, "AfterNamespace": false, "AfterObjCDeclaration": false, "AfterStruct": false, "AfterUnion": false, "AfterExternBlock": false, "BeforeCatch": false, "BeforeElse": false, "BeforeLambdaBody": false, "BeforeWhile": false, "IndentBraces": false, "SplitEmptyFunction": true, "SplitEmptyRecord": true, "SplitEmptyNamespace": true}, "BreakBeforeBinaryOperators": "None", "BreakBeforeConceptDeclarations": "Always", "BreakBeforeBraces": "Attach", "BreakBeforeInheritanceComma": false, "BreakInheritanceList": "BeforeColon", "BreakBeforeTernaryOperators": true, "BreakConstructorInitializersBeforeComma": false, "BreakConstructorInitializers": "BeforeColon", "BreakAfterJavaFieldAnnotations": false, "BreakStringLiterals": true, "ColumnLimit": 80, "CommentPragmas": "^ IWYU pragma:", "QualifierAlignment": "Leave", "CompactNamespaces": false, "ConstructorInitializerIndentWidth": 4, "ContinuationIndentWidth": 4, "Cpp11BracedListStyle": true, "DeriveLineEnding": true, "DerivePointerAlignment": true, "DisableFormat": false, "EmptyLineAfterAccessModifier": "Never", "EmptyLineBeforeAccessModifier": "LogicalBlock", "ExperimentalAutoDetectBinPacking": false, "PackConstructorInitializers": "NextLine", "BasedOnStyle": "", "ConstructorInitializerAllOnOneLineOrOnePerLine": false, "AllowAllConstructorInitializersOnNextLine": true, "FixNamespaceComments": true, "ForEachMacros": ["foreach", "Q_FOREACH", "BOOST_FOREACH"], "IfMacros": ["KJ_IF_MAYBE"], "IncludeBlocks": "Regroup", "IncludeCategories": [{"Regex": "^<ext/.*\\\\.h>", "Priority": 2, "SortPriority": 0, "CaseSensitive": false}, {"Regex": "^<.*\\\\.h>", "Priority": 1, "SortPriority": 0, "CaseSensitive": false}, {"Regex": "^<.*", "Priority": 2, "SortPriority": 0, "CaseSensitive": false}, {"Regex": ".*", "Priority": 3, "SortPriority": 0, "CaseSensitive": false}], "IncludeIsMainRegex": "([-_](test|unittest))?$", "IncludeIsMainSourceRegex": "", "IndentAccessModifiers": false, "IndentCaseLabels": true, "IndentCaseBlocks": false, "IndentGotoLabels": true, "IndentPPDirectives": "None", "IndentExternBlock": "AfterExternBlock", "IndentRequiresClause": true, "IndentWidth": 2, "IndentWrappedFunctionNames": false, "InsertBraces": false, "InsertTrailingCommas": "None", "JavaScriptQuotes": "Leave", "JavaScriptWrapImports": true, "KeepEmptyLinesAtTheStartOfBlocks": false, "LambdaBodyIndentation": "Signature", "MacroBlockBegin": "", "MacroBlockEnd": "", "MaxEmptyLinesToKeep": 1, "NamespaceIndentation": "None", "ObjCBinPackProtocolList": "Never", "ObjCBlockIndentWidth": 2, "ObjCBreakBeforeNestedBlockParam": true, "ObjCSpaceAfterProperty": false, "ObjCSpaceBeforeProtocolList": true, "PenaltyBreakAssignment": 2, "PenaltyBreakBeforeFirstCallParameter": 1, "PenaltyBreakComment": 300, "PenaltyBreakFirstLessLess": 120, "PenaltyBreakOpenParenthesis": 0, "PenaltyBreakString": 1000, "PenaltyBreakTemplateDeclaration": 10, "PenaltyExcessCharacter": 1000000, "PenaltyReturnTypeOnItsOwnLine": 200, "PenaltyIndentedWhitespace": 0, "PointerAlignment": "Left", "PPIndentWidth": -1, "RawStringFormats": [{"Language": "Cpp", "Delimiters": ["cc", "CC", "cpp", "Cpp", "CPP", "c++", "C++"], "CanonicalDelimiter": "", "BasedOnStyle": "google"}, {"Language": "TextProto", "Delimiters": ["pb", "PB", "proto", "PROTO"], "EnclosingFunctions": ["EqualsProto", "EquivToProto", "PARSE_PARTIAL_TEXT_PROTO", "PARSE_TEST_PROTO", "PARSE_TEXT_PROTO", "ParseTextOrDie", "ParseTextProtoOrDie", "ParseTestProto", "ParsePartialTestProto"], "CanonicalDelimiter": "pb", "BasedOnStyle": "google"}], "ReferenceAlignment": "Pointer", "ReflowComments": true, "RemoveBracesLLVM": false, "RequiresClausePosition": "OwnLine", "SeparateDefinitionBlocks": "Leave", "ShortNamespaceLines": 1, "SortIncludes": "CaseSensitive", "SortJavaStaticImport": "Before", "SortUsingDeclarations": true, "SpaceAfterCStyleCast": false, "SpaceAfterLogicalNot": false, "SpaceAfterTemplateKeyword": true, "SpaceBeforeAssignmentOperators": true, "SpaceBeforeCaseColon": false, "SpaceBeforeCpp11BracedList": false, "SpaceBeforeCtorInitializerColon": true, "SpaceBeforeInheritanceColon": true, "SpaceBeforeParens": "ControlStatements", "SpaceBeforeParensOptions": {"AfterControlStatements": true, "AfterForeachMacros": true, "AfterFunctionDefinitionName": false, "AfterFunctionDeclarationName": false, "AfterIfMacros": true, "AfterOverloadedOperator": false, "AfterRequiresInClause": false, "AfterRequiresInExpression": false, "BeforeNonEmptyParentheses": false}, "SpaceAroundPointerQualifiers": "Default", "SpaceBeforeRangeBasedForLoopColon": true, "SpaceInEmptyBlock": false, "SpaceInEmptyParentheses": false, "SpacesBeforeTrailingComments": 2, "SpacesInAngles": "Never", "SpacesInConditionalStatement": false, "SpacesInContainerLiterals": true, "SpacesInCStyleCastParentheses": false, "SpacesInLineCommentPrefix": {"Minimum": 1, "Maximum": -1}, "SpacesInParentheses": false, "SpacesInSquareBrackets": false, "SpaceBeforeSquareBrackets": false, "BitFieldColonSpacing": "Both", "Standard": "Auto", "StatementAttributeLikeMacros": ["Q_EMIT"], "StatementMacros": ["Q_UNUSED", "QT_REQUIRE_VERSION"], "TabWidth": 8, "UseCRLF": false, "UseTab": "Never", "WhitespaceSensitiveMacros": ["STRINGIZE", "PP_STRINGIZE", "BOOST_PP_STRINGIZE", "NS_SWIFT_NAME", "CF_SWIFT_NAME"]}', '--assume-filename', 'dummy.cpp']
▋[Formatter](Thread-4:formatter_clangformat.py#L97): [ERROR] File not formatted due to an error (exitcode=255): "The filename, directory name, or volume label syntax is incorrect.

"
▋[Formatter](Thread-4:main.py#L418): [DEBUG] Formatting failed. 💔😢💔
bitst0rm commented 9 months ago

To the first issue: I have updated the clang-format commands, as they were not present when Formatter was born.

Regarding the second issue: Editing settings in the left-hand pane under Formatter > Settings will lead to it consistently reverting to the default one, while the right-hand pane is where user customizations should be made.

h2110100 commented 9 months ago

But now there this error

Formatter: [ERROR] File not formatted due to an error (exitcode=255): "'gmock' is not recognized as an internal or external command,

and I have also updated the plugin

bitst0rm commented 9 months ago

Without using Formatter, could you please run from terminal to see what is happening:

"C:\\Program Files\\Clang\\clang-format\\clang-format.exe" --style=file:"C:\\Users\\The Fool\\AppData\\Roaming\\Sublime Text\\Packages\\User\\formatter.assets\\config\\clang_format_google_rc.yaml" --assume-filename=dummy.cpp "C:\\path\\to\\file\\test.cpp" --

test.cpp

#include <iostream>
using namespace std;

int main() {
  int n;

  cout << "Enter an integer: ";
  cin >> n;

  if (n % 2 == 0)
                                                cout << n << " is even.";
  else
                                                cout << n << " is odd.";

  return 0;
}

This is what i got on windows:
▋[Formatter](Thread-44:formatter_clangformat.py#L80): [DEBUG] Current arguments: ['C:\\Users\\admin\\Downloads\\clang-format.exe', '--style=file:C:\\Users\\admin\\AppData\\Roaming\\Sublime Text\\Packages\\User\\formatter.assets\\config\\clang_format_google_rc.yaml', '--assume-filename=dummy.cpp', '-']
▋[Formatter](Thread-44:main.py#L415): [DEBUG] Formatting successful. 🎉😃🍰
h2110100 commented 9 months ago

It prints

#include <iostream>
using namespace std;

int main() {
  int n;

  cout << "Enter an integer: ";
  cin >> n;

  if (n % 2 == 0)
    cout << n << " is even.";
  else
    cout << n << " is odd.";

  return 0;
}

but not the formatting successful status

bitst0rm commented 9 months ago

gmock is neither part of the executed arguments nor it is part of Formatter codebase. I do not have any clue how it appears here. The input command arguments chain and your logs seem to be correct. Formatter only feeds the correct command arguments to the subprocess. However, I could not reproduce this issue with the exitcode 255 on my Mac and Windows. This must be done on your system. You could try to:

These are all that one can do and where Formatter directly invokes.

The dummy --assume-filename=dummy. is part of the command arguments and Formatter handles correct this ways, otherwise we will get an another type of error.

Update: @h2110100 It should get fixed now i think.

h2110100 commented 9 months ago

It does work now. Thanks for your time!

bitst0rm commented 9 months ago

@h2110100 Thanks for your time to testing and bug report! I released 1.1.6 to address this issue.