Recent

Author Topic: [SOLVED] "Ctrl+Space" causes an error with a cursor outside of code  (Read 625 times)

furious programming

  • Hero Member
  • *****
  • Posts: 582
  • Working on my own "loz alttp"-like game (FP+SDL2)
I am working on code for a game project (as a console project, not Application with forms) and ran into a very strange problem with code tools. It concerns two specific units of this project, named Game_InputMapping and Game_InputMappingAction. The former has the latter in uses section.

if I press Ctrl+Space on any place in the first unit, the IDE moves me to a random place in the second unit and shows the following error:

Code: Pascal  [Select][+][-]
  1. Game_InputMappingAction.pp (6,29) Error: cursor pos outside of code

The code structure is correct, the project builds and runs correctly. I've already tried everything — restarting the IDE, rebuilding the project (including cleanup), removing and adding paths again, removing and re-adding both units to the project. Unfortunately, it didn't help and the problem is still bothering me. I can't use the code tools function (code inside or jump to declaration) in the first unit at all, because each attempt ends with the above-mentioned error. Writing code without these features is inconvenient and slow.

What can cause this error? Where to look for problems?



The project contains several dozen units and include files (.inc). As the code for this project is closed (ultimately it will be a commercial game), I cannot publish its sources for testing. If anyone has any tips, please share them — I will be very grateful.

If you need more information, ask for it, I will try to provide everything you need.
« Last Edit: June 16, 2022, 04:29:03 pm by furious programming »
Lazarus 2.2.0 with FPC 3.2.2 (2022-01-02), Windows 10 — all 64-bit

Thaddy

  • Hero Member
  • *****
  • Posts: 11764
You mean ctrl-space in YOUR program? The IDE uses that shortcut already....
« Last Edit: June 15, 2022, 03:59:21 pm by Thaddy »
Black themes should be banned.

furious programming

  • Hero Member
  • *****
  • Posts: 582
  • Working on my own "loz alttp"-like game (FP+SDL2)
You mean ctrl-space in YOUR program?

Not in my program, but in the IDE (in Lazarus), when my game projetc is loaded.

The Game_InputMapping module is somehow buggy, because I can't use functions such as "code completion", "code insight" or "jump to declaration" in it, but also the Lazarus editor doesn't see any include files at all. If I hold Ctrl and navigate mouse cursor to the name of the .inc file it doesn't turn into a link — despite the fact that this file is in the same directory as Game_InputMapping and this directory is added to the paths in the project settings window.

I use the same scheme throughout the project. I have the .pp files placed throughout the directory tree (few levels), and if any .pp file uses an .inc file with a separate logic, I put both files in the same directory. See the screenshots in the attachments.
« Last Edit: June 15, 2022, 04:37:46 pm by furious programming »
Lazarus 2.2.0 with FPC 3.2.2 (2022-01-02), Windows 10 — all 64-bit

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 8095
  • Debugger - SynEdit - and more
    • wiki
What can cause this error? Where to look for problems?

There isn't *one* specific place....
 
When you press ctrl-space the IDE must read all your sources, to find possible completion.
The part of the IDE that does that is called "codetool". It has it's own pascal parser. And that parser might have a bug. Therefore fpc may be able to compile. But codetool may not be able to read your code.

How to fix... Ultimately: find sources that can be used to *always* reproduce the problem.  Then report a bug.



In the meantime....

Are the error you get sporadic?
I.e. if you restart the IDE, can you then do the ctrl-space that failed before?
That is can you do it at least once, just after starting the IDE. Even if later it will fail again?

Then it may be that codetools cache gets corrupted.
If you do not want to restart the IDE, then try this
- go up one or two lines from the "jumped to" error pos.
- make any dummy change to the source
- invoke completion on the dummy change
- undo the change
That normally forces codetools to reread that unit.




There is the menu: View > IDE internals > show codetool node....
(or similar)

That shows some of the internal info from codetool.

If you can't find an example to 100% reproduce it then you can try to report without this.
The report will need the sources on which it happens.

- At the very least the file that codetool reports the error in (with inc files), but probably others to.
- The code where you invoked completion
- All the content from the above menu (opened while the error file is active)



furious programming

  • Hero Member
  • *****
  • Posts: 582
  • Working on my own "loz alttp"-like game (FP+SDL2)
There isn't *one* specific place....

I understand it, but I was hoping that someone had such a problem at one time and somehow dealt with it. Perhaps the way he solved this problem himself would be helpful in my case. Is there anybody like that?
 
Quote
When you press ctrl-space the IDE must read all your sources, to find possible completion.
The part of the IDE that does that is called "codetool". It has it's own pascal parser. And that parser might have a bug. Therefore fpc may be able to compile. But codetool may not be able to read your code.

It is very possible that this is a bug in codetool, because the project code is valid and compilable, while this one specific unit (i.e. Game_InputMapping) is having problems and the codetool is going crazy and it reports the error cursor pos outside of code in a completely different unit, although the codetool works fine in that unit and has no problems.

The problem, however, is that I removed this unit from the project and its path from the project settings, then I created a new unit (I named it the same), the IDE itself added it to the file tree and asked to add the path (which I confirmed in the dialog window), and nevertheless, nothing has changed and this problem continues to bother me.

Quote
Are the error you get sporadic?
I.e. if you restart the IDE, can you then do the ctrl-space that failed before?
That is can you do it at least once, just after starting the IDE. Even if later it will fail again?

This error only affects the file mentioned — Game_InputMapping — and is reproducible every time, no matter what the cursor position in it and no matter how many times I restart the IDE. This problem only affects the Game_InputMapping unit and does not disappear even if I remove all my code from this unit (leaving only the unit template).

Quote
Then it may be that codetools cache gets corrupted.
If you do not want to restart the IDE, then try this
- go up one or two lines from the "jumped to" error pos.
- make any dummy change to the source
- invoke completion on the dummy change
- undo the change
That normally forces codetools to reread that unit.

It doesn't help, the problem won't go away.

Quote
There is the menu: View > IDE internals > show codetool node....
(or similar)

There is only what is shown in the attachment. But I did not find anything helpful in these options.
Lazarus 2.2.0 with FPC 3.2.2 (2022-01-02), Windows 10 — all 64-bit

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 8095
  • Debugger - SynEdit - and more
    • wiki
If it is 100% reproducible, then it calls for a bug report.

If the sources are private, then maybe once someone picks up the bug, that developer can contact you and receive them in confidence (you would need to keep a snapshot, of the current version).


About the menu entry. My bad, it's only added with the package cody installed (afaik, it's cody).

Btw: Cody, most useful => "identifier dictionary"
(may take a couple of sessions, before it has enough data, but then can find identifiers in units, even if they are not used by the project)


furious programming

  • Hero Member
  • *****
  • Posts: 582
  • Working on my own "loz alttp"-like game (FP+SDL2)
Damn, I solved this problem. I wanted to write about it right away, but the forum was not reachable (it happens quite often), so I went for a walk.

I deleted only the Game_InputMappingAction file from the project files tree, because I was redirected to it when I tried to use the codetool in the Game_InputMapping unit. And even though Game_InputMappingAction was no longer part of the project, codetool still redirected me to it — load it to the editor window and show the above mentioned error.

So I deleted the Game_InputMappingAction file from the disk (I actually moved it to a different directory) so the IDE could not find it. In the code editor, I moved to the Game_InputMapping unit and pressed Ctrl+Space in a random place — the IDE did nothing, no error appeared, and the window with the list of identifiers appeared (caused by a shortcut). After re-adding the Game_InputMappingAction unit to the project (using the Project Inspector window), the codetool started working properly and this problem no longer occurs.



Apparently the codetool did have corrupted data. However, I still don't know where this problem came from and what caused it, so even if I would like to report a bug, I don't have any information on how to cause it — only the error message remains.

Problem solved, and in case someone also encounters one, try it in the same way:
  • remove the unit to which the IDE redirects from the project and shows the error cursor pos outside of code in it, using the Project Inspector window,
  • delete this file from the disk, so that the IDE no longer has any access to it (just temporarily move this file to another directory),
  • open in the IDE the unit in which codetool did not work, place the cursor anywhere and press Ctrl+Space — no error should pop up,
  • restore a deleted file to its previous location (or create new),
  • open the Project Inspector window and add the previously deleted file to the project,
  • try to use codetool on both units — it shouldn't be any problem anymore.
« Last Edit: June 16, 2022, 04:30:41 pm by furious programming »
Lazarus 2.2.0 with FPC 3.2.2 (2022-01-02), Windows 10 — all 64-bit

BeniBela

  • Hero Member
  • *****
  • Posts: 841
    • homepage
Re: [SOLVED] "Ctrl+Space" causes an error with a cursor outside of code
« Reply #7 on: June 16, 2022, 09:50:27 pm »
Lazarus would be better if it  would just ignore the error and show a list anyways when there is an error. It could show the ctrl+w list as fallback if it really cannot get anything for the normal list

I usually use the newest FPC syntax features (generics, typehelpers, etc.) before Lazarus knows them, so I can almost never use Codetools. Eventually the error is fixed, but by then I am using a new syntax, and get another error from it

PascalDragon

  • Hero Member
  • *****
  • Posts: 4282
  • Compiler Developer
Re: [SOLVED] "Ctrl+Space" causes an error with a cursor outside of code
« Reply #8 on: June 17, 2022, 09:00:36 am »
Lazarus would be better if it  would just ignore the error and show a list anyways when there is an error. It could show the ctrl+w list as fallback if it really cannot get anything for the normal list

It should at least show the error in the message box as it does now, cause otherwise users might think that everything is alright and then complain that they don't get fancy code completion.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 8095
  • Debugger - SynEdit - and more
    • wiki
Re: [SOLVED] "Ctrl+Space" causes an error with a cursor outside of code
« Reply #9 on: June 17, 2022, 01:22:11 pm »
Lazarus would be better if it  would just ignore the error and show a list anyways when there is an error. It could show the ctrl+w list as fallback if it really cannot get anything for the normal list

Well, then it has been better for quite some time...

Menu:  Tools > Options
Use the search box, and look for "error", you will find
   Codetools > Identifier Completion > "Jump to error"

Which you can switch off.

According to my tests:
- get the error in the message box
- get the word completion (I don't think, there would ever be a "partial" codetool list, but I did never check for it)

It may however be, that getting the word completion depends on the kind of error encountered... It works for me.


-- EDIT

No idea why the default is as it is. But probably:
- original behaviour, from the days of yore
- people might want to know, if they have actual errors in their source. And that is not just by accidentally spotting it in the messages window.

The latter of course depends on what the most common cause for errors is. And that differs for each individual. If you are new to pascal, you may have lot of errors of your own.

IMHO, the best would be, if instead of jumping, the drop down had an entry "Syntax error ... found at ..." or similar.
That entry could be non-selectable. It would just be a more visual indicator. You could then still click the error in the message-view. Or it could be linked to a hot-key. Or even offer an automated quick fix....

But in the absence of this....
« Last Edit: June 17, 2022, 01:31:17 pm by Martin_fr »

 

TinyPortal © 2005-2018