PythonTools and VS Isolated Shell

Jan 24, 2012 at 5:43 PM

Hi,

I am wondering if it's possible to add the python tools extension to a VS Isolated shell?

Thank you,

Anna. 

Coordinator
Jan 24, 2012 at 5:48 PM

There's no support for installing it into an isolated shell by default, and it might depend upon how the isolated shell app was packaged up, OTOH it is certainly possible w/ the integrated shell.  It may be possible that you just need to copy the extension into the isolated shell's hive.  Usually if you do a per-user install we'll install PTVS into:

%LOCALAPPDATA%\Microsoft\VisualStudio\10.0\Extensions\Microsoft

The "10.0" part there represents the hive.  You might be able to navigate to %LOCALAPPDATA%\Microsoft\VisualStudio and see another directory which is being used for the isolated shell app.  If you then copy all of the PTVS stuff from %LOCALAPPDATA%\Microsoft\VisualStudio\10.0\Extensions\Microsoft to the corresponding directory below the other hive it might load.

If that doesn't work then it means you'd need to manually updated the .pkgdef file for the isolated shell app which might start to get crazy.

Jan 24, 2012 at 6:10 PM

Dinov, thank you so much for your prompt reply!

Copying the extension files into the isolated shells hive works!

Anna. 

Jan 31, 2012 at 8:09 PM

Hi Dinov,

I have another question regarding the same topic..

I was able to add the python tools extension to isolated shell by copying the extenssion files that were added in "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft" while installing the python tools for VS extension, to the base directory of my isolated shell project.  This includes 3 folders: Microsoft.VisualStudio.ReplWindow, Python Tools for Visual Studio, PythonProfiling.

The problem is that not everything works - the two examples of features that doesn't works are: I am not able to add references via right click on references in the project, and also I don't have the refactoring options.

Can you please help me with figuring out which files are needed for those features to work properly - did I miss copying some files? or maybe I should change some configuration files?

Thank you!

Anna.

 

Coordinator
Jan 31, 2012 at 8:51 PM

What happens when you attempt to add the reference?  Is the menu option simply missing?

What I suspect is going on is that the isolated shell app that you're using isn't defining the menu groups and commands that we respond to.  I think the only way to fix that would be to include those command definitions in the .vsct file of the isolated shell when it's being built.

Alternately you could re-build PTVS and add new menu groups to it's .vsct file so that it will register the menus/buttons rather than relying upon the pre-existing ones.

Jan 31, 2012 at 9:18 PM
Edited Jan 31, 2012 at 9:38 PM

Aha...

Yes - nothing happens when I am clicking on references with the right button in order to get the menu where i can choose "Add Reference" - this menu doesn't appear.

And regarding the refactoring - this menu item is missing.

Can you tell me which commands are the ones that responsible for these options? I tries to play with that file but couldn't find the right ones for references - and I didn't find any commands for "Refactoring"

Thank you for your help!

Anna. 

Coordinator
Jan 31, 2012 at 10:24 PM

I don't see these defined in the master used command file so there's no way to turn them on/off using the defines, I think you need to add:

<UsedCommands>
   <UsedCommand guid="guidVSStd2K" id="ECMD_RENAME"/>
   <UsedCommand guid="guidVSStd2K" id="ECMD_EXTRACTMETHOD"/>
   <UsedCommand guid="guidVSStd2K" id="ECMD_ADDREFERENCE"/>
</UsedCommands>

 I'm not 100% certain if that'll work but give it a shot and let me know if it doesn't.

Jan 31, 2012 at 10:47 PM

Yay - it worked!!!

Now I can reach the references menu!

( Still don't have the refactoring option.. )

 

Coordinator
Jan 31, 2012 at 11:00 PM

Is refactoring not showing up even w/ a Python file is the currently active text view?

Feb 1, 2012 at 1:22 PM
Edited Feb 1, 2012 at 1:23 PM

Yes - the "Refactor" menu item is missing when I'm using the Isolated shell ( It does appear in the VS when I'm working on the same python file )

My menu items start with "Remove Imports" -> "Go to definition" -> "Find All References"...

 

Feb 1, 2012 at 3:29 PM

Dinov,

I have one more question (this time related to the general Python Tools project - not specific to Isolated Shell ).
I am not able to make the intellisence to work on my assemblies.
I found few other discussions on this topic but nothing that was suggested there worked for me.
For example I have the CE.Python.dll file, and I write the following code in a python file:

import clr
import sys
sys.path.append('path to the root')
clr.AddReferenceToFileAndPath('path from root to CE.Python')

import CE.Python
from CE.Python import *

pythonCommandProvider = PythonCommandProvider("path")
x = pythonCommandProvider.SetStandardOutput()


The path to the dll was added to the Search Paths.
When I'm debugging this file - I get no errors on the imports which means that the assembly was loaded successfully.
I am getting error on the last line "x = pythonCommandProvider.SetStandardOutput()" saying "SetStandardOutput() takes exactly 1 argument (0 given)" - which is a correct error and a good sign that the method is recognized.

But, the intellisence doesn't work.
Both - in the imports section: "from CE.Python import" brings me to only one autocompletion: "*"
And in the code - for example on the last line "x = pythonCommandProvider." doesn't bring me to the available methods list.

Do you have any suggestions regarding this?

Thank you,
Anna.

Feb 1, 2012 at 3:31 PM

oh - I'm working with IronPython and the dll is .Net dll...

Coordinator
Feb 1, 2012 at 4:45 PM

Sounds like you're looking on the context menu - is there a top-level Refactor menu?  It looks like the context menu is defined in the C# package rather than for VS as a whole.  I'd try adding something like this to your VSCT:

 

<Groups>
<Group guid="guidSHLMainMenu" id="IDG_REFACTORING_COMMON" priority="0x0000">
   <Parent guid="guidYOURISOLATEDSHELLGUIDHERE" id="IDM_VS_CTX_REFACTORING"/>
</Group>
</Groups>

<Menus>
 <Menu guid="guidYOURISOLATEDSHELLGUIDHERE" id="IDM_VS_CTX_REFACTORING" priority="0x0300" type="Context">
    <Parent guid="guidSHLMainMenu" id="IDG_VS_CODEWIN_LANGUAGE"/>
       <Strings>
       <ButtonText>Refactor</ButtonText>
       <CommandName>&amp;Refactor</CommandName>
       </Strings>
 </Menu>
</Menus>

You'll need to the IDM_VS_CTX_REFACTORING in your GuidSymbol list and replace guidYOURISOLATEDSHELLGUIDHERE with the appropriate name.  This will create a new group on the context menu and place the refactoring common group on it. 

Coordinator
Feb 1, 2012 at 4:49 PM

Is the path in the call to clr.AddReferenceToFileAndPath('path from root to CE.Python') a relative path?  If so we probably won't resolve that.  Does a normal clr.AddReference call work?  If so then I think we'll pick it up if you just do a normal clr.AddReference.  If not you might be able to make the IDE happy by adding a reference to the DLL via the References node in the project and then doing:

 

if False:

    clr.AddReference('AssemblyName')

 

If that works then we probably just need to be more aggressive about searching referenced assemblies for clr.AddReference* forms other than the main one.  So if it works feel free to open a bug, it should be pretty easy to fix (but unlikely to be fixed for 1.1 final as it's a pretty minor issue w/ an easy workaround).

Feb 2, 2012 at 2:53 PM
Edited Feb 2, 2012 at 3:01 PM

Dinov thank you for your help!

Refactoring - Fixed!

(Have the context Refactoring menu which works just fine. No top level Refactoring menu..)

References - Works almost well:
In VS no issues.
In the shell - when I open the "Add Reference" window, go to "Browse", navigate to the folder which contains the .dll files, the files doesn't appear in the files list even though the chosen type is the default: "*.dll;*.pyd". when I begin writing the file name in the "File name" text box I get a drop down list with this file and I am able to choose it. If I type "*" in the "File name" text box and hit Enter - all the files appears in the files list.

Intellisence - Nothing worked so far.. trying to play with that more.. (both in VS and in the Shell)

 

 

 

Coordinator
Feb 7, 2012 at 4:34 PM

Regarding intellisense - do you get syntax color highlighting?  Do you get any completions after typing "import " at the top of a file?

Feb 7, 2012 at 4:44 PM

Hi Dinov,

I reinstalled everything and now it works fine - I guess something went wrong with the installation.

I have a small question for you:

When I type for example a variable name, I get the list with available completions only after I click ctrl+space - Is there a way to make it show up automatically?

Thanks,

Anna.

Coordinator
Feb 7, 2012 at 6:05 PM

Great!  For the completions you should be able to go to Tools->Options->Python Tools->Text Editor->Python->General and uncheck the "Auto list members" option.  I think from then on out you'll need to hit Ctrl-Space to get the completions.

Feb 7, 2012 at 6:14 PM
Edited Feb 7, 2012 at 6:15 PM

Actually my question was how to make it show the autocompletions automatically without hitting ctrl+space :)

In Tools->Options->Text Editor->Python->General, "Auto list members" option is checked but it shows the autocompletions only after hitting ctrl+space..

Coordinator
Feb 7, 2012 at 6:24 PM

So you don't get completions after typing "." but they show up after typing dot and then hitting ctrl-space?

Do you get completions if you hit @?  Also do you get signature help when calling a method, and if so, does it track the parameters as you hit commas?

Feb 7, 2012 at 6:53 PM
Edited Feb 7, 2012 at 6:54 PM

OK - sorry for the confusion..

I do get the autocompletions after I hit "." , I do get completions for "import" , I do get signature help when calling a method, and when I hit commas in the parameter list it shows the method signature again (is that what you mean by tracking the parameters? they are not being highlighted or something like that)

The thing that I was talking about is for variable names etc.. for example if I have the following lines of code:

pythonCommandProvider = PythonCommandProvider("path"

) 

pythonCommandProvider2= PythonCommandProvider("path") 

x = pythonCommandProvider.SetStandardOutput

();

When I start typing "pythonCommandProvider" I don't get the autocompletion for that. Only after I hit ctrl+space I get the list with the items: {"pythonCommandProvider","pythonCommandProvider2"}

 

 

 

Coordinator
Feb 7, 2012 at 7:03 PM

I see - this is a missing feature.  C# has an option in Tools->Options-Text Editor->C#->Intellisense called "Show completion list after a character is typed" and we don't have a similar feature yet.  Feel free to open a feature request - this is the 2nd time this has come up but I don't think we have an issue to track it.


Feb 7, 2012 at 7:09 PM

Oh.. OK, not a big deal.. I'll be waiting for this feature whenever it comes out!

Now that everything works for me, I can tell you that you did a terrific work with this project!! THANK YOU SO MUCH!!

Anna.

 

Mar 15, 2012 at 3:23 PM
Hi Dino,
I posted few questions several weeks ago and now I got back to work on that I have another question.
I've created a VS Isolated Shell with PTVS extension that supposed to serve as a Python Editor app. without the need for any installation.
I know that PTVS does not support installation for isolated shell, but I'm still trying to make it work :)
I will appreciate it very much if you could help me here.
In the regular-PTVS installation I noticed that if the PTVS is installed before the IronPython, the Intellisense doesn't work. Everything else does work, except the intellisense. 
I have the same problem in my Isolated shell - everything works without the need in any installation, except the intellisence.
Since I'm trying to avoid the need in any installation, I am trying to figure out how to bypass the need in that particular order of installation.
I don't know about PTVS implementation details so it's hard for me to find how to fix it ( played all day yesterday with Python Tools -> interpreters information in the registry/ played with the data stored in AppData\Local\Python Tools\CompletionDB etc.., but nothing solved this issue so far )
I guess it has something to do with registry information of the default interpreter for Python Tools, and I hope that it can be solved manually/programmatically.
Can you please give me some information about why it's important to install IronPython before the PTVS so I can figure out a way to bypass this issue?
Thank you very much,
Anna.

 

Coordinator
Mar 15, 2012 at 5:05 PM

Are you actually running the installer in this case?  By default the installer will actually not install the Ipy support feature if IronPython isn't installed.  That's because the Wix for the installer includes:

      <Feature Id="Feature_IronPython" AllowAdvertise="no" Level="1" Title="IronPython support" Description="IronPython support">
        <Condition Level="2">NOT IPY_INSTALLED</Condition>
        <MergeRef Id="IronPythonInterpreter"/>
      </Feature>

Removing the Condition line would make it always install by default regardless if IronPython is installed or not.

Mar 15, 2012 at 6:16 PM

I am running the installer locally in order to get the needed extension files - I copy these files (4 folders that were created in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft ) into my isolated shell extensions library and this shell can be run on any computer wher the PTVS and IronPython weren't installed (I add manually path to interpreter which lies along with the shell).

Hm... In that case I would assume that my extension files would include this feature (they were created when IronPython was installed before the PTVS), but it still doesn't work. One of the extension folders that I copy is "IronPython Interpreter" which I guess is the needed extension.

maybe there is something else that have to be done in order for the intellisence to work?

 

Coordinator
Mar 15, 2012 at 7:37 PM

Does IronPython show up in Tools->Extension Manager? 

There is a reg key (under Software\Microsoft\VisualStudio\10.0\ExtensionManager\EnabledExtensions with the name 0AC9CC8C-C057-4CFA-884B-0D4318BB2EFC,1.1 and value [EXTENSION_INSTALLPATH]Extensions\Microsoft\IronPython Interpreter\1.1\) which needs to be set depending on if it's a per-user or all-users install (forget which one).  I'm hoping the extension is being picked up but not not enabled, so if it shows up in extension manager you should be able to enable it there (or write this reg key so you don't need to do so via the UI).

Mar 15, 2012 at 8:16 PM

Unfortunatelly my isolated shell doesn't include the Extensions Manager (at least not the menu item so I cannot open the manager).

I assume that the IronPython Interpreter extension is enabled since I do get the different IronPython project templates for a new project (Does it mean that the extension is included? ).

I tried adding this key and value to EnabledExtensions of my shell (Software\Microsoft\<Shells name>\<Shells version>\ExtensionManager\EnabledExtensions) but it didn't fix it.

Mar 16, 2012 at 1:52 PM

Just in case that this info will point to what is wrong:

I do have the extension. Something wrong with the intellisense - it shows "<no type information available>" when I'm hovering over any method/type. It doesn't show me the existing methods in class after I write "<objectname>." and after writing "from <something> import " the only option that is shown is "*".

Looks like the intellisense "works" but doesn't recognize any types. When I'm debugging, all the types are known and I get errors as expected when there is a missing parameter for example in a method call.

 

Coordinator
Mar 16, 2012 at 4:40 PM

Do you see the IronPython interactive window in View->Other Windows or in Tools->Python Tools?  Or does it show up in Tools->Options->Interpreter Options as an auto-discovered (where the path/arch/version are all grayed out) interpreter?  I'm thinking if we're not picking up Ipy from the registry then that could be impacting intellisense.

Mar 16, 2012 at 4:57 PM

Yes the IronPython interactive window appears in View->Other Windows and in Tools->Python Tools  and it works.

Hm....  Under Tools->Options->Python Tools->Interpreter Options I don't have a default interpreter with grayed out fields. I have only the interpreter that I added manually. Do you think that the fact that I don't have an auto-discovered interpreter is the reason for this behavior? Do you know if it's something that I might be able to fix?

Coordinator
Mar 16, 2012 at 5:04 PM

Yep, that's likely the issue - at least that would prevent getting .NET intellisense, you should still be able to get intellisense within your files for your own classes though.

To discover Ipy we look in the registry at HKLM\Software\IronPython\2.7\InstallPath (or HKLM\Software\Wow6432Node\IronPython\2.7\InstallPath on a 64-bit machine).  Does that reg key exist for you?

Mar 16, 2012 at 5:20 PM

No - under HKLM\Software\Wow6432Node\ I don't have IronPython key. (I have 64-bit machine) 

I tried adding it but still didn't get the intellisense (I added InstallPath as a new String Value with the value of the path to IronPython dir, under the key HKLM\Software\Wow6432Node\IronPython\2.7 )

Dino, thank you for your help!

Coordinator
Mar 16, 2012 at 5:38 PM

Hurm, that should have let us pick up Ipy.  Given that there's no extension manager UI, let's try this to see if the Ipy extension is getting loaded...  Can you start VS w/ the /log option and then look in %APPDATA%\Microsoft\VisualStudio\<hivename> for ActivityLog.xml?  Do you end up seeing an entry like:

  <entry>
    <record>176</record>
    <time>2012/03/16 17:36:25.066</time>
    <type>Information</type>
    <source>Extension Manager</source>
    <description>Extension is enabled...</description>
    <path>C:\Users\dinov\AppData\Local\Microsoft\VisualStudio\10.0\Extensions\Microsoft\IronPython Interpreter\1.1\</path>
  </entry>

or

  <entry>
    <record>233</record>
    <time>2012/03/16 17:36:25.176</time>
    <type>Information</type>
    <source>Microsoft.VisualStudio.CommonIDE.ExtensibilityHosting.VsShellComponentModelHost</source>
    <description>Successfully loaded component assembly from cache</description>
    <path>C:\Users\dinov\AppData\Local\Microsoft\VisualStudio\10.0\Extensions\Microsoft\IronPython Interpreter\1.1\Microsoft.PythonTools.IronPython.dll</path>
  </entry>

Or anything else related to IronPython?

Mar 16, 2012 at 5:44 PM

Dino, actually this is it - that's the issue - I installed IronPython and I saw this key in the reg (and the correct way in which it should appear) , after the installation the intellisense did work!!

I tried removing the installation and adding this key manually with a path to the IronPython dir, and opening the project again - now I got error - couldn't load the proj. and even couldn't create a new IronPython proj., I guess the reason is some missing reg keys that are added by the IronPython installation or something like that (since I didn't install, but just using copied installation directory). Removing the new added key fixed this and I returned to the previous state of things - project loads fine but no intellisense.

I will have to figure out now if the IronPython missing keys (or whatever it is) is something that I can fix, or in the worst case - IronPython will have to be installed (hopefully not).

Thank you so much Dino!

If you know from the top of your head which keys should be added in order to load the IronPython project correctly - I'll be happy if you could help here, otherwise - don't worry about it - you helped me a lot - now I know what is the issue :)

 

Coordinator
Mar 16, 2012 at 5:53 PM

Ah-ha, it's probably the fact that IronPython is installed in the GAC when it's installed, but when it's not installed it's not.  The IronPython intellisense actually calls directly into the IronPython DLLs so it needs to be loadable by PTVS.  Having it in the GAC accomplishes that, you could also probably copy all of the DLLs to the IronPython interpreter directory where the VS extension gets installed.

Mar 16, 2012 at 6:05 PM

YAAAY!!!! :-)

Copying all the IronPython dlls to IronPython Interpreter extension folder did fix that!

Thank you so so much Dino!!!