Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2023-05

Some source editor context menu items broken

7 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Van Canneyt

Hello,

The refactoring context menu item and the find identifier references context menu are broken.

Type
   TSourceParser = Class(TObject)
    function ParseSource: TPasModule;
   end;

With the cursor on "ParseSource", the 'Find identifier references' and 'Rename identifier' menu items in the context menu are grayed out. (plus some others)

The same problem exists if the cursor is on "ParseSource" in the implementation:

function TSourceParser.ParseSource: TPasModule;

I did some digging, and it seems to me that the error is in the TCustomSynEdit.CaretAtIdentOrString routine, which does not detect an identifier correctly.

It seems a bit strange to me that the syntax highlighter is used to determine whether the cursor is on a identifier or something else.

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).

Any solutions ?

Michael.

Reply by email

Luca Olivetti
to Michael Van Canneyt

El 21/5/23 a les 10:48, Michael Van Canneyt via lazarus ha escrit:

Any solutions ?

I found this issue a while ago (and I think I reported it here but I cannot find the message right now) and even if the context menu is greyed out, the "F2" key still works to rename the identifier. No idea about the "find identifier references" sorry.

Bye

Luca Olivetti Wetron Automation Technology https://wetron.es/ Tel. +34 93 5883004 (Ext.3010) Fax +34 93 5883007

Reply by email

Luca Olivetti
to Luca Olivetti

El 21/5/23 a les 11:05, Luca Olivetti via lazarus ha escrit:

Show quoted text 7 lines
El 21/5/23 a les 10:48, Michael Van Canneyt via lazarus ha escrit: > > Any solutions ? I found this issue a while ago (and I think I reported it here but I cannot find the message right now)

found it

https://lists.lazarus-ide.org/pipermail/lazarus/2019-May/236611.html

Bye

Luca Olivetti Wetron Automation Technology https://wetron.es/ Tel. +34 93 5883004 (Ext.3010) Fax +34 93 5883007

Reply by email

Michael Van Canneyt
to Luca Olivetti: El 21/5/23 a les 10:48, Michael Van Canneyt via lazarus ha escrit: I found this issue a…
Luca Olivetti wrote 8 lines
El 21/5/23 a les 10:48, Michael Van Canneyt via lazarus ha escrit: > > Any solutions ? I found this issue a while ago (and I think I reported it here but I cannot find the message right now) and even if the context menu is greyed out, the "F2" key still works to rename the identifier.

That would be an error in itself.

No idea about the "find identifier references" sorry.

They are updated at the same time with the same logic.

Michael.

Reply by email

Mattias Gaertner
to Michael Van Canneyt: The refactoring context menu item and the find identifier references context menu are…
Show quoted text 11 lines
[...] 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

Martin?

Mattias

Reply by email

Michael Van Canneyt
to Mattias Gaertner
Mattias Gaertner wrote 19 lines
On Sun, 21 May 2023 10:48:30 +0200 (CEST) Michael Van Canneyt via lazarus 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.

Reply by email

Martin Frb
to Mattias Gaertner: On Sun, 21 May 2023 10:48:30 +0200 (CEST) Problem is that this function checks: AtIdent…
Mattias Gaertner wrote 19 lines
On Sun, 21 May 2023 10:48:30 +0200 (CEST) Michael Van Canneyt via lazarus 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

Yes that is broken in SynEdit.

This is related to procedure names having a color of their own.

Same probably happens for case-labels
? "case enum of" and then the named enum-members as labels. Yet in that case there is no easy way to differentiate between identifier (enum member name) and else/otherwise (keyword).

That should be reported as a bug. (It may need a more substantial fix to be future-safe / a dedicated function in the HL maybe)

-------------------
Using CaretAtIdentOrString is questionable anyway.

Afaik codetools also works on comments.
At least "find?identifier?references" (if invoked via key combo) works on idents in comments.

Yet CaretAtIdentOrString does by design not return true for comments.

So "git blame" the source editor, and see what was used before CaretAtIdentOrString.

Reply by email