Inteliisense for Nested modules

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
KeHE Distributors
Posts: 9
Joined: Thu Jan 11, 2018 11:35 am

Inteliisense for Nested modules

Post by KeHE Distributors »

Product: PowerShell Studio 2020 (64 Bit)
Build: v5.7.174
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.16299.0

Does Powershell Studio Support Intellisense for Nested Modules in a Powershell Module Project? If not, is that on a road map?

I have a PS Module Project with a nested module defined in the manifest. The code works as expected when I execute the module but when editing, Powershell Studio does not recognize the functions from the nested module.

You can see in the attachments I have the nested module defined in the manifest file. In the main module code, the function "New-CronJob" is from the nested module but is not recognized by the studio and appears in gray.
Attachments
Code.JPG
Code.JPG (45.77 KiB) Viewed 743 times
Manifest.JPG
Manifest.JPG (32.53 KiB) Viewed 743 times

User avatar
brittneyr
Site Admin
Posts: 500
Joined: Thu Jun 01, 2017 7:20 am

Re: Inteliisense for Nested modules

Post by brittneyr »

This is most likely caused by the cache for PowerShell Studio not having that module information. Is the module 'CronTab' listed in the Object Browser panel:
SPS_ObjectBrowser.png
SPS_ObjectBrowser.png (201.29 KiB) Viewed 725 times
If its not, then your cache needs to be rebuilt or you can import the module via the cache editor.
SPS_RebuildCache.png
SPS_RebuildCache.png (84.69 KiB) Viewed 725 times
SPS_cacheeditor.png
SPS_cacheeditor.png (112.9 KiB) Viewed 725 times
Brittney Ryn
SAPIEN Technologies, Inc.

User avatar
KeHE Distributors
Posts: 9
Joined: Thu Jan 11, 2018 11:35 am

Re: Inteliisense for Nested modules

Post by KeHE Distributors »

CronTab is not listed in the object browser. following your suggestion, I rebuilt the cache but it did not appear. I then went to the editor and tried to import it but it failed with "Import failed. Please check permissions and script execution policies" (screenshot) (Note: I am set to bypass for execution policy)

To be clear, this is not a module loaded in the WindowsPowershell\Modules folder. Its a module sitting in a subfolder of the project (screen shot). I happen to have called the subfolder "Modules" which I see is misleading of course from my initial description.

Perhaps I am approaching it incorrectly. I am trying to include with the project some sub-modules. I don't want them to be Required Modules that try to install from the PS Repo. I do know from a PS execution perspective, it does run as expected so I believe using the module being in a subfolder to the main module and defined in "ModuleList" works.

Is there a different way I should be using nested modules in the project so the intellisense can read it?
Attachments
Project.JPG
Project.JPG (28.41 KiB) Viewed 720 times
Error.JPG
Error.JPG (68.44 KiB) Viewed 720 times

User avatar
brittneyr
Site Admin
Posts: 500
Joined: Thu Jun 01, 2017 7:20 am

Re: Inteliisense for Nested modules

Post by brittneyr »

What are the permissions of the psm1 file you tried to import? It is strange that the import failed. Also, what is your PowerShell execution Policy set to?

You use the NestedModules element of the psd1 file to reference the path of the nested module to be loaded. PowerShell will look in the paths specified in the $env:PSModulePath environment variable when searching for available modules on a system. Therefore, this requires that the Nested module's path be relative to a location in the $env:PSModulePath.
Brittney Ryn
SAPIEN Technologies, Inc.

User avatar
KeHE Distributors
Posts: 9
Joined: Thu Jan 11, 2018 11:35 am

Re: intellisense for Nested modules

Post by KeHE Distributors »

I have full rights to the file. I created and placed it into the folder.

As to the nestmodule, when including a folder path as I have, powershell seems to including looking in a path relative to the module itself. It might try the $env:PSModulePath as part of a search order but it does seem to find it when its local to the module.

To be clear, Powershell does execute the code as expected and works properly. It sounds like Powershell Studio however does not attempt to import the module from the nestedmodules element if the sub module path is relative to the module itself and not located in the $env:PSModulePath?
Last edited by KeHE Distributors on Thu May 28, 2020 12:04 pm, edited 1 time in total.

User avatar
KeHE Distributors
Posts: 9
Joined: Thu Jan 11, 2018 11:35 am

Re: intellisense for Nested modules

Post by KeHE Distributors »

I created a sample project using a sub-folder of the project to hold the nested module.
TestNestedmodules.zip
Sample Project
(4.08 KiB) Downloaded 18 times

You can see in the studio, the function from the sub-module is labeled as unknown.
Submodule.JPG
Submodule.JPG (28.8 KiB) Viewed 506 times

When the project runs though, powershell successfully locates and execute the sub module function.
Output.JPG
Output.JPG (27.85 KiB) Viewed 506 times

Note: I tried to import the sub module to the cache in PS Studio and it succeeded with this example but the function from the sub module still shows as unknown in the editor.

User avatar
brittneyr
Site Admin
Posts: 500
Joined: Thu Jun 01, 2017 7:20 am

Re: Inteliisense for Nested modules

Post by brittneyr »

We are currently investigating this and will get back to you with more information.
Brittney Ryn
SAPIEN Technologies, Inc.

User avatar
brittneyr
Site Admin
Posts: 500
Joined: Thu Jun 01, 2017 7:20 am

Re: Inteliisense for Nested modules

Post by brittneyr »

From the example you provided, I was able to get intellisense working with your nested modules by doing the following:
1. Update the values for ModuleList and NestedModules in the psd1 to the following:
  1.  @('.\SubModules\MySubmodule.psm1')
I was not able to run Test-Module.ps1 until I updated this.
2. Open the cache editor and make sure to have the version of PowerShell you are working with selected:
SPS_CacheEditorVersion.png
SPS_CacheEditorVersion.png (45.5 KiB) Viewed 382 times
Import the nested module and locate the nested module in the SubModule folder. Make sure you can see the module in the list and is checked.
Close the cache editor.
3. In PowerShell Studio, reload the cache:
SPS_Reload-Cache.png
SPS_Reload-Cache.png (30.19 KiB) Viewed 382 times
The module should now be visible from the Object Browser panel:
SPS_ObjectBrowser.png
SPS_ObjectBrowser.png (201.29 KiB) Viewed 382 times
The intellisense for the nested module should now be working.
Brittney Ryn
SAPIEN Technologies, Inc.

Locked