Arma Reforger Script API
Loading...
Searching...
No Matches
SCR_BasicCodeFormatterPlugin Interface Reference

A Basic Code Formatter - use Ctrl+Shift+K to trigger. More...

Inheritance diagram for SCR_BasicCodeFormatterPlugin:

Public Member Functions

void RunForced ()
 Run the code formatter forced (formats all lines of the currently-opened file)
 

Static Public Member Functions

static void GetIndentAndLineContent (string fullLine, out string indentation, out string content)
 Split line between indentation and content (trailing spaces included if any)
 

Protected Member Functions

override void Run ()
 Running method.
 
void Initialise ()
 Required initialisation (prefixes filter)
 
void RunCurrentFile ()
 Run the current file.
 
void RunAddonFilesBatchProcess ()
 Show dialogs to treat all addon script files.
 
array< ref SCR_BasicCodeFormatterPluginFileReportProcessFiles (array< string > relativeFilePaths, bool useFileIO)
 Process multiple files (using ProcessFile)
 
SCR_BasicCodeFormatterPluginFileReport ProcessFile (string relativeFilePath, bool useFileIO)
 Process a single file.
 
array< string > ReadFileContent (string relativeFilePath, bool useFileIO)
 Get relative file's content lines as array of strings.
 
void PrintReport (notnull SCR_BasicCodeFormatterPluginFileReport report, bool printFixes, bool printFindings)
 Output fixes and findings in the log console.
 
int GeneralFormatting (string indentation, inout notnull array< string > pieces)
 General formatting like spacing, "NULL" → "null", ";;" → ";", etc.
 
bool AddFinalLineReturnToCurrentFile ()
 Add the final line return to a file (to end with a line return instead of the usual closing bracket)
 
bool HasBadVariableNaming (string indentation, string findingsString)
 Checks for bad prefixes and non-uppercased consts.
 
void PrintFinding (string description, notnull array< int > lineNumbers, string tip=string.Empty)
 Print the finding with line numbers examples: "int(s)", {}, "" = "No int(s) found" "int(s)", {}, "a tip" = "No int(s) found" "int(s)", { 1, 2, 3 }, "" = "3 int(s) found at line(s) 1, 2 & 3" "int(s)", { 1, 2, 3 }, "use longs instead" = "3 int(s) found at line(s) 1, 2 & 3 - use longs instead".
 
array< int > GetFileModifiedLineNumbers (string absoluteFilePath, out bool isInRepository)
 Get the 1-based line numbers of lines that were modified since the last edit (according to the local VCS' diff) This method creates a temporary txt file next to the analysed one containing the diff result The temporary txt file is deleted (if everything goes well) after its parsing.
 
override void Configure ()
 
bool ButtonOK ()
 
bool ButtonCancel ()
 
void SCR_BasicCodeFormatterPlugin ()
 

Static Protected Member Functions

static void GetIndentAndLineContentAsPieces (string fullLine, out string indentation, out array< string > pieces)
 Get line content as array of strings.
 
static string JoinLineNumbers (notnull array< int > lineNumbers, int maxNumbers=LINE_NUMBER_LIMIT)
 Joins the provided line numbers together with commas and ampersand for the last element; also groups them by range (e.g 1,2,3,4,6,7,9 = 1-5, 6-7, 9).
 

Protected Attributes

bool m_bGeneralFormatting
 
bool m_bTrimLineEnds
 
bool m_bFixTabs
 
bool m_bFixMethodSeparators
 
bool m_bAddFinalLineReturn
 
ref array< string > m_aAcceptedScriptPrefixes
 
bool m_bBatchProcessAddon
 
int m_iAddon
 
bool m_bOnlyLogChanges
 
int m_iMaxLoggedReports
 
bool m_bDemoMode
 
bool m_bSilentExecution
 
bool m_bOnlyFormatModifiedLines
 
bool m_bLogFixes
 
bool m_bReportFindings
 
ref array< string > m_aExcludedDirectories
 
ref SCR_BasicCodeFormatterSpellCheckConfig m_SpellCheckConfig
 
bool m_bShowSpellCheckFindingsDetails
 
string m_sDiffCommand
 
ref array< ref array< string > > m_aGeneralFormatting_Start
 
ref array< ref array< string > > m_aGeneralFormatting_Middle
 
ref array< ref array< string > > m_aGeneralFormatting_End
 
ref array< string > m_aForbiddenDivisions
 
ref array< string > m_aPrefixLineChecks
 what should be followed by a TAG_ prefix
 
ref array< string > m_aPrefixChecks
 
ref array< string > m_aForbiddenDirectories
 
ref array< string > m_aForForEachWhileArray
 
ref array< string > m_aIfForForEachWhileArray
 
ref array< string > m_aEndBracketSemicolonArray
 
ref array< string > m_aNewArrayNewRefArray
 
ref array< string > m_aScriptInvokerArray
 
ref map< string, string > m_mVariableTypePrefixes
 
ref map< string, string > m_mVariableTypePrefixesStart
 
ref map< string, string > m_mVariableTypePrefixesEnd
 
ref map< string, string > m_mForbiddenWords
 mistake-correction map; mistake can contain star(s)
 

Static Protected Attributes

static const int LINE_NUMBER_LIMIT = 12
 used by JoinLineNumbers to limit the amount of shown line number groups
 
static const string LINE_NUMBER_RANGE = "%1-%2"
 used by JoinLineNumbers to give a line range (e.g 5-17, 2001-2013, etc)
 
static const string LOG_SEPARATOR = "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
 
static const string BRACKET_OPEN = "{"
 
static const string BRACKET_CLOSE = "}"
 
static const string MEMBER_PREFIX = "m_"
 
static const string STATIC_PREFIX = "s_"
 
static const ref array< string > NATIVE_TYPES
 
static const ref array< string > VARIABLE_NAME_ENDING = { SCR_StringHelper.SPACE, ",", "=", ";", SCR_StringHelper.SLASH }
 
static const string METHOD_SEPARATOR = SCR_StringHelper.DOUBLE_SLASH + "------------------------------------------------------------------------------------------------"
 
static const string DIFF_FILENAME = "tempDiffFile.txt"
 
static const string DEFAULT_DIFF_CMD = "cmd /c svn diff \"%1\" > \"%2\""
 
static const ref array< string > FORMAT_IGNORE = { SCR_StringHelper.DOUBLE_SLASH, SCR_StringHelper.SLASH + "*", SCR_StringHelper.DOUBLE_QUOTE }
 
static const ref array< string > FORCED_PREFIXES = { "SCR_" }
 
static const ref array< string > EXCLUDED_DIRECTORIES
 
static const string GENERATED_SCRIPT_WARNING = "Do not modify, this script is generated"
 
static const ResourceName SPELLCHECK_CONFIG = "{53D7DE332A43449F}Configs/Workbench/ScriptEditor/BasicCodeFormatterPlugin/BasicCodeFormatterSpellCheckConfig.conf"
 

Detailed Description

A Basic Code Formatter - use Ctrl+Shift+K to trigger.

Ctrl+Alt+Shift+K can be used to force processing all the lines of the currently opened file.

See also
SCR_BasicCodeFormatterForcedPlugin

Constructor & Destructor Documentation

◆ SCR_BasicCodeFormatterPlugin()

void SCR_BasicCodeFormatterPlugin.SCR_BasicCodeFormatterPlugin ( )
protected

Member Function Documentation

◆ AddFinalLineReturnToCurrentFile()

bool SCR_BasicCodeFormatterPlugin.AddFinalLineReturnToCurrentFile ( )
protected

Add the final line return to a file (to end with a line return instead of the usual closing bracket)

Returns
true if an empty line has been added, false otherwise

◆ ButtonCancel()

bool SCR_BasicCodeFormatterPlugin.ButtonCancel ( )
protected

◆ ButtonOK()

bool SCR_BasicCodeFormatterPlugin.ButtonOK ( )
protected

◆ Configure()

override void SCR_BasicCodeFormatterPlugin.Configure ( )
protected

◆ GeneralFormatting()

int SCR_BasicCodeFormatterPlugin.GeneralFormatting ( string indentation,
inout notnull array< string > pieces )
protected

General formatting like spacing, "NULL" → "null", ";;" → ";", etc.

Parameters
[in]indentationused to determine the scope level
[in,out]piecestext pieces input/output
Returns
number of replacements that happened

◆ GetFileModifiedLineNumbers()

array< int > SCR_BasicCodeFormatterPlugin.GetFileModifiedLineNumbers ( string absoluteFilePath,
out bool isInRepository )
protected

Get the 1-based line numbers of lines that were modified since the last edit (according to the local VCS' diff) This method creates a temporary txt file next to the analysed one containing the diff result The temporary txt file is deleted (if everything goes well) after its parsing.

Parameters
[in]absoluteFilePaththe ABSOLUTE file path (e.g C:/ArmaReforger/Data/scripts/myFile.c)
[in]isInRepository
Returns
array of line numbers (first line = 1!), empty on no changes / new file, null on error

◆ GetIndentAndLineContent()

static void SCR_BasicCodeFormatterPlugin.GetIndentAndLineContent ( string fullLine,
out string indentation,
out string content )
static

Split line between indentation and content (trailing spaces included if any)

Parameters
[in]fullLinethe line's content
[out]indentationgets the left spacing (tabs and spaces)
[out]contentgets the text

◆ GetIndentAndLineContentAsPieces()

static void SCR_BasicCodeFormatterPlugin.GetIndentAndLineContentAsPieces ( string fullLine,
out string indentation,
out array< string > pieces )
staticprotected

Get line content as array of strings.

Cannot return an empty array

Parameters
[in]fullLinethe line to analyse
[out]indentationgets the left spacing (tabs and spaces)
[out]piecesthe line as split in code, string, comment parts - first element being indentation (empty when none). can be provided null, result is never null or empty

◆ HasBadVariableNaming()

bool SCR_BasicCodeFormatterPlugin.HasBadVariableNaming ( string indentation,
string findingsString )
protected

Checks for bad prefixes and non-uppercased consts.

Parameters
[in]fullLinethe line to check - indentation is used to determine the variable's level (1 tab = member variable)
Returns
true if a badly-named variable has been spotted

◆ Initialise()

void SCR_BasicCodeFormatterPlugin.Initialise ( )
protected

Required initialisation (prefixes filter)

◆ JoinLineNumbers()

static string SCR_BasicCodeFormatterPlugin.JoinLineNumbers ( notnull array< int > lineNumbers,
int maxNumbers = LINE_NUMBER_LIMIT )
staticprotected

Joins the provided line numbers together with commas and ampersand for the last element; also groups them by range (e.g 1,2,3,4,6,7,9 = 1-5, 6-7, 9).


examples:
{} = ""
{ 1 } = "1"
{ 1, 2, 3 } = "1-3"
{ 1, 2, ... , 10, 11 } = "1-11"
{ 1, 2, 3, 7, 8, 9 } = "1-3 & 7-9"
{ 1, 2, 3, 5, 7, 8, 9 } = "1-3, 5 & 7-9"
{ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23 } = "1, 3, 5, 7, 9, 11, 13, 15, 17, 19, ..."

Parameters
[in]lineNumberssaid line numbers in ascending order
[in]maxNumbersmaximum number of lines before ellipsis
Returns
the joined numbers

◆ PrintFinding()

void SCR_BasicCodeFormatterPlugin.PrintFinding ( string description,
notnull array< int > lineNumbers,
string tip = string::Empty )
protected

Print the finding with line numbers examples: "int(s)", {}, "" = "No int(s) found" "int(s)", {}, "a tip" = "No int(s) found" "int(s)", { 1, 2, 3 }, "" = "3 int(s) found at line(s) 1, 2 & 3" "int(s)", { 1, 2, 3 }, "use longs instead" = "3 int(s) found at line(s) 1, 2 & 3 - use longs instead".

Parameters
[in]descriptionthe finding(s)' description, starting with a lowercase as it is meant to be used in the middle of a sentence
[in]lineNumbersthe lines where the findings have been found
[in]tipa suggestion to fix the finding

◆ PrintReport()

void SCR_BasicCodeFormatterPlugin.PrintReport ( notnull SCR_BasicCodeFormatterPluginFileReport report,
bool printFixes,
bool printFindings )
protected

Output fixes and findings in the log console.

Parameters
[in]reportthe generated report
[in]printFixesprint applied fixes (edited lines, trimmings, formatting etc)
[in]printFindingsprint findings that may require user attention (one-liners, bad variable naming, etc)

◆ ProcessFile()

SCR_BasicCodeFormatterPluginFileReport SCR_BasicCodeFormatterPlugin.ProcessFile ( string relativeFilePath,
bool useFileIO )
protected

Process a single file.

Parameters
[in]relativeFilePaththe file's relative path
[in]useFileIOtrue = use FileIO's API (no Ctrl+Z available, but does not open a Script Editor tab),
false = use ScriptEditor API method (opens a tab, allows for Ctrl+Z)
Returns
provided file's report, null on error

◆ ProcessFiles()

array< ref SCR_BasicCodeFormatterPluginFileReport > SCR_BasicCodeFormatterPlugin.ProcessFiles ( array< string > relativeFilePaths,
bool useFileIO )
protected

Process multiple files (using ProcessFile)

Parameters
[in]relativeFilePathsmultiple relative file paths
[in]useFileIOtrue = use FileIO's API (no Ctrl+Z available, but does not open a Script Editor tab),
false = use ScriptEditor API method (opens a tab, allows for Ctrl+Z)
Returns
array of reports (in the order of relativeFilePaths)

◆ ReadFileContent()

array< string > SCR_BasicCodeFormatterPlugin.ReadFileContent ( string relativeFilePath,
bool useFileIO )
protected

Get relative file's content lines as array of strings.

Parameters
[in]relativeFilePaththe file's relative path
[in]useFileIOuse FileIO API, otherwise use Script Editor API (opening the file in a tab)
Returns
file lines

◆ Run()

override void SCR_BasicCodeFormatterPlugin.Run ( )
protected

Running method.

◆ RunAddonFilesBatchProcess()

void SCR_BasicCodeFormatterPlugin.RunAddonFilesBatchProcess ( )
protected

Show dialogs to treat all addon script files.

◆ RunCurrentFile()

void SCR_BasicCodeFormatterPlugin.RunCurrentFile ( )
protected

Run the current file.

◆ RunForced()

void SCR_BasicCodeFormatterPlugin.RunForced ( )

Run the code formatter forced (formats all lines of the currently-opened file)

Member Data Documentation

◆ BRACKET_CLOSE

const string SCR_BasicCodeFormatterPlugin.BRACKET_CLOSE = "}"
staticprotected

◆ BRACKET_OPEN

const string SCR_BasicCodeFormatterPlugin.BRACKET_OPEN = "{"
staticprotected

◆ DEFAULT_DIFF_CMD

const string SCR_BasicCodeFormatterPlugin.DEFAULT_DIFF_CMD = "cmd /c svn diff \"%1\" > \"%2\""
staticprotected

◆ DIFF_FILENAME

const string SCR_BasicCodeFormatterPlugin.DIFF_FILENAME = "tempDiffFile.txt"
staticprotected

◆ EXCLUDED_DIRECTORIES

const ref array<string> SCR_BasicCodeFormatterPlugin.EXCLUDED_DIRECTORIES
staticprotected
Initial value:
= {
"scripts/Core/generated/",
"scripts/GameLib/generated/",
"scripts/Game/generated/",
"scripts/WorkbenchGameCommon/generated/",
}

◆ FORCED_PREFIXES

const ref array<string> SCR_BasicCodeFormatterPlugin.FORCED_PREFIXES = { "SCR_" }
staticprotected

◆ FORMAT_IGNORE

const ref array<string> SCR_BasicCodeFormatterPlugin.FORMAT_IGNORE = { SCR_StringHelper.DOUBLE_SLASH, SCR_StringHelper.SLASH + "*", SCR_StringHelper.DOUBLE_QUOTE }
staticprotected

◆ GENERATED_SCRIPT_WARNING

const string SCR_BasicCodeFormatterPlugin.GENERATED_SCRIPT_WARNING = "Do not modify, this script is generated"
staticprotected

◆ LINE_NUMBER_LIMIT

const int SCR_BasicCodeFormatterPlugin.LINE_NUMBER_LIMIT = 12
staticprotected

used by JoinLineNumbers to limit the amount of shown line number groups

◆ LINE_NUMBER_RANGE

const string SCR_BasicCodeFormatterPlugin.LINE_NUMBER_RANGE = "%1-%2"
staticprotected

used by JoinLineNumbers to give a line range (e.g 5-17, 2001-2013, etc)

◆ LOG_SEPARATOR

const string SCR_BasicCodeFormatterPlugin.LOG_SEPARATOR = "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
staticprotected

◆ m_aAcceptedScriptPrefixes

ref array<string> SCR_BasicCodeFormatterPlugin.m_aAcceptedScriptPrefixes
protected

◆ m_aEndBracketSemicolonArray

ref array<string> SCR_BasicCodeFormatterPlugin.m_aEndBracketSemicolonArray
protected

◆ m_aExcludedDirectories

ref array<string> SCR_BasicCodeFormatterPlugin.m_aExcludedDirectories
protected

◆ m_aForbiddenDirectories

ref array<string> SCR_BasicCodeFormatterPlugin.m_aForbiddenDirectories
protected

◆ m_aForbiddenDivisions

ref array<string> SCR_BasicCodeFormatterPlugin.m_aForbiddenDivisions
protected

◆ m_aForForEachWhileArray

ref array<string> SCR_BasicCodeFormatterPlugin.m_aForForEachWhileArray
protected

◆ m_aGeneralFormatting_End

ref array<ref array<string> > SCR_BasicCodeFormatterPlugin.m_aGeneralFormatting_End
protected

◆ m_aGeneralFormatting_Middle

ref array<ref array<string> > SCR_BasicCodeFormatterPlugin.m_aGeneralFormatting_Middle
protected

◆ m_aGeneralFormatting_Start

ref array<ref array<string> > SCR_BasicCodeFormatterPlugin.m_aGeneralFormatting_Start
protected

◆ m_aIfForForEachWhileArray

ref array<string> SCR_BasicCodeFormatterPlugin.m_aIfForForEachWhileArray
protected

◆ m_aNewArrayNewRefArray

ref array<string> SCR_BasicCodeFormatterPlugin.m_aNewArrayNewRefArray
protected

◆ m_aPrefixChecks

ref array<string> SCR_BasicCodeFormatterPlugin.m_aPrefixChecks
protected

◆ m_aPrefixLineChecks

ref array<string> SCR_BasicCodeFormatterPlugin.m_aPrefixLineChecks
protected

what should be followed by a TAG_ prefix

◆ m_aScriptInvokerArray

ref array<string> SCR_BasicCodeFormatterPlugin.m_aScriptInvokerArray
protected

◆ m_bAddFinalLineReturn

bool SCR_BasicCodeFormatterPlugin.m_bAddFinalLineReturn
protected

◆ m_bBatchProcessAddon

bool SCR_BasicCodeFormatterPlugin.m_bBatchProcessAddon
protected

◆ m_bDemoMode

bool SCR_BasicCodeFormatterPlugin.m_bDemoMode
protected

◆ m_bFixMethodSeparators

bool SCR_BasicCodeFormatterPlugin.m_bFixMethodSeparators
protected

◆ m_bFixTabs

bool SCR_BasicCodeFormatterPlugin.m_bFixTabs
protected

◆ m_bGeneralFormatting

bool SCR_BasicCodeFormatterPlugin.m_bGeneralFormatting
protected

◆ m_bLogFixes

bool SCR_BasicCodeFormatterPlugin.m_bLogFixes
protected

◆ m_bOnlyFormatModifiedLines

bool SCR_BasicCodeFormatterPlugin.m_bOnlyFormatModifiedLines
protected

◆ m_bOnlyLogChanges

bool SCR_BasicCodeFormatterPlugin.m_bOnlyLogChanges
protected

◆ m_bReportFindings

bool SCR_BasicCodeFormatterPlugin.m_bReportFindings
protected

◆ m_bShowSpellCheckFindingsDetails

bool SCR_BasicCodeFormatterPlugin.m_bShowSpellCheckFindingsDetails
protected

◆ m_bSilentExecution

bool SCR_BasicCodeFormatterPlugin.m_bSilentExecution
protected

◆ m_bTrimLineEnds

bool SCR_BasicCodeFormatterPlugin.m_bTrimLineEnds
protected

◆ m_iAddon

int SCR_BasicCodeFormatterPlugin.m_iAddon
protected

◆ m_iMaxLoggedReports

int SCR_BasicCodeFormatterPlugin.m_iMaxLoggedReports
protected

◆ m_mForbiddenWords

ref map<string, string> SCR_BasicCodeFormatterPlugin.m_mForbiddenWords
protected

mistake-correction map; mistake can contain star(s)

◆ m_mVariableTypePrefixes

ref map<string, string> SCR_BasicCodeFormatterPlugin.m_mVariableTypePrefixes
protected

◆ m_mVariableTypePrefixesEnd

ref map<string, string> SCR_BasicCodeFormatterPlugin.m_mVariableTypePrefixesEnd
protected

◆ m_mVariableTypePrefixesStart

ref map<string, string> SCR_BasicCodeFormatterPlugin.m_mVariableTypePrefixesStart
protected

◆ m_sDiffCommand

string SCR_BasicCodeFormatterPlugin.m_sDiffCommand
protected

◆ m_SpellCheckConfig

ref SCR_BasicCodeFormatterSpellCheckConfig SCR_BasicCodeFormatterPlugin.m_SpellCheckConfig
protected

◆ MEMBER_PREFIX

const string SCR_BasicCodeFormatterPlugin.MEMBER_PREFIX = "m_"
staticprotected

◆ METHOD_SEPARATOR

const string SCR_BasicCodeFormatterPlugin.METHOD_SEPARATOR = SCR_StringHelper.DOUBLE_SLASH + "------------------------------------------------------------------------------------------------"
staticprotected

◆ NATIVE_TYPES

const ref array<string> SCR_BasicCodeFormatterPlugin.NATIVE_TYPES
staticprotected
Initial value:
= {
"bool", "float", "int", "string", "typename", "vector",
"FactionKey", "LocalizedString", "ResourceName",
}

◆ SPELLCHECK_CONFIG

const ResourceName SCR_BasicCodeFormatterPlugin.SPELLCHECK_CONFIG = "{53D7DE332A43449F}Configs/Workbench/ScriptEditor/BasicCodeFormatterPlugin/BasicCodeFormatterSpellCheckConfig.conf"
staticprotected

◆ STATIC_PREFIX

const string SCR_BasicCodeFormatterPlugin.STATIC_PREFIX = "s_"
staticprotected

◆ VARIABLE_NAME_ENDING

const ref array<string> SCR_BasicCodeFormatterPlugin.VARIABLE_NAME_ENDING = { SCR_StringHelper.SPACE, ",", "=", ";", SCR_StringHelper.SLASH }
staticprotected

The documentation for this interface was generated from the following file: