[Lazarus] Some source editor context menu items broken

Michael Van Canneyt michael at freepascal.org
Sun May 21 11:52:34 CEST 2023



On Sun, 21 May 2023, Mattias Gaertner via lazarus wrote:

> On Sun, 21 May 2023 10:48:30 +0200 (CEST)
> Michael Van Canneyt via lazarus <lazarus at lists.lazarus-ide.org> wrote:
>
>> [...]
>> I saw a remark in main.pp that this is supposed to be faster than
>> using the codetools:
>>
>>      CurWordAtCursor := ASrcEdit.GetWordAtCurrentCaret;
>>      //it is faster to get information from SynEdit than from
>> CodeTools
>> ASrcEdit.EditorComponent.CaretAtIdentOrString(ASrcEdit.EditorComponent.CaretXY,
>> IdentFound, StringFound);
>>
>> Faster? Probably. Correct? clearly not (yet).
>
> Problem is that this function checks:
>          AtIdent := Attri = Highlighter.IdentifierAttribute;
> But TSynPasSyn has its own attribute
>  ProcedureHeaderName: TSynHighlighterAttributesModifier

Asking the syntax highlighter means there is a probability that the code
breaks again whenever a new attribute is introduced.

Looking at the code, I think it should not be hard to change this algorithm
so it uses the codetools. Simply start scanning tokens on the line of the
caret, and determine the token type when the caret position is reached.
That is what the highlighter does, after all.

The advantage is that it will be more unambiguous.

Well, just an idea.

Michael.


More information about the lazarus mailing list