Code Tools: the "Find declaration" option jumps to the routine body instead of to its declaration
- Lazarus/FPC Version: Lazarus 3.0 (rev lazarus_3_0) FPC 3.2.2 x86_64-win64-win32/win64
- Operating System: Windows 10, 64-bit
- CPU/Bitness: 64-bit
What happens
The Find declaration
option does not jump to the routine declaration, but to its implementation (body). By default, this option has the Alt+Up
shortcut assigned, but regardless of whether I use this shortcut, select this option from the context menu, or use the mouse and Ctrl+LMB
shortcut, the jump takes place to the function body.
Below is an example of an incorrect jump—to the implementation, instead of the declaration. All within the same module. It doesn't matter if I use Alt+Up
or Ctrl+LMB
, the result is the same:
From what I have researched, a jump to a function declaration occurs only when the declaration is in a module other than the call to the function from which we jump. So in short:
- If we use a jump to function declaration within the same module, the jump will be to the implementation (body) of that function.
- If we use a jump to function declaration that is in a different module than the function call on which we use the jump, the jump will actually take place to the declaration of that function.
Note that the Jump directly to method body
option is disabled in the IDE settings. If I enable it, the jump always takes place to the implementation of the function, regardless of whether it is within the same module or between modules.
Interestingly, if this option is enabled, the jump will occur correctly, but the caret will be placed at the beginning of the first line in the main begin end
block of the routine. However, if it is disabled and this unwanted jump to the implementation occurs (instead of to the function declaration), the caret is placed at the beginning of the function name, in its header (this can be seen in the attached gif).
What did you expect
If the Jump directly to method body
option is disabled, the Find declaration
option, no matter how used, should always jump to the function declaration (prototype), regardless of whether it is in the same file or not. Additionally, no matter which section it is in—interface
or implementation
. The function prototype can be located in the implementation
section if it is a forwarded function.
If the Jump directly to method body
option is enabled, the Find declaration
option should always jump to the implementation (body) of the function. Here, too, regardless of which section and file its implementation is located.