How to make the IDE recognize Keyword as Arguments in Custom Python Library?

I’ve created some custom python libraries that, similar to the builtin run_keword and its variants, have Keywords that take other Keywords as arguments. It works fine, but it is currently not user friendly to work with, because the IDE is interpreting it as a string so I don’t get the correct syntax highlighting and autocompletion in my IDE.

With Keywords like the builtin “Run Keyword”, the syntax highlighting and autocompletion works, but I couldn’t really figure out why that is, even after looking at the source code. I’m not experienced with this stuff, but I guess it must be something hard-mapped into the LSP?

Any way I could make this work with my keywords?

Thanks!

Which IDE are you using?

I’m using VS Code and (your?) Extension “Robot Code” :slight_smile:
(Sorry for calling it an IDE :smiley: )

As an example here is a Keyword of one of my custom python libraries taking keywords as an argument:

I’m not sure if there is a way to mark that argument as a Keyword instead of a string, if you look at the bultin library and run_keyword Keyword arguments, they also don’t have anything special on them:

Unfortunately, this is not possible because there is no standardised interface for implementing such keywords.

In RobotCode this is hard-coded for the BuiltIn keywords Run Keyword, Run Keyword If etc. because we know how to handle them. If, as in your case, it is a variant where it is implemented differently again, how am I supposed to know? On the other hand, I don’t want to maintain all variants.

There have long been discussions in the RobotFramework that something like this should be implemented, see for example here Enhance parser to optionally detect keywords used in arguments of other keywords (e.g. `Wait Until Keyword Succeeds`) · Issue #4857 · robotframework/robotframework · GitHub
But they have never really led to a solution.

I could also imagine that the whole thing could be done on the RobotCode side, so it doesn’t have to happen in the RobotFramework. However, this would again require a defined API. Can you maybe open an issue as an extension at RobotCode Issues · d-biehl/robotcode · GitHub and describe what you want and link to this post, maybe also find some matching issues in RobotFramework and link to them. I’m not sure when I could implement something like that, but I don’t want to forget the idea.

And what else I wanted to say: Great idea, your library!!!

2 Likes