vscode-rf-language-server icon indicating copy to clipboard operation
vscode-rf-language-server copied to clipboard

Goto definition matches single word

Open patjlm opened this issue 7 years ago • 13 comments

First, thank you for this project! Using the latest 0.5.1, I can't seem to make the Goto Definition (F12) work. It complains it cannot find the definition for the word my cursor is on.

For example, putting my cursor inside the word "Little" in "My Little Test" and hitting F12, it would show a tooltip saying "No definition found for 'Little'"

I tried selecting the whole keyword, but it still matches only the first or last word (depending if the cursor is on he first or last word...)

CTRL-T works and shows my that keyword.

patjlm avatar Apr 05 '17 13:04 patjlm

Hi and thank you for your feedback!

Did you try the Goto Definition from a place where the keyword is used, or where it is defined? I.e. in 1) or in 2) in the example below? The extension incorrectly says "No definition found for 'word'" when you try to go to definition from where the keyword is already defined. Also if the definition is not found, VSCode by default uses only the current word under the cursor for the error message. The extension does usually detect the whole name for the keyword, but the error message can be a bit confusing. If it was from place where the keyword is called, could you provide an example code that reproduces the problem?

*** Keywords ***
# Define keyword, 1)
My Little Keyword
    [Arguments]    ${arg}
    Call Another Keyword

# Define another keyword
Another Keyword
    # Call the first keyword, 2)
    My Little Keyword      Arg to pass
    

tomi avatar Apr 05 '17 17:04 tomi

It would be from location 2) in your example. I'll try to provide an example from work tomorrow morning

patjlm avatar Apr 05 '17 19:04 patjlm

quite confusing: I opened a fresh empty folder, created a file test.robot and pasted your example. Goto Definition then worked. I upgraded vscode to the March release (i probbaly should not have done that in the middle of this tests...), which restarted vscode. Then Goto Definition was not working anymore. Created test2.robot with same content: Goto definition was working there, but still not in test.robot.

One note: I am using vscode on Windows.

I think I actually found something. On a file where Goto Definition is not working, if a do a change (add a blank line for example) and save, then it starts working (after 1 or 2 seconds). If I restart vscode and do not change files, it does not work (even after few seconds). Do you parse robot files on startup or folder open ?

patjlm avatar Apr 06 '17 07:04 patjlm

The robot files are parsed when

  1. A folder or file is opened
  2. A file changes
  3. A new file is added

It sounds like there are some conditions that don't cause the file not being parsed correctly. I'll try to investigate this. Also it's clear that better error messages are needed.

You can always use the command RF Intellisense - Reindex robot files in the workspace to reindex all the files in the workspace. You can also open the output with View: Toggle Output command and select Robot Framework Intellisense Server and see if the log gives you some idea about why the definition is not found.

tomi avatar Apr 06 '17 17:04 tomi

Here is the output when I just open vscode:

Initializing...
onDidChangeConfiguration...
buildFromFiles { files: 
   [ 'd:\\tmp\\vscodetest\\test.1.robot',
     'd:\\tmp\\vscodetest\\test.robot' ] }
Parsing d:\tmp\vscodetest\test.1.robot
Parsing d:\tmp\vscodetest\test.robot

So files are indeed being parsed

Then when I hit on F12 on keywork reference (and it fails to find it):

onDefinition...

When I change the file (add a line), before saving

onDidChangeTextDocument

And when I save:

onDidChangeWatchedFiles [object Object]

And then F12 works with this in the output again:

onDefinition...

Note that using RF Intellisense - Reindex robot files in the workspace does not make it work, even though it does print in the output that it's parsing the files.

patjlm avatar Apr 07 '17 07:04 patjlm

The previous versions (before 0.7.0) of the extension had a short delay before the changed file was parsed. It might be that this somehow caused the issue. Also the logging has been improved in the latest release to print more information about why a definition is not found. More logging can be enabled by setting the parameter rfLanguageServer.logLevel to debug. Even more logging can be enabled by setting the parameter rfLanguageServer.trace.server to verbose.

Could you test this with the latest version and see if this is still an issue?

tomi avatar Jun 27 '17 17:06 tomi

Hi, I've just had a similar problem now, with latest version of Code 64-bit and latest version of the plugin. Running the Reindex command didn't help, but adding a dummy change and reverting it did.

MiroslawBorowiecki avatar Aug 16 '17 09:08 MiroslawBorowiecki

Hi, Is there any way to trigger robot files parsed without adding a dummy change? When I enter the file which I want to edit, I will assume all reference(*.py, resource, lib) were beening parsed. Thanks!

WindAzure avatar Mar 19 '18 16:03 WindAzure

Hi. I'm experiencing the same issue on Windows 10 with VS Code 1.21.1 and Robot Framework Intellisense 2.0.0. F12 only works for global variables after I've modified the file containing the variable I want to find the definition of. It never works for keywords it seems. Any plans to deliver a fix for this issue in near future?

bergstenarn avatar Mar 28 '18 19:03 bergstenarn

+1

allan-medeiros avatar Feb 21 '19 00:02 allan-medeiros

Hey, I'd love to fix this but I need a way to reproduce it. I am not able to do it on my Mac machine. If someone could include minimal steps to on how to do that it would be highly appreciated. Please include:

  1. The files and their contents
  2. Steps needed for this to happen
  3. The output when rfLanguageServer.logLevel has been set to debug

tomi avatar Mar 02 '19 08:03 tomi

Hi, i am attaching some sample where i see this and other reported issues. vscode_bug.zip When opening the folder, you can find the robot file under "tests" folder.

Observed behavior in this robot file is that it is possible to run the GoTo definition feature for the python keyword in the testcase(TC-1), but not for other python keywords called from keywords in this file (Load Data). Note that they belong to two different files, but both are in the workspace(the other folder on the same level as tests, includes the bdd folder) and they are also added to PYTHONPATH. Additionally, nonrelevant files are not included in this file so you may notice errors on the python files, but reproducing the observed behavior should still be possible

log output from the working GoTo call: onDefinition... Parent is a call expression, finding a keyword definition

log output from the non-working call: onDefinition... Parent is a call expression, finding a keyword definition No matching file found for namespace COMMON Keyword definition 'Load verification data from file ${TEST_DATA_FILE}' not found from the workspace

paniego avatar Aug 09 '19 11:08 paniego

Same problem here. Log:

onDefinition...
Parent is a call expression, finding a keyword definition
No matching file found for namespace Dado que o usuário esteja logado
Keyword definition '' not found from the workspace
[Trace - 15:02:32] Received response 'textDocument/definition - (23)' in 10ms.
No result returned.

VS 1.39.2 plugin 2.8.0

I found how to solve that, in my case it was the dot in the end of each phrase. By removing the "." im able to find the keyword resource, apparently the dot is stopping the plugin's scan. I believe its the case for alot of ppl here, @paniego your keywork is COMMON.Load and is just looking for "COMMON" I Believe its a good idea to fix that.

vinavega avatar Oct 28 '19 18:10 vinavega