How to Get Sibling Intelliprompt Imports with Shared Language

SyntaxEditor Python Language Add-on for WPF Forum

The latest build of this product (v26.1.1) was released 14 days ago, which was before this thread was created.
Posted 1 days ago by Shaun Gannon
Version: 25.1.4
Avatar

Hello,

I'm using the Actipro PythonSyntaxLanguage for WPF with a single shared PythonSyntaxLanguage and IProject instance across multiple open Python documents.

I'd like IntelliPrompt to automatically resolve sibling modules relative to the currently edited document.

For example, if I have:

D:\Project1\main.py D:\Project1\helper.py

And separately:

D:\Project2\main.py D:\Project2\helper.py

I'd like import helper in each main.py to resolve to the corresponding helper.py.

Currently, the only way I've found to achieve this is to add each opened file's directory to IProject.SearchPaths. However, adding broad directories can cause Actipro to recursively scan large portions of the filesystem, resulting in significant performance problems.

What is the suggested approach to get this to work? 

Note: At start-up, I initialize an IProject instance on a background thread with all of the search paths from PYTHONPATH and sys.path and then swap in that IProject instance to be the active project of my PythonSyntaxLanguage when it is complete. However, such an approach seems messy for opening new documents. 

Thank you!

Comments (2)

Answer - Posted 20 hours ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Shaun,

You can continue sharing one PythonSyntaxLanguage and IProject. Set each document's FileName to the module's full path, then call AmbientPackageRepositoryProvider.Repository.QueuePackageCacheUpdate(directoryPath, isRootPath: true, recurse: false) for its directory. This prepares sibling module information without recursively scanning subfolders or adding the directory to SearchPaths. You can then enter "import helper" and get member completion for the corresponding local "helper.py" module. Refresh the cache when those files change.

We have also updated the future build v26.1.2 code so it includes sibling module and package names in completion suggestions after "import" or "from". These suggestions will use the current document's directory, with local names taking precedence over matching project search paths. This fixes the issue in the current version where "import helper" resolves (assuming the document's FileName is set) but the "helper" doesn't show in the IntelliPrompt completion list after the "import" keyword.


Actipro Software Support

Posted 2 hours ago by Shaun Gannon
Avatar

Thank you for the quick response! That makes sense.

I don't mean to try to peer into the implemention too much, but if I can route around SearchPaths by directly queuing a cache update operation myself, what role does an IProject and its SearchPaths collection actually play in all of this? I know that adding to SearchPaths causes cache update operations to be queued, but is that it? Does removing an item from the SearchPaths have any meaningful impact on behavior? 

Add Comment

Please log in to a validated account to post comments.