Personal tools
You are here: Home Forum Use Using autcompletion with Visual studio code

Using autcompletion with Visual studio code

Up to Use


This forum is DEPRECATED, please create new topics in the new SALOME forum.
For existing topics please transfer them to the new forum.

Using autcompletion with Visual studio code

Posted by samir1291 at March 08. 2019

Is it possible to add autcompletion feature while writing Salome scripts in Visual Studio Code?
I tried to add
/home/s1291//Salome_9.2_UBUNTU1804/SALOME-9.2.0-UB18.04-SRC/BINARIES-UB18.04/KERNEL/lib/python3.5/site-packages/salome
to PYTHONPATH environment variable in ~/.bashrc file but there is no autocompletion!
Any idea?
Salome

:PHA+SXMgaXQgcG9zc2libGUgdG8gYWRkIDxnIGNsYXNzPSJncl8gZ3JfMzIgZ3ItYWxlcnQgZ3Jf c3BlbGwgZ3JfaW5saW5lX2NhcmRzIGdyX3J1bl9hbmltIENvbnRleHR1YWxTcGVsbGluZyBpbnMt ZGVsIG11bHRpUmVwbGFjZSIgaWQ9IjMyIiBkYXRhLWdyLWlkPSIzMiI+YXV0Y29tcGxldGlvbjwv Zz4gZmVhdHVyZSB3aGlsZSB3cml0aW5nIFNhbG9tZSBzY3JpcHRzIGluIFZpc3VhbCBTdHVkaW8g Q29kZT88L3A+PHA+SSB0cmllZCB0byBhZGQ8L3A+PHA+YC9ob21lL3MxMjkxLy9TYWxvbWVfOS4y X1VCVU5UVTE4MDQvU0FMT01FLTkuMi4wLVVCMTguMDQtU1JDL0JJTkFSSUVTLVVCMTguMDQvS0VS TkVML2xpYi9weXRob24zLjUvc2l0ZS1wYWNrYWdlcy9zYWxvbWVgIDxicj48L3A+PHA+dG8gYFBZ VEhPTlBBVEhgIGVudmlyb25tZW50IHZhcmlhYmxlIGluIGB+Ly5iYXNocmNgIGZpbGUgYnV0IHRo ZXJlIGlzIG5vIGF1dG9jb21wbGV0aW9uITwvcD48cD5BbnkgaWRlYT88L3A+PHA+IVtTYWxvbWVd KGh0dHBzOi8vaS5pbWd1ci5jb20vdUhEV014Qi5wbmcpPC9wPg==">​

Re: Using autcompletion with Visual studio code

Posted by ghodbane at March 20. 2019

Hi,

you need to set the environment beforehand.

  • Linux:
    • run source ./env_launch.sh and start VS ( code)
  • Windows: 
    • start a VS dev terminal
    • in that terminal:
      • cd the installation folder 
      • type: call <SALOME installation folder>work\set_env.bat
      • type: call <SALOME installation folder>\products\env_launch.bat
      • start visual studio with devenv.exe
      • autocompletion should work

 

 

 

Attachments

Re: Using autcompletion with Visual studio code

Posted by samir1291 at March 30. 2019

Thank you that works (by choosing python version used by salome 9.2: 3.5.1 inbVScode) 

thanemireth dear Nabil

Re: Using autcompletion with Visual studio code

Posted by vectorhasting at November 22. 2020

Thank you in advance for your time. 

I am attempting to write plugins for Salome Shaper that will create threads and other topologies to make modeling for 3D printing easier. Having autocompletion is how I learn a new programming environment. 

What I have done: 

I am on Windows 10, I have downloaded and installed Salome 9.5.0 in a path with a short name and no special characters (c:\dev\apps\Salome_9_5_0\... )

I have downloaded and installed MS Visual Studio Code, version 1.51.1, and then installed both the Microsoft Python Interpreter extension and pylint. 

I have launched Salome, and run Tools>Plugins>Launch VS Code (debugger). This launches Visual Studio Code successfully. 

From within VS Code, I opened a Terminal window, and tried to type the above commands (call c:\dev\apps\Salome_9_5_0\work\set_env.bat ... (see problem below)

I also attempted to set the paths inside the VS Code application, under the Python interpreter settings @ext:ms-python.python; setting python.autoComplete.ExtraPaths . 

However, I have the following problems: 

1) the VS Terminal does not recognize the "call" command, but send the message: "the Term 'call' is not recognized .... 

2) I get pylint errors for all imports of any module as follows: "No name 'geom' in module 'salome' pylint(no-name-in-moduel) [30,5]" , etc. 

3) I cannot find any set_env.bat file in any of the Salome installation directories. (Is this because I did not cmake my installation, but instead installed from the Salome-9.5.0.exe file?) 

Please  help direct me to enable autocompletion in some sort of python development environmont. 

(I'm more competent than these questions might appear, but self taught on both Salome and python.) 

Thank you again for your time. 

Vector H. 

Re: Using autcompletion with Visual studio code

Posted by vectorhasting at November 23. 2020

Thank you for your time. 

I believe I have solved my problem. 

On Windows, with a .py script open in Visual Studio Code, choose Terminal > New

  (This opens a powershell window) 

In the powershell window, type:

    cd <SalomeRootDir>    (enter)

    start env_launch.bat    (enter)

where <SalomeRootDir> is the the directory on windows that contains the W64 directory, for example c:\Salome\Salome-9.5.0

Now autocompletion will work. 

Note that there are three changes from the expert post above: 

a) the powershell command is "start" not "call"

b) the batch file set_env no longer seems to exist, so one simply runs the env_launch.bat file

c) the env_launch.bat file only exists in the installation directory, not in each product directory (eg GEOM, SHAPER, etc.)  

 

I hope this is helpful. 

PS, to switch the Terminal window to classic command syntax, one may type cmd and press enter, to swich it back to powershell mode, type powershell and press enter.  

Re: Using autcompletion with Visual studio code

Posted by vectorhasting at November 24. 2020

This is still not fully functional. 

I have also discovered that the supplied env_launch.bat file seems to have a bug in it: namely the out_dir_Path variable includes a trailing backslash, but it is everywhere in the batch file appended with another backslash before the W64 directory name. 

I changed the code to the following:

set out_dir_PathFull=%~dp0

set out_dir_Path=%out_dir_PathFull:~0,-1%

that strips off the final character (the offending extra backslash).

Sadly, even with this modification, I still have an abundance of errors in Visual Studio Code... namely it cannot find salome.geom. 

"No name 'geom' in module 'salome'

The import salome is now resolving (inside Visual Studio Code) to .../W64/KERNEL/lib/python3.6/site-packages/salme/salome/__init__.py. 

I understand from the documentation in that file that we are expecting the paths to be appended such that whenever there is a <MODULE_ROOT_DIR>/lib/pythonX.Y/site-packages/salome/<ROOT_PYTHONPACKAGE_NAME> then those python files will be appended into a large "virtual python package."

This clearly works inside the Salome project itself, however it is not working in VS Code. (It could be that VS Code simply cannot resolve all those vitual python packages, but only stores the first one it encounters)

I'm guessing from Nabil's earlier post that each module subdirectory was one time the home for an env_launch.bat file, in which case his instruction might have made sense to point the paths to the __init__.py needed by the module one is working on. However, since there now seems to be only one env_launch.bat (and no set_env.bat), this method won't work 

I hope that's clear and my sincerity in seeking an answer comes through. 

 

Again, we are looking for a way to use VS Code to have auto-completion and error checking while working on Salome plugin scripts, but the environment setup is not allowing us to find a library that will do both "import salome" and "import geom" and "from salome.geom import  geomBuilder" 

 

Thank you for your time. 

Re: Using autcompletion with Visual studio code

Posted by ghodbane at November 24. 2020

Hi Vector,

apologize for the late reply. The prescription I wrote was aimed to provide autocompletion within Visual studio in a visual studio console for SALOME 9.3.0

In case of SALOME 9.5.0, in order to develop and debug a script, here is how I proceed:

- start SALOME

- In the main bar menu, select tools -> Plugins ->  Launch VS Code (debugger), assuming that you extended your PATH environment variable with the VSCode installation directory

- edit your script

- click on Run - Start debugging

- as Debug configuration, select Python File

- Define your breakpoints, etc..

you don't need to source environment, since this is already set within SALOME.

See enclosed screen capture, which shows a sample session.

Auto completion works as well, given that you start VSCode from SALOME.

Re: Using autcompletion with Visual studio code

Posted by ghodbane at November 24. 2020

Enclosed the completion

Attachments

Re: Using autcompletion with Visual studio code

Posted by ghodbane at November 24. 2020

Enclosed a screen capture when debugging (SALOME is of course running in the background)

Attachments

Re: Using autcompletion with Visual studio code

Posted by vectorhasting at November 25. 2020

Thank you for your attention!

And I apologize again for my not being able to make it work.

I am able to proceed as you described this far:

Start Salome  - check

In the main bar, select Tools > Plugins > Launch VS Code (debugger) – check

VS Code launches in a separate window

Edit my script – check, for this example I’m still trying to open salome_plugins.py from the …W64\share\salome\plugins\gui\demo folder.

Click on Run – Start debugging – check

As Debug Configuration, select Python file – check.

xxx

Now my screen shows as follows: it will not run with these errors. There is still something fundamentally wrong with my environment.

Attachments

Re: Using autcompletion with Visual studio code

Posted by vectorhasting at November 25. 2020

Auto-completion also does not work.

It appears to me that there is some installation/installation step that’s not the same in our environments, but I am so far at a loss to figure out what it is.

 

Thank you again for your help. 

 

Attachments

Re: Using autcompletion with Visual studio code

Posted by vectorhasting at November 25. 2020

In looking at this further, I think the following information and questions might help:

Regarding PATHs:

In Salome, in the Python Console, if I type;
      import sys print (sys.path)
      print (sys.path)
then I get a long system path which include many of the form:
   <installationdirectory>\\W64\\<module name>\\bin\\salome and
   <installationdirectory>\\W64\\<module name>\\lib\\salome
   <installationdirectory>\\W64\\<module name>\\lib\\python3.6\\site-packages listed.

However, after I launch VS Code from Salome, and go to the terminal window, and type:
      $env:path
then I also get a long list of paths, but they are not the same at all. Notably, in VS Code the <installationdirectory>\W64\<module name>\lib\python3.6\site-packages are missing.

I tried to add these missing paths to the path within VS Code using $env:path = ($env:path + $astringwiththemissingpaths), but that did not solve my problem.

I also tried adding them to the json.settings file (see below) but I could still not autocomplete. Thoughts?

Questions:

1) In Visual Studio Code, I was prompted to install a Python extension... I used ms-python.python v2020.11.371526539.
       Are you using the same? 

2) if you're also using that python extension, then from the Extensions panel, if you click the gear box, it will take you to a settings editor headed by @ext:ms-python.python.... searching this for autocomplete turns up a setting called Python > Auto Complete: Extra Paths, where you may make changes by clicking 'edit in settings.json' 
      Do you have any paths setup there? If so, could you copy them here? 

3) There is another setting called Linting: Ignore Patterns, which says it is “Patterns used to exclude files or folders from being linted” which as by default the pattern “**/site-packages/**/*.py
   Do you have this setting enabled with this pattern? (I removed it, but no luck)

4) Similar to (3), there’s a setting “Workspace Symbols: Exclusion Patterns, which also defaults to **/site-packages/**
   Do you have this setting enabled? (I also removed this, but still no luck, I set them both back again)

 

Re: Using autcompletion with Visual studio code

Posted by vectorhasting at November 25. 2020

These are the two path-sets.

Attachments

Re: Using autcompletion with Visual studio code

Posted by vectorhasting at November 26. 2020

I found it!! 

In VS Code, go to Settings by pressing Ctrl + ,

Search for python.languageserver, change from Jedi to Pylance. Download and set this as your default. 

Reload, and the autocompletion and resolution to definitions works. 

Notably, under the Pylance settings, it automatically reads the Salome installation and detects the additional directories (ending in .../site-packages/salome) and adds them to its parameter Python > Analysis: Extra Paths. 

I found this solution on this board: https://stackoverflow.com/questions/64255834/no-definition-found-for-function-vscode-python 

Thank you, thank you for your help! 

Re: Using autcompletion with Visual studio code

Posted by vectorhasting at November 27. 2020

Just to beat this to death, I need to correct a statement in the previous post: Pylance does not automatically read the Salome installation for the paths and apply them to Python > Analysis: Extra Paths... in my case this was left over from my earlier tinkering. 

In fact, it seems to me that Pylance resolves the Salome python path structure with no need for "Extra Paths" at all (unless you want it to resolve tubebuilder and tubedialog, in which case you need to add the path to the gui demo folder eg: <installation-dir>\W64\GUI\share\salome\plugins\gui\demo )

Thanks again!

Re: Using autcompletion with Visual studio code

Posted by vectorhasting at September 29. 2021

I'm now having trouble again. Autocomplete for python scripting is no longer working

 

I have upgraded to Salome 9.7.0, perhaps this is a problem?

 

Is there a better way to see all the methods for a module?


This forum is DEPRECATED, please create new topics in the new SALOME forum.
For existing topics please transfer them to the new forum.

Powered by Ploneboard
Document Actions