[IronPython] autocompletion (intellisense) for clr.AddReference

Dino Viehland dinov at microsoft.com
Fri Jan 7 22:30:48 CET 2011


Piotr  wrote:
> > I have a feeling that getting autocompletion/intellisense for CLR
> > libraries referenced that way is not a trivial task, though it's
> > probably not impossible. What we ended up doing is writing a Python
> > 'pretend' module for our CLR assembly and importing that, but doing
> trickery so that the names actually resolve to the CLR assembly at runtime, so
> the Python module is only used to assist in the autocompletion. If you want I
> can get the specific details on how you can 'trick' the IDE into looking at the
> Python script but actually reference the assembly.
> 
> Yes I would like to learn the "trick"

Just to give you some ideas on how you can do this w/ just your assembly.

The way we load the assembly is by calling into IronPython's clr module to
Load the assembly the same way it normally does (we call clr.LoadAssemblyByName).

If that fails we then try clr.LoadAssemblyByPartialName.  Those should turn into
clr calls to do Assembly.Load(name) and Assembly.LoadWithPartialName(name).

So the question then becomes what do you need to do to make sure we can find
your assembly.  One option would be to put the assembly in the GAC but that'll
require that it's strong named.  Another option would be to put your assembly
in the CLR's loader path.   That probably means putting the assembly where devenv.exe
lives or some similar location.  You could find a definite location by running fuslogvw (which
is part of the .NET framework SDK), click on settings, enable logging bind failures,
and then loading up VS and opening up your file.  We should try loading the assembly
and you should see the assembly name in the list of bind failures when you refresh
in fuslogvw.  You should also see a list of paths where we looked.

Probably what should really happen is that we should support looking in some location
within the project.  If someone wanted to make this change it would be in
ProjectState.cs in the AddReference(CallExpression node, Func<string, Assembly> partialLoader) 
method.  You'd just need to flow where to look into the ProjectState object.

> 
> 
> BTW: do you know the explanation for the behavior below?
> 
> > import System.Text as text
> > text.<TAB>   produces autocompletion list
> >
> > whereas
> >
> > import System.Text
> > System.Text.<TAB> does not

Does "Text." give you completions?  We could just be misanalysing the
import statement.



More information about the Ironpython-users mailing list