Posted 20 years ago
by Blaise

Hi,
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: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"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:But this yields a very limited list:
Any help would be appreciated.
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 -->
<Triggers>
<KeyPressTrigger Key="MemberListTrigger" Character=".">
<KeyPressTriggerValidStates>
<KeyPressTriggerValidState State="DefaultState" />
</KeyPressTriggerValidStates>
</KeyPressTrigger>
<KeyPressTrigger Key="TypeListTrigger" Character=" ">
<KeyPressTriggerValidStates>
<KeyPressTriggerValidState State="DefaultState" />
</KeyPressTriggerValidStates>
</KeyPressTrigger>
</Triggers>
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
Loop
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
oMemberList.Clear()
' 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
_1
_1
_Version
AssemblyInfo
Object (that's a good one!)
Script (Another hit!)
ThisAssembly
ThisAssembly
ThisAssembly
ThisAssembly
ThisAssembly
ThisAssembly
ThisAssembly