public virtual LookupList GetLookupList(ScintillaEditForm document) { UpdateLists(); if ((settingsManager.ColorizeTypes || settingsManager.ColorizeVariables) && settingsManager.ColorizeOnLookup) { ColourizeVariablesAndTypes(document); } /* * Prepare the search content and target for * the code assist lookup. */ Line line = document.Editor.Lines.Current; string text = line.Text.Substring(0, line.SelectionStartPosition - line.StartPosition); int lineStartPos = GetLineStartPosition(text); text = text.TrimStart(); /* * Check for embedded option or empty comment. */ if (text.StartsWith("//")) { if (text.Length > 2 && "$?&".IndexOf(text[2]) != -1) { return(EmbeddedOptionHelper.GetEmbbededOptionFileList(text)); } else { return(null); } } /* * Get the full source and the source up to the * caret position. */ string fullSource = document.GetContent() as string; int currentPos = document.Editor.CurrentPos; string preSource = fullSource.Substring(0, currentPos); /* * Restrict the fullSource to the current class definition. */ fullSource = GetFullSource(fullSource, ref currentPos); if (fullSource == String.Empty) { return(null); } if (currentPos > fullSource.Length) { return(null); } /* * Detect if we are before the first class declaration. * If not we can stop the lookup as soon as we've done * the 'using' search as this is the only lookup type * valid before a class definition. This means 'using' * declarations have to appear before the class defs * but I think that's good practice anyway. */ Regex re = new Regex(@"(?s)class\s+.+\{"); bool beforeClass = re.Match(preSource).Success; LookupContext context = new LookupContext( fullSource, preSource, text, lineStartPos, currentPos, beforeClass); return(GetCSharpLookupList(context)); }
private LookupList GetJScriptLookupList( QuickSharp.Editor.ScintillaEditForm document) { UpdateLists(); if ((settingsManager.ColorizeTypes || settingsManager.ColorizeVariables) && settingsManager.ColorizeOnLookup) { ColourizeVariablesAndTypes(document); } /* * Get the search target from the current line. */ Line line = document.Editor.Lines.Current; string text = line.Text.Substring(0, line.SelectionStartPosition - line.StartPosition).TrimStart(); /* * Check for embedded option or empty comment. */ if (text.StartsWith("//")) { if (text.Length > 2 && "$?&".IndexOf(text[2]) != -1) { return(EmbeddedOptionHelper.GetEmbbededOptionFileList(text)); } else { return(null); } } /* * Cleanup the source. */ text = JScriptFormattingTools.RemoveUnwantedText(text); text = JScriptFormattingTools.RemoveUnwantedBracketText(text); text = JScriptFormattingTools.RemoveUnwantedParentheses(text); LookupTarget target = new LookupTarget(text); List <LookupListItem> lookupItemList; string source = document.GetContent() as string; source = source.Substring(0, document.Editor.CurrentPos); source = JScriptFormattingTools.RemoveUnwantedText(source); source = JScriptFormattingTools.RemoveUnwantedBracketText(source); /* * Looking for namespaces as part of an 'import' * declaration... */ lookupItemList = GetChildNamespaces(target, text); if (lookupItemList != null) { return(new LookupList(target.LookAhead, lookupItemList)); } /* * Looking for members of a namespace... */ if (target.Entity != String.Empty) { List <LookupListItem> types = FindNamespaceTypeLookupItems(target.Entity); List <LookupListItem> namespaces = FindNamespaceChildLookupItems(target.Entity); if (types != null || namespaces != null) { lookupItemList = new List <LookupListItem>(); if (types != null) { lookupItemList.AddRange(types); } if (namespaces != null) { lookupItemList.AddRange(namespaces); } } } if (lookupItemList != null) { return(new LookupList(target.LookAhead, lookupItemList)); } /* * Get the local variables declared within the scope visible * from the lookup location (the caret)... */ DeclaredVariables declaredVariables = new DeclaredVariables(source, fullNamespaceList, true); /* * Looking for anything in scope... */ if (String.IsNullOrEmpty(target.Entity)) { lookupItemList = GetVisibleTypes( source, declaredVariables, true, true); if (lookupItemList != null) { // Add the root namespaces foreach (string ns in rootNamespaceList) { LookupListItem item = new LookupListItem(); item.DisplayText = ns; item.InsertText = ns; item.Category = QuickSharp.CodeAssist.Constants.NAMESPACE; item.ToolTipText = String.Format("namespace {0}", ns); lookupItemList.Add(item); } return(new LookupList(target.LookAhead, lookupItemList)); } } /* * The target cannot be blank after this point; if we haven't found * anything using a blank target then there's nothing to find. */ if (String.IsNullOrEmpty(target.Entity)) { return(null); } /* * Looking for members of a variable... */ Variable variable = declaredVariables.GetVariable(target.Entity); if (variable != null) { String[] split = target.Entity.Split('.'); if (target.IsIndexed) { target.Entity = variable.GetVariableCollectionType(target.Entity); } else { split[0] = variable.Type; target.Entity = String.Join(".", split); } lookupItemList = GetTypeMembers( source, target, false, false); if (lookupItemList != null) { return(new LookupList(target.LookAhead, lookupItemList)); } } /* * Looking for members of a class... */ lookupItemList = GetTypeMembers(source, target, true, false); return(new LookupList(target.LookAhead, lookupItemList)); }