robotcode icon indicating copy to clipboard operation
robotcode copied to clipboard

[Enhancement] New keywords not found until cache is manually cleared

Open AndersHogqvist opened this issue 11 months ago • 4 comments

Describe the bug If I write a new keyword in an existing test library and use it in a .robot/resource file, RobotCode doesn't recognize it until I do a "Clear Cache And Restart Language Servers".

Steps To Reproduce Steps to reproduce the behavior:

  1. Add a new keyword in an existing test library
  2. Add a call to that keyword in a .robot/resource file where the test library is used

Expected behavior When I save the test library file after adding the new keyword, RobotCode should recognize that a test library that it's already aware of has changed and update the cache automatically. This should also be the case when a keyword is removed.

Desktop (please complete the following information):

  • VS Code Version 1.98.0
  • RobotCode Version 1.0.0
  • OS: Windows
  • Python Version 3.11.9
  • RobotFramework Version 7.2.2

AndersHogqvist avatar Mar 06 '25 09:03 AndersHogqvist

How did you add the new keyword? There are so many ways to do this.

And where is your repository located and your libraries located, directly on the hard drive?

Sometimes this can happen, because RobotCode listens to file changes from vscode, but vscode is not able to send this everytime because of the location of the repository.

d-biehl avatar Mar 06 '25 22:03 d-biehl

Ok, this might be an edge case maybe. I have a test library that I import like this:

.robot file:

*** Settings ***
Documentation       Test suite for the SwRS tests
Metadata            SemVer    ${SEMVER}

Library             ../../python/SwRSRAE3.py

If I add a keyword in the SwRSRAE3 class it gets picked up by RobotCode without the need to manually clear the cache. However, the keywords I've been adding lately have been added to AgvHelper, a parent class to SwRSRAE3:

SwRSRAE3.py:

"""Module containing the keywords for the SwRS RAE 3 test suite"""

import random
import time

import AgvHelper
from robot.api.deco import keyword, library, not_keyword
from robot.api.exceptions import Failure

@library
class SwRSRAE3(AgvHelper.AgvHelper):

AndersHogqvist avatar Mar 07 '25 08:03 AndersHogqvist

Currently, RobotCode only has access to information provided by Libdoc, which includes the file or module where the keyword class is defined. It does not, however, have insight into the internal structure of a class, such as parent classes and their respective file locations.

If you import a library as a file (as shown in the example above), RobotCode can only track changes in that specific file. Consequently, if you modify keywords within a parent class located in a separate file, RobotCode won't be able to detect those changes.

On the other hand, if you import your library as a Python module—which is the recommended approach—RobotCode attempts to track all files belonging to that module and monitors changes across all related files.

For details on different ways to import libraries in Robot Framework, see the official documentation.

I'm currently unable to confirm whether this approach fully addresses your issue due to limited investigation time. Given this uncertainty, the issue cannot be immediately resolved, but I will reclassify it from a bug to an enhancement. We might revisit this once the planned rewrite of Robot Framework's import functionality is complete.

d-biehl avatar Mar 10 '25 09:03 d-biehl

I've added the path to the Python Path:

"robotcode.robot.pythonPath": [
"HIL-rig/python"
]

Then I changed the import to

Library        SwRSRAE3

A newly created keyword in the parent class of SwRSRAE3 was immediately picked up by RobotCode, but any subsequent changes or keyword additions in the file where not.

However, it's not a show stopper by any means so I completely understand if this goes to the bottom part of your priority list.

AndersHogqvist avatar Mar 14 '25 08:03 AndersHogqvist