Recent

Author Topic: Sourcecodeeditor typecolor customization  (Read 2851 times)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: Sourcecodeeditor typecolor customization
« Reply #15 on: November 18, 2019, 08:30:10 pm »
2.) But I really need to rely on lazarus/FPC naming convinctions (any type has a "T" prefix) so if you have code like: "Foo(x)" I will treat it as ur fault, if you dont mark it as TFoo (as it should be) and if its an external class, u can make it urself (but i saw like 90%code is reliant on the type convections, so no worries about this)

For your own personal use, you can of course rely on the T.

For an official add on to the IDE, things should work for any name.

- Integer (not a build in type, the build in is afaik longint) does not have a T.
- English words can start with a T. A variable "There" could be a type "T Here". (Yes upper/lower....)


If you want to base this on a regex like pattern, to find identifiers starting with a T, then  TSynEditMarkupHighlightAllCaret or its base class is a good starting point. Make a copy, and instead of searching for a specific word search for words starting with T.
But that is not going to be an official patch.... (and not working for the windows unit, that has afaik lots of types not starting with a T)

ide/SynSourceEditor shows how to activate the new markup.



howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Sourcecodeeditor typecolor customization
« Reply #16 on: November 18, 2019, 08:33:21 pm »
"Relying on Lazarus/FPC naming conventions" is almost guaranteed not to work consistently unless you are restricting your project to code you write and control yourself.
For a start, Lazarus and FPC sources do not follow the same conventions, and neither set of sources is particularly self-consistent.
This is perfectly understandable - there is no one policing the code, except that new code might be rejected simply on stylistic grounds, even if it were perfect in every other respect. Over the years there have been numerous contributors, each with his own style preferences, which may not bend too much towards the preferred house style when coded in anger. The hundreds of thousands of lines of legacy code are not going to be rewritten to conform to some ideal any time soon.
For instance FPC source often uses capitalised identifiers for variables. While classes usually tend to start with a "T" many other types do not, quite apart from all the non-"T" standard types such as Byte, Boolean, Pointer etc.
Consistent highlighting has to rely on in-depth parsing that has accurately determined the syntactic meaning. It cannot depend on 'surface' formatting or conventional leading characters being present.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: Sourcecodeeditor typecolor customization
« Reply #17 on: November 18, 2019, 08:35:26 pm »
Just for info. Markup is an extension to highlighting.

The highlighter is bound to the language (usually structure, and lexical stuff, but NO content parsing).
So the pascal HL gets all the blocks (begin/end/var/class/....), and lexical stuff like numbers, ";" ":=", or strings....


Markups are usually not language specific. Though there are several (FoldColorOutline, LowLightIfdef, WordPairs) that are specific to either one HL, or a group of HL.

Markups can scan for anything. There are no limiting rules. But of course they must be fast enough to be called on each paint of the editor..


To get the final result, the editor first gets the color from the HL, then asks every Markup for any changes to that color, and then paints it.

Shpend

  • Full Member
  • ***
  • Posts: 167
Re: Sourcecodeeditor typecolor customization
« Reply #18 on: November 18, 2019, 09:06:10 pm »
@Martin_fr

So i really need only to watch out for:

Quote
TSynPasSyn.IdentKind
TSynPasSyn.NExt

and
cfbtVarType, cfbtLocalVarType

as well as
    rsAfterEqualOrColon,   // very first word after "=" or ":"
    rsAfterEqual,          // between "=" and ";" (or block end) // a ^ means ctrl-char, not pointer to type


An ident after a equal or colon, if inside a vartype block.....
?

So I can write my code logic inside the "IdentToken" and "Next" functions/procedures  based on the "=" after/before part ypu have mentioned?

Shpend

  • Full Member
  • ***
  • Posts: 167
Re: Sourcecodeeditor typecolor customization
« Reply #19 on: November 18, 2019, 09:21:04 pm »
But I have to be honest, i am currently heavily engaged in working on GameEngine stuff and improving their, so no real time for this, i thought this could be a bit faster, but I saw its not haha.

Anyways maybe its smth for you guys, since it would be a really nice feature , it helps alot visually to distinguish code, would be glad to see it in next or future patches :)


Tz

  • Jr. Member
  • **
  • Posts: 54
  • Tz with FPC Pen Cil
Re: Sourcecodeeditor typecolor customization
« Reply #20 on: November 18, 2019, 09:27:14 pm »
At last,  Personally I like this feature.

Make pairing clear

I just add UInt8 UInt16 UInt32 UInt64 Int8 Int16 Int32 Int64 Single Double Extended Currency DateTime Guid
Bytes String Object Array Boolean Byte Char WideChar AnsiString WideString UnicodeString

example code

Code: Pascal  [Select][+][-]
  1.   TJSON = class (TObject)
  2.   public
  3.     const
  4.     EmptyObject = '{}';
  5.   private
  6.     FObject   :TJSONObject;
  7.     procedure Add(APath :String; AData :TJSONData);
  8.     function  GetAJSON  :String;
  9.     procedure SetAJSON    (AData :String);
  10.     function  GetBoolean  (APath :String) :Boolean;
  11.     function  GetUInt8    (APath :String) :UInt8;
  12.     function  GetUInt16   (APath :String) :UInt16;
  13.     function  GetUInt32   (APath :String) :UInt32;
  14.     function  GetUInt64   (APath :String) :UInt64;
  15.     function  GetInt8     (APath :String) :Int8;
  16.     function  GetInt16    (APath :String) :Int16;
  17.     function  GetInt32    (APath :String) :Int32;
  18.     function  GetInt64    (APath :String) :Int64;
  19.     function  GetSingle   (APath :String) :Single;
  20.     function  GetDouble   (APath :String) :Double;
  21.     function  GetExtended (APath :String) :Extended;
  22.     function  GetCurrency (APath :String) :Currency;
  23.     function  GetDateTime (APath :String) :TDateTime;
  24.     function  GetGuid     (APath :String) :TGuid;
  25.     function  GetBytes    (APath :String) :TBytes;
  26.     function  GetString   (APath :String) :String;
  27.     function  GetObject   (APath :String) :String;
  28.     procedure SetBoolean  (APath :String; AData :Boolean);
  29.     procedure SetUInt8    (APath :String; AData :UInt8);
  30.     procedure SetUInt16   (APath :String; AData :UInt16);
  31.     procedure SetUInt32   (APath :String; AData :UInt32);
  32.     procedure SetUInt64   (APath :String; AData :UInt64);
  33.     procedure SetInt8     (APath :String; AData :Int8);
  34.     procedure SetInt16    (APath :String; AData :Int16);
  35.     procedure SetInt32    (APath :String; AData :Int32);
  36.     procedure SetInt64    (APath :String; AData :Int64);
  37.     procedure SetSingle   (APath :String; AData :Single);
  38.     procedure SetDouble   (APath :String; AData :Double);
  39.     procedure SetExtended (APath :String; AData :Extended);
  40.     procedure SetCurrency (APath :String; AData :Currency);
  41.     procedure SetDateTime (APath :String; AData :TDateTime);
  42.     procedure SetGuid     (APath :String; AData :TGuid);
  43.     procedure SetBytes    (APath :String; AData :TBytes);
  44.     procedure SetString   (APath :String; AData :String);
  45.     procedure SetObject   (APath :String; AData :String);
  46.   public
  47.     constructor Create;
  48.     destructor Destroy; override;
  49.     function AsFormat                   :String;
  50.     property AsJSON                     :String     read GetAJSON     write SetAJSON;
  51.     property AsBoolean  [APath :String] :Boolean    read GetBoolean   write SetBoolean;
  52.     property AsUInt8    [APath :String] :UInt8      read GetUInt8     write SetUInt8;
  53.     property AsUInt16   [APath :String] :UInt16     read GetUInt16    write SetUInt16;
  54.     property AsUInt32   [APath :String] :UInt32     read GetUInt32    write SetUInt32;
  55.     property AsUInt64   [APath :String] :UInt64     read GetUInt64    write SetUInt64;
  56.     property AsInt8     [APath :String] :Int8       read GetInt8      write SetInt8;
  57.     property AsInt16    [APath :String] :Int16      read GetInt16     write SetInt16;
  58.     property AsInt32    [APath :String] :Int32      read GetInt32     write SetInt32;
  59.     property AsInt64    [APath :String] :Int64      read GetInt64     write SetInt64;
  60.     property AsSingle   [APath :String] :Single     read GetSingle    write SetSingle;
  61.     property AsDouble   [APath :String] :Double     read GetDouble    write SetDouble;
  62.     property AsExtended [APath :String] :Extended   read GetExtended  write SetExtended;
  63.     property AsCurrency [APath :String] :Currency   read GetCurrency  write SetCurrency;
  64.     property AsDateTime [APath :String] :TDateTime  read GetDateTime  write SetDateTime;
  65.     property AsGuid     [APath :String] :TGuid      read GetGuid      write SetGuid;
  66.     property AsBytes    [APath :String] :TBytes     read GetBytes     write SetBytes;
  67.     property AsString   [APath :String] :String     read GetString    write SetString;
  68.     property AsObject   [APath :String] :String     read GetObject    write SetObject;
  69.     property AsArray    [APath :String] :String     read GetObject    write SetObject;
  70.   end;
  71.  
  72.  

 :)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: Sourcecodeeditor typecolor customization
« Reply #21 on: November 18, 2019, 09:27:56 pm »
Yes it will be a bit of work.

For adding this to the HL, yes those are the functions to start with...

Also maybe FTokenIsCaseLabel, which does the highlight mod for case labels, and then in the mentioned locations a FTokenIsTypeName would need to be added.


On the long term, I think this will however go into a markup (or half and half...) .... Because then it can later be extended with codetools.

Shpend

  • Full Member
  • ***
  • Posts: 167
Re: Sourcecodeeditor typecolor customization
« Reply #22 on: November 18, 2019, 10:31:36 pm »
@Martin_fr

so you would consider the effort to implement this (as I said, its smth all IDE have nowadays) ?

Since I cant put the effort right now fior this as I mentioned before, maybe some other lazarus-users have interesst in this :)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: Sourcecodeeditor typecolor customization
« Reply #23 on: November 19, 2019, 12:11:13 am »
You are not the first to ask for this....
And in general this is an acceptable feature request.

As for when and who....

This depends a lot on time available. I currently maintain SynEdit and the IDE-Debugger (including all the backend-wrappers: gdb-wrapperS, lldb-wrapper, fpdebug). This is taking huge amounts of time. So I can make no promise when (or if) I will get to work on it.

Adding colors, in the var/const/param blocks only (excluding any code blocks), is probably something I can do in reasonable time. I am not sure if it's worth it. The real usefulness of highlighting the types is if they occur inside the code block.
For the code block part, there is no way around code-tools (and probably added caching). However with Codetools I am not that familiar, so that will take considerable longer.

Shpend

  • Full Member
  • ***
  • Posts: 167
Re: Sourcecodeeditor typecolor customization
« Reply #24 on: November 19, 2019, 02:50:56 pm »
@Martin_fr:

Ofc, I can understand this fully, as I mentioned earlier, I am engaged currently myself in something also very time and brain consuming and I am not able to participate on it unfortunately, as much as I would like too actually, but Im still not such a good developer who can multi-task develop source code in different areas .

And yea, the stuff you mentioned have higher priority ofc, I want just to stretch again, that it is a nice feature an IDE should provide, its fully up to you guys, when you decide to implement it !


Anyway, thanks for taking the issue/request seriously and atleast considering it.


Tz

  • Jr. Member
  • **
  • Posts: 54
  • Tz with FPC Pen Cil
Re: Sourcecodeeditor typecolor customization
« Reply #25 on: November 26, 2019, 01:50:27 pm »
Just add list for term _ (underscore) and ; (semicolon) with Money Green color

seem snake case more readable, and less noise.

My current scheme color is Delphi, but I think should be tune for each theme.

awesome  :D



 

TinyPortal © 2005-2018