I'm not sure I'm implementing my Intellisense correctly. My scripting language is lua, and say I have 3 global tables - 'math', 'string' and 'table'. If the user starts typing in empty space, I want to display an Intellisense popup with those 3 options. Once they type a complete global name with a '.', I want to switch to Intellisense specific to that table.
My current solution is to create 4 CompletionSessions, one for the global completion and one for each table. In the DocumentTextChanged event, if the TypedText is '.', I read back and see if it matches one of my specific tables, and if so Open the corresponding session. If a . wasn't typed and IsTypedWordStart is true, I display the global session.
It appears to work, but one thing I'm not happy about is that I need to check to see if any of the other sessions are open before opening the gobal. Is there a better way to solve this problem?
Here's the code for the DocumentTextChangedEvent
My current solution is to create 4 CompletionSessions, one for the global completion and one for each table. In the DocumentTextChanged event, if the TypedText is '.', I read back and see if it matches one of my specific tables, and if so Open the corresponding session. If a . wasn't typed and IsTypedWordStart is true, I display the global session.
It appears to work, but one thing I'm not happy about is that I need to check to see if any of the other sessions are open before opening the gobal. Is there a better way to solve this problem?
Here's the code for the DocumentTextChangedEvent
switch (e.TypedText)
{
case ".":
{
ITextSnapshotReader reader = _Editor.ActiveView.GetReader();
reader.ReadCharacterReverseThrough('.');
IToken token = reader.ReadTokenReverse();
if (token != null)
{
switch (reader.TokenText)
{
case "math":
_MathSession.Open(_Editor.ActiveView);
break;
case "string":
_StringSession.Open(_Editor.ActiveView);
break;
case "table":
_TableSession.Open(_Editor.ActiveView);
break;
}
}
return;
}
}
if (e.IsTypedWordStart)
{
if (!_MathSession.IsOpen&& !_StringSession.IsOpen && !_TableSession.IsOpen)
{
_GlobalSession.Open(_Editor.ActiveView);
return;
}
}