robotcodedev / robotcode

RobotFramework support for Visual Studio Code
https://robotcode.io
Apache License 2.0
168 stars 13 forks source link

[QUESTION] Multi keyword error keeps showing in VSCode #188

Closed tibitTW closed 7 months ago

tibitTW commented 7 months ago

Please describe. I have a robot suite and the Suite Setup looks like this:

*** Settings ***
Suite Setup         Run Keywords
...                     Set Library Search Order    MASTER    AND
...                     HERO6: Connect

The "My Keyword" is from module I wrote and puts in workspace folder, and it keeps highlighted with error:

Multiple keywords with name 'HERO6: Connect' found. Give the full name of the keyword you want to use: 
...

Below is RobotCode settings in settings.json, and I pretty sure RobotCode extension can load my module, since I can track keyword in my robot suite with cmd + click

"robotcode.robot.pythonPath": [".", ".venv/bin/python"]

I'm not sure if this is an issue of RobotCode or vscode, is there any solution?

Desktop (please complete the following information):

d-biehl commented 7 months ago

Have you imported your library twice? Or is there another library with the same keyword?

The keyword that is found multiple times is HERO6: Connect and not My Keyword, in which line does the error occur?

tibitTW commented 7 months ago

Sorry for my mistake, it's should be the below code.

*** Settings ***
Resource            ../../../Keywords/Main.robot
Suite Setup         Run Keywords
...                     Set Library Search Order    MASTER    AND
...                     HERO6: Connect

This problem is happened on HERO6: Connect, and the resource file Main.robot import 2 times of my module indeed (like the below code):

Library        path.to.my.module.HERO6Client  WITH NAME  MASTER
Library        path.to.my.module.HERO6Client  WITH NAME  SLAVE

I want to ensure that would I get these warning if I already use the keyword Set Library Search Order to specify the keyword I want? Is it expected behavior or not?

d-biehl commented 7 months ago

ok, I understand, unfortunately RobotCode does not support Set Library Search Order, as this can only be evaluated dynamically at runtime. However, RobotCode only performs a static analysis.

A workaround is, and because it is actually more readable, simply put the namespace in front of the keyword:

*** Settings ***
Library        path.to.my.module.HERO6Client  WITH NAME  MASTER
Library        path.to.my.module.HERO6Client  WITH NAME  SLAVE
Suite Setup     MASTER.HERO6: Connect

You can also replace the WITH NAME with AS, WITH NAME is deprecated and will be removed in one of the next RobotFramework versions.

*** Settings ***
Library        path.to.my.module.HERO6Client  AS  MASTER
Library        path.to.my.module.HERO6Client  AS  SLAVE
Suite Setup     MASTER.HERO6: Connect

If you do not want this, you can also simply hide the error by telling RobotCode to ignore this error.

*** Settings ***
Resource            ../../../Keywords/Main.robot
Suite Setup         Run Keywords
...                     Set Library Search Order    MASTER    AND
...                     HERO6: Connect    # robotcode: ignore

Simply add # robotcode: ignore ignore in the line where the error occurs as a comment.

tibitTW commented 7 months ago

OK, I'll give it a try, thanks alot!!