Intellisense and wpf.LoadComponent()

Aug 10 at 1:17 AM
Edited Aug 10 at 1:23 AM
Intellisense is working fine for me on my setup (VS2013, latest PTVS beta, IP2.7) but for one thing:
Whenever I try to get intellisense on a Named component (eg a Canvas named as cnvs) within a .xaml file that is loaded in the main window class init method via wpf.LoadComponent() and I type out:

width = self.cnvs.ActualWidth #for example

in the same method AFTER loading the xaml then no intellisense is shown for the variable or it's methods. This is mildly irksome as I want to get at the methods of the component without having to look them up on MSDN!!
Is this normal behaviour? I'm pretty sure that when I first got IP and PTVS up'n'running a few months ago that it worked.

Thanks for your response and help in advance btw.
Coordinator
Aug 10 at 7:18 PM
Yes, this is supposed to work. I cannot repro, though - completions are there for me in beta 2 in a similar scenario. Note that it may take a little bit of time (a second or two) for Intellisense to parse that XAML and show the members.

Is there anything special about your XAML?
Aug 10 at 8:59 PM
Edited Aug 10 at 9:06 PM
No, there's nothing special. For eg I just create a new project and add a Canvas and name it like so:
<Window 
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
       Title="WpfApplication1" Height="300" Width="300"> 
       <Grid>
            <Canvas Name="cnvs"></Canvas>
       </Grid>
</Window> 

The application module is:

import wpf
from System.Windows import Application, Window

class MyWindow(Window):
    def __init__(self):
        wpf.LoadComponent(self, 'WpfApplication1.xaml')
        c = self.cnvs.Children

Application().Run(MyWindow())
When I type out c = self. intellisense comes up with a list of possibles presumably from superclass Window, but 'cnvs' is not in the list. It does hesitate a bit though when I type the dot after self. Hmph - I thought I would give it another try and this time it works properly; but more often than not it doesn't work. I have had installed 'pyIntelliSense(2013).vsix' (I hope you've heard of it). I think it's something to do with this, because when I closed the solution and reopened it and started to type c = self. intellisense automatically came up with a list but not with self in it. So when I entered c = se and pressed Control-Space intellisense did come up with the correct list. Now, I can close the solution or close VS and when I reload the solution intellisense is showing up self correctly (so pyIntellisense is working consistently too)
So there we go :( I can't repro the anomaly so I'll have to wait and see if there's any rules that apply.
Coordinator
Aug 11 at 5:29 AM
I have had installed 'pyIntelliSense(2013).vsix' (I hope you've heard of it).
I can't say that I am familiar with it, and I can't find any search hits for that name. Can you tell more about what this is?

PTVS has its own IntelliSense engine, so if this is something distinct that also tries to provide completions for Python, the results may well be inconsistent.
Aug 11 at 2:06 PM
I can't find the posts concerning pyIntellisense so I can't put you in a direction. It's a 10k file. Whether it builds it's own intellisense DB I don't know. All it does is to avoid having to press Control-Space or Control-J when first typing thus emulating VS C# intellisense behaviour - it does nothing else afak. Perhaps in the future if I can pin down the conditions when it doesn't work properly for the Xaml code, I'll uninstall it and see what happens.
Thanks for your reply.
Coordinator
Aug 11 at 4:35 PM
Thanks! If this still repros even without pyIntellisense, please go ahead and open a bug in the tracker.
Aug 12 at 3:17 PM
I've decided to uninstall pyIntellisense but unfortunately there's no uninstall facility with it and I can't find the original website that I downloaded it from. I've uninstalled/reinstalled PTVS 2.2b2 but it hasn't removed pyIntellisense functionality. Any ideas about how would I go about manually removing it bearing in mind that it's a .vsix file?
Coordinator
Aug 12 at 4:10 PM
I'd be surprised if it's the cause - it is far more likely that our IntelliSense engine is simply failing for some reason here.

But to uninstall a vsix extension you'll go through Tools-Extensions and Updates inside VS.
Coordinator
Aug 12 at 4:34 PM
Actually, do you have virtual space enabled? Because our analysis is asynchronous and sometimes time consuming (especially the first time it has to load a .NET assembly for IronPython), it's possible that the list of completions you are seeing is the global list and not the values in the function scope. I can reproduce this with virtual space and pressing Ctrl+J where you start typing c = self. (without virtual space I can't put the cursor in exactly the right spot, but I guess on a slower machine it may be possible to type the tab as well), but it's possible that pyIntellisense is simply revealing that we haven't updated our knowledge of where the end of the function is.

Can I suggest adding a pass statement at the end of the function and then typing code above that? We currently define the end of the function as the last statement, not the first line following that isn't indented (otherwise we'd get comments and folding wrong), so typing within a function almost always works more reliably than right at the end.

(FWIW, our analyzer for XAML is fine, in case anyone reading this is getting the wrong impression - as I did.)
Aug 12 at 5:45 PM
Edited Aug 12 at 6:01 PM
No, virtual space was not enabled. I uninstalled pyIntellisense completely just to get it out of the way; and then did some explorations with just a bare Python WPF project that I newly created. I gave the window a Name = wndw and researched from there. I think I have found the conditions under which intellisense doesn't work for the Xaml code. It seems that the Xaml has to have first been displayed by the Designer in the current session in order for it to work properly:

(1) With the Xaml Tab present or not in the editor, close and reload the solution (ensuring that the editor doesn't default to displaying the Xaml Tab when reloading) - intellisense doesn't work properly.
(2) Open the Xaml file in a Tab and make sure the Designer displays it - intellisense works OK, even after the Tab is closed.
Coordinator
Aug 12 at 6:12 PM
Does self have any completions at all when you see this issue? Or does it have most of them but not the name from the XAML file?

I was able to encounter an issue where self had no completions, but after a few seconds of waiting it was fine. I believe this was due to slowness loading the .NET assemblies containing type information.

I haven't been able to observe any other problems with those steps. We are analyzing the XAML regardless of whether the designer has been opened or not, though it does take longer than for plain Python code.
Aug 12 at 7:41 PM
Yes, self does show many completions but just not the the name in the Xaml. The same here for the delay sometimes.
What you find is really odd - I can replicate the lack of completions every time on my system (VS2013, JetBrain's Resharper 8 disabled, Windows 7) under the conditions I've already stated.
Coordinator
Aug 12 at 7:45 PM
I assume your XAML file is alongside the .py file and the name in the LoadComponent call is correct? (We use the LoadComponent call and the directory of the .py file to find the XAML file; the name of the .py file is irrelevant).
Aug 12 at 9:30 PM
Yes for both. The prog and everything else runs fine - it's just the intellisense that's intermittent.
Aug 26 at 10:51 PM
It's working fine now without intermittency. I've closed/reopened VS2013 several times since. Perhaps there was a peculiar glitch and it's put itself right?