Creating an Intelliprompt list of available types

SyntaxEditor for Windows Forms Forum

Posted 19 years ago by Blaise

I am brand new to SyntaxEditor (and code parsing in general, for that matter)

My objective is to use SyntaxEditor to provide a VB.NET code editor using ItelliPrompt to behave similar to the way VS7 offers IntelliSense. Ultimately, I want to implement as much statement completion functionality as I can.

But I'm starting small ... :)

So I grabbed the Trigger event handler from the Sample project and started with that (although that seems particularly suited to C#). With a few adjustments, this bought me an IntelliPrompt list when the period key was pressed. Cool!

Now, for VB, I want an IntelliPrompt list of types when the user types "As" or "As New" and then a space character. So I figured I had to add a trigger for the space key to the language definition. I did so like this in the ActiproSoftware.VBDotNet.xml file:

    <!-- Triggers -->
        <KeyPressTrigger Key="MemberListTrigger" Character=".">
                <KeyPressTriggerValidState State="DefaultState" />
        <KeyPressTrigger Key="TypeListTrigger" Character=" ">
                <KeyPressTriggerValidState State="DefaultState" />
and this seems to work (the Trigger event is raised when the space key is pressed, with a Key of "TypeListTrigger"). But would it be better to define an EditCommand for this?

So, how do I create a list of types ... here's what I'm trying:

First, look backwards to see if we have "As" or "As New"

Case "TypeListTrigger"

    'Construct full name of oItem to see if reflection can be used... 
    'iterate backwards through the oToken oStream
    Dim oStream As TokenStream = txtCode.Document.GetTokenStream(txtCode.Document.Tokens.IndexOf( _
       txtCode.SelectedView.Selection.EndOffset - 1))

    Dim sFullName As String = ""
    Dim iPeriods As Integer = 0
    Dim bGotNew, bGotAs As Boolean
    Dim oToken As Token
    Do While oStream.Position > 0
        oToken = oStream.ReadReverse()
        If oToken.Key = "ReservedWordToken" Then
            sFullName = txtCode.Document.GetTokenText(oToken)
            If sFullName = "As" Then
                bGotAs = True
                Exit Do
            ElseIf sFullName = "New" Then
                bGotNew = True
            End If

        End If  'Reserved Word
OK ... but now what? How do I get a list of appropriate types? I mean I can iterate of the types of loaded assemblies, but which attributtes of a type should be used to whittle down the large list of all available types?

My attempt follows:

If bGotAs Then
    Dim oMemberList As IntelliPromptMemberList = txtCode.IntelliPrompt.MemberList

    ' Set IntelliPrompt ImageList
    oMemberList.ImageList = txtCode.ReflectionImageList

    ' Add items to the list

    ' find Types
    Dim assemblies() As [Assembly] = AppDomain.CurrentDomain.GetAssemblies()
    Dim assemblyData As [Assembly], sName As String
    Dim oType As Type
    For Each assemblyData In assemblies
        sName = assemblydata.FullName()
        For Each oType In assemblyData.GetTypes
           If Not oType.IsAbstract AndAlso _
             (oType.IsClass OrElse oType.IsEnum OrElse oType.IsValueType OrElse oType.IsInterface) Then
                oMemberList.Add(New IntelliPromptMemberListItem(oType.Name, 0, oType.ToString))
           End If
        Next    'type
    Next    'assembly
But this yields a very limited list:

    Object            (that's a good one!)
    Script            (Another hit!)
Any help would be appreciated.

Comments (3)

Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
I think the trigger would be best for you like you're doing.

Did you check out our help methods to build the list for you? Its the AddReflectionForAssemblyNamespacesAndTypes. Search for it in our MainForm code. It builds the list of namespaces and types and has a lot of options for picking exactly what you want.

Also, in the docs, look at the "General Features / IntelliPrompt Member List" topic. That has help on using that method.

Actipro Software Support

Posted 19 years ago by Ashton - Developer, Schema Solutions LLC
VB does most of its Intellisense by using the background compiler to basically compile code as you type. If you truly want to provide Intellisense you will probably need to do something similar.

Look at the following article on the background compiler:

Using reflection (or the methods in SE) you can get a list of types from some assemblies. The hard thing is trying to parse the text so that's why Microsoft has the BC to generate the code into items that can be reflected upon to provide proper intellisense for.

You could implement a poor man's BC by using threading and the System.CodeDom.Compiler namespace to try and compile the code the user is typing in the background and then reflect against it.

Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
As an add-on to Ashton's comment, we're currently working on developing some sort of mechanism to create abstract syntax trees for the document text that would be language specific. So the end goal would be you end up with a root CompilationUnit node and then crawl down through namespace declarations, type declarations, etc. We also would like to support maintenance of a symbol table. If anyone has experience in these areas, send us an e-mail. We welcome all feedback/help on the subject.

Actipro Software Support

The latest build of this product (v24.1.0) was released 4 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.