Recent

Author Topic: Unknown Identifier Search  (Read 5348 times)

Tony Stone

  • Sr. Member
  • ****
  • Posts: 277
Unknown Identifier Search
« on: February 14, 2023, 03:07:58 pm »
So after thousands of errors about unknown identifiers when I am testing code I find online I just last night discovered that Lazarus can search your units for the identifier.  Then with a simple right click it can add the found unit to your use section.  I love it.  Wish I knew about it years ago.  Which makes me think maybe there could be a "smart" message to go with an unknown identifier error?  Meaning if the IDE knows that identifier is in xx unit it will give you that as a message?  Or maybe the first time the IDE ever encounters the error it offers the user the method to search your units?  Then that message could have a simple don't show this message again check mark.  Just a thought for new users.  I never knew the search tool was in there.  I could be way off on this idea.  Just curious what others think.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11926
  • Debugger - SynEdit - and more
    • wiki
Re: Unknown Identifier Search
« Reply #1 on: February 14, 2023, 04:33:08 pm »
I agree the "quick fix" feature has very low visibility. Not sure though, how best to improve.

I don't think that "auto repeating" the fix is a good idea.
- If you have the same identifier several times in the unit, then fixing it once (by inserting the needed unit into the uses clause) will fix the rest too.
- If it is another ident, you need to check if the offered unit is correct.
- If it is the same ident, but in a diff unit, then again the fix may not be the same, the ident could be from another unit too.

Even if you fix the first ident in a unit by updating the uses clause, later idents of the same name could be from other units.



Btw, you may want to install package cody, which adds the "Show Unit / Identifier dictionary" to the "Source" menu. It can find units even from packages that you haven't yet added to the project. And you can start typing, and it searches by prefix. (The normal drop down code completion only finds identifiers from units already in the uses clause)

Also read https://wiki.lazarus.freepascal.org/Lazarus_IDE_Tools

Tony Stone

  • Sr. Member
  • ****
  • Posts: 277
Re: Unknown Identifier Search
« Reply #2 on: March 22, 2023, 12:41:15 pm »
I have a bug with using the Search Edentifier tool when i have 2 code editors docked side by side.  When the Identifier search is searching the code editor that had focus scrolls very far to the right by about 200, some times more like 400 characters or more to the right.  Not sure if this is an issue in the editor or the Identifier Search.  Anyone else experience anything like this?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11926
  • Debugger - SynEdit - and more
    • wiki
Re: Unknown Identifier Search
« Reply #3 on: March 22, 2023, 01:17:12 pm »
I have a bug with using the Search Edentifier tool when i have 2 code editors docked side by side.  When the Identifier search is searching the code editor that had focus scrolls very far to the right by about 200, some times more like 400 characters or more to the right.  Not sure if this is an issue in the editor or the Identifier Search.  Anyone else experience anything like this?
Can't say I had. But lets clarify some points
- "scrolls 200/400 horiz-right" => I assume the identifier isn't on a line that is that long?
- And then also, you have enabled/allowed "caret past EOL" ? (otherwise it couldn't go there, if the line is shorter)

Then we have to consider it could be an issue in docking. (which I don't use, and then would explain I haven't seen the issue).

And if it relies on a 2nd editor being open. Does that 2nd editor
- show the same file
- has lines that are that long (so that maybe the position was meant for the 2nd editor)

Also, when does it happen?
- during the search
- automatically at the end of the search
- when you click a found-result in the "search result" window?
  (And are there results found?)
- Only when the search ends in an error (messages window)
  (Or no search results shown?)

Tony Stone

  • Sr. Member
  • ****
  • Posts: 277
Re: Unknown Identifier Search
« Reply #4 on: March 22, 2023, 01:26:14 pm »
Yes I have scroll past EOL enabled.

It seems to scroll horizontally as soon as the search is started.  I am starting the search from the message window list


I say it is only when I have the editors docked side by side because that is my layout on my desktop monitors(very large)... On my laptop I do not see this issue but i also dont use cloned and docked editors on the lap top.


Last night I seem to have noticed it is scrolling further to the right the larger the unit is.  I.E. 1000 lines scrolls further to the right than a unit that has 500 lines.

No errors, not sure if this is happening only when no results are found.

When I get home tonight I will see if I can sort out some better details and try to explain steps to make it reproduceable for others.

I also want to say yes, the same unit are often opened in both editors.... 
« Last Edit: March 22, 2023, 01:30:13 pm by Tony Stone »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11926
  • Debugger - SynEdit - and more
    • wiki
Re: Unknown Identifier Search
« Reply #5 on: March 22, 2023, 01:34:12 pm »
I am starting the search from the message window list

Last night I seem to have noticed it is scrolling further to the right the larger the unit is.  I.E. 1000 lines scrolls further to the right than a unit that has 500 lines.

SO then the message in the message window has a location? What is it?

Any relation between that, and the editor pos? After the scroll, the editor status bar ought to show line and column. Maybe it went to the column, that should have been the line?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11926
  • Debugger - SynEdit - and more
    • wiki
Re: Unknown Identifier Search
« Reply #6 on: March 22, 2023, 01:36:57 pm »
Well, that was easy to test
Code: Text  [Select][+][-]
  1. testwatches.pas(64,5) Error: Identifier not found "xResultDBGType"

"Search identifier" and the editor jumps to line 5, column 64.  The error however was at line 64 column 5.

Tony Stone

  • Sr. Member
  • ****
  • Posts: 277
Re: Unknown Identifier Search
« Reply #7 on: March 22, 2023, 01:49:02 pm »
Ahhh... so it wasn't me losing my mind!  I'm here reconfiguring my laptop to try and reproduce it.(I am supposed to be working. lol).  So maybe it's a simple fix...

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11926
  • Debugger - SynEdit - and more
    • wiki

Tony Stone

  • Sr. Member
  • ****
  • Posts: 277
Re: Unknown Identifier Search
« Reply #9 on: March 22, 2023, 02:03:44 pm »
Thank you Martin!  I just realized even on my laptop it IS doing it but I was not noticing it because I was putting my error at like the 10th line!  So it wasn't behaving the same on my laptop as obviously as it does on larger files on my desktop! Either way you guys are the best.  But at the same time this is why I came here to sort out the bug before I even considered submitting a bug.  I have done that in the past when it is my own error and I feel really stupid wasting developers time on a non-existent bug.   :-[
« Last Edit: March 22, 2023, 02:14:04 pm by Tony Stone »

_Antares_

  • New Member
  • *
  • Posts: 13
Re: Unknown Identifier Search
« Reply #10 on: November 17, 2024, 11:34:20 am »
What? Lazarus already provides this?? I just posted about it how nice it would be to have something like this.

Would it be possible to allow the functionality to be bound to a certain keyboard shortcut? Would be awesome. Like: Ctrl+U on a name and the unit gets added to the uses section! :D

As for the issue with same identifier from different units:
While this case could occur, most identifiers should be fairly unique, I suppose.
If there are conflicts, the possible units in question could be presented in a selection dialog at least, so the user can add those to the uses clause and then go through the code deciding which unit to specify on each occurence of the identifier (which can be accomplished with search tool available, I suppose). Would be a valuable tool support still, IMHO.
« Last Edit: November 17, 2024, 11:40:23 am by _Antares_ »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11926
  • Debugger - SynEdit - and more
    • wiki
Re: Unknown Identifier Search
« Reply #11 on: November 17, 2024, 12:37:24 pm »
You can add key shortcuts yourself.

Tools > Options
Editor > Keymap

Find the command in the list. And assign one or two shortcuts of your own.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4652
  • I like bugs.
Re: Unknown Identifier Search
« Reply #12 on: November 17, 2024, 04:36:34 pm »
@Tony Stone, you experienced a bug that was fixed a year ago.
You should use the fixes_4 branch from Gitlab, or the 4.0 RC version, when studying and testing Lazarus features.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

bytebites

  • Hero Member
  • *****
  • Posts: 767
Re: Unknown Identifier Search
« Reply #13 on: November 17, 2024, 05:23:22 pm »
That message was posted year and half ago.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4652
  • I like bugs.
Re: Unknown Identifier Search
« Reply #14 on: November 17, 2024, 05:57:09 pm »
Oops right...
The reply from _Antares_ was new, the others were old.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

 

TinyPortal © 2005-2018