Jump to content
Sign in to follow this  
wuwuxin

How to let MMX wrap code properly?

Recommended Posts

MMX would wrap code line (that exceeds the set max columns), but sometimes the wrapping is not very optimal, for example,

 

function MyFooFooFunction(const AParam1: string; const AParam2: TObject; const AParam3: IInterface): TObject

 

would be wrapped up as

function MyFooFooFunction(const AParam1: string; const AParam2: TObject; const
  AParam3: IInterface): TObject

 

or wrapped up as

function MyFooFooFunction(const AParam1: string; const AParam2
  : TObject; const AParam3: IInterface): TObject

Ideally, I want to keep the parameter declaration intact,  i.e., const AParam3: IInterface doesn't get "cut off" at const,  or at ":".

 

How can I do that?

Edited by wuwuxin
improve

Share this post


Link to post
4 hours ago, wuwuxin said:

How can I do that?

Unfortunately, you cannot.

 

The wrapping algorithm is based on a tokenizer with some checks for line comments and special delimiters (like comma, semicolon and opening brackets) which are kept with the following token.

 

Currently there is nothing implemented to detect complete declarations. You can file a feature request here: support@mmx-delphi.de (best accompanied by a set of examples to help me create some unit tests).

Share this post


Link to post

It seems the latest MMX improves the wrapping algorithm.  But still it doesn't seem to be able to wrap generic param correctly: for example:

ATables: TArray<TSQLRecordClass>

 

can be wrapped as at the left bracket:

ATables: TArray<

TSQLRecordClass>

 

Share this post


Link to post

Well, I am thankful for every test case. 

 

The test case should have:

  1. the complete line with leading spaces
  2. the expected length of the first line after wrapping
  3. the wrap margin to use (default = 80)
  4. the indent for the wrapped lines (default = 4)

Share this post


Link to post

1. The implementation of the function is wrapped wrongly:

class function TMormotOrmFactory.CreateMormotOrm(const AParams: TMormotOrmParams; const ATables: TArray<
  TSQLRecordClass>; const ASchema: String; const AObsoleteSchemas: TArray<String>; const ACreateIndexProc:
  TMormotCreateIndexProc; const AStartupScript: String = ''): IMormotOrmFramework;

 

2.  Not sure what it means.

 

3. Wrap margin is 118

4. Indent = 2

Share this post


Link to post

I just realized that this is far more complex than I anticipated. The current implementation takes one or more lines and splits them each independently. If a line break is inserted, the remaining text is also handled as if it were independent. Unfortunately that will not work reliable when semantics come into play and some state has to be carried on.

 

Seems I have to re-design the whole approach before it can be used in production.

 

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×