Forum > Editor

[SOLVED] "Ctrl+Space" causes an error with a cursor outside of code

(1/2) > >>

furious programming:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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.

Thaddy:
You mean ctrl-space in YOUR program? The IDE uses that shortcut already....

furious programming:

--- Quote from: Thaddy on June 15, 2022, 03:44:39 pm ---You mean ctrl-space in YOUR program?

--- End quote ---

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.

Martin_fr:

--- Quote from: furious programming on June 15, 2022, 12:34:12 pm ---What can cause this error? Where to look for problems?

--- End quote ---

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:

--- Quote from: Martin_fr on June 16, 2022, 12:02:43 pm ---There isn't *one* specific place....

--- End quote ---

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.

--- End quote ---

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?

--- End quote ---

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.

--- End quote ---

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


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

--- End quote ---

There is only what is shown in the attachment. But I did not find anything helpful in these options.

Navigation

[0] Message Index

[#] Next page

Go to full version