public static bool ShowWindow (char firstChar, ICompletionDataList list, ICompletionWidget completionWidget, CodeCompletionContext completionContext, System.Action closedDelegate) { try { if (wnd == null) { wnd = new CompletionListWindow (); wnd.WordCompleted += HandleWndWordCompleted; } try { if (!wnd.ShowListWindow (firstChar, list, completionWidget, completionContext, closedDelegate)) { if (list is IDisposable) ((IDisposable)list).Dispose (); DestroyWindow (); return false; } if (ForceSuggestionMode) wnd.AutoSelect = false; OnWindowShown (EventArgs.Empty); return true; } catch (Exception ex) { LoggingService.LogError (ex.ToString ()); return false; } } finally { ParameterInformationWindowManager.UpdateWindow (completionWidget); } }
// ext may be null, but then parameter completion don't work public static bool ShowWindow (CompletionTextEditorExtension ext, char firstChar, ICompletionDataList list, ICompletionWidget completionWidget, CodeCompletionContext completionContext) { try { if (ext != null) { int inserted = ext.document.Editor.EnsureCaretIsNotVirtual (); if (inserted > 0) completionContext.TriggerOffset = ext.document.Editor.Caret.Offset; } if (wnd == null) { wnd = new CompletionListWindow (); wnd.WordCompleted += HandleWndWordCompleted; } wnd.Extension = ext; try { if (!wnd.ShowListWindow (firstChar, list, completionWidget, completionContext)) { if (list is IDisposable) ((IDisposable)list).Dispose (); HideWindow (); return false; } if (ForceSuggestionMode) wnd.AutoSelect = false; wnd.Show (); DesktopService.RemoveWindowShadow (wnd); OnWindowShown (EventArgs.Empty); return true; } catch (Exception ex) { LoggingService.LogError (ex.ToString ()); return false; } } finally { ParameterInformationWindowManager.UpdateWindow (ext, completionWidget); } }
static void ContinueSimulation(CompletionListWindow listWindow, ICompletionDataList list, ref TestCompletionWidget testCompletionWidget, string simulatedInput) { listWindow.ResetState(); listWindow.CodeCompletionContext = new CodeCompletionContext(); listWindow.CompletionDataList = list; listWindow.CompletionWidget = testCompletionWidget = new TestCompletionWidget(); listWindow.FilterWords(); listWindow.ResetSizes(); listWindow.UpdateWordSelection(); SimulateInput(listWindow, simulatedInput); listWindow.CompleteWord(); }
public virtual async Task TriggerCompletion(CompletionTriggerReason reason) { if (Editor.SelectionMode == SelectionMode.Block) { return; } if (CompletionWindowManager.IsVisible) { CompletionWindowManager.ToggleCategoryMode(); return; } Editor.EnsureCaretIsNotVirtual(); ICompletionDataList completionList = null; int cpos, wlen; if (!GetCompletionCommandOffset(out cpos, out wlen)) { cpos = Editor.CaretOffset; wlen = 0; } completionTokenSrc.Cancel(); completionTokenSrc = new CancellationTokenSource(); var token = completionTokenSrc.Token; CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext(cpos); CurrentCompletionContext.TriggerWordLength = wlen; var metadata = new Dictionary <string, string> (); metadata ["Result"] = "Success"; try { Counters.ProcessCodeCompletion.BeginTiming(metadata); completionList = await DoHandleCodeCompletionAsync(CurrentCompletionContext, new CompletionTriggerInfo (reason), token); if (completionList != null && completionList.TriggerWordStart >= 0) { CurrentCompletionContext.TriggerOffset = completionList.TriggerWordStart; CurrentCompletionContext.TriggerWordLength = completionList.TriggerWordLength; } if (completionList == null || !CompletionWindowManager.ShowWindow(this, (char)0, completionList, CompletionWidget, CurrentCompletionContext)) { CurrentCompletionContext = null; } } catch (Exception) { metadata ["Result"] = "Failure"; throw; } finally { Counters.ProcessCodeCompletion.EndTiming(); } }
public IListDataProvider <string> GetCollections() { var result = new List <CodeTemplateVariableValue> (); var ext = CurrentContext.DocumentContext.GetContent <CompletionTextEditorExtension> (); var analysisProject = TypeSystemService.GetCodeAnalysisProject(CurrentContext.DocumentContext.Project); var compilation = analysisProject != null?analysisProject.GetCompilationAsync().Result : null; if (ext != null) { if (list == null) { list = ext.HandleCodeCompletionAsync( CurrentContext.DocumentContext.GetContent <MonoDevelop.Ide.CodeCompletion.ICompletionWidget> ().CurrentCodeCompletionContext, CompletionTriggerInfo.CodeCompletionCommand).Result; } //foreach (var data in list.OfType<ISymbolCompletionData> ()) { // if (data.Symbol == null) // continue; // var type = data.Symbol.GetReturnType (); // if (type == null) // continue; // if (GetElementType (compilation, type) != null) { // var method = data as IMethodSymbol; // if (method != null) { // if (method.Parameters.Length == 0) // result.Add (new CodeTemplateVariableValue (data.Symbol.Name + " ()", ((CompletionData)data).Icon)); // continue; // } // if (!result.Any (r => r.Text == data.Symbol.Name)) // result.Add (new CodeTemplateVariableValue (data.Symbol.Name, ((CompletionData)data).Icon)); // } //} //foreach (var data in list.OfType<ISymbolCompletionData> ()) { // var m = data.Symbol as IParameterSymbol; // if (m != null) { // if (GetElementType (compilation, m.Type) != null && !result.Any (r => r.Text == m.Name)) // result.Add (new CodeTemplateVariableValue (m.Name, ((CompletionData)data).Icon)); // } //} //foreach (var sym in list.OfType<ISymbolCompletionData> ()) { // var m = sym.Symbol as ILocalSymbol; // if (m == null) // continue; // if (GetElementType (compilation, m.Type) != null && !result.Any (r => r.Text == m.Name)) // result.Add (new CodeTemplateVariableValue (m.Name, ((CompletionData)sym).Icon)); //} } return(new CodeTemplateListDataProvider(result)); }
public void ShowCompletion (ICompletionDataList completionList) { CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext (Editor.CaretOffset); int cpos, wlen; if (!GetCompletionCommandOffset (out cpos, out wlen)) { cpos = Editor.CaretOffset; wlen = 0; } CurrentCompletionContext.TriggerOffset = cpos; CurrentCompletionContext.TriggerWordLength = wlen; CompletionWindowManager.ShowWindow (this, '\0', completionList, CompletionWidget, CurrentCompletionContext); }
public void ShowCompletion (ICompletionDataList completionList) { currentCompletionContext = CompletionWidget.CreateCodeCompletionContext (Document.Editor.Caret.Offset); int cpos, wlen; if (!GetCompletionCommandOffset (out cpos, out wlen)) { cpos = Document.Editor.Caret.Offset; wlen = 0; } currentCompletionContext.TriggerOffset = cpos; currentCompletionContext.TriggerWordLength = wlen; CompletionWindowManager.ShowWindow ('\0', completionList, CompletionWidget, currentCompletionContext, OnCompletionWindowClosed); }
public void ShowCompletion(ICompletionDataList completionList) { CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext(Editor.CaretOffset); int cpos, wlen; if (!GetCompletionCommandOffset(out cpos, out wlen)) { cpos = Editor.CaretOffset; wlen = 0; } CurrentCompletionContext.TriggerOffset = cpos; CurrentCompletionContext.TriggerWordLength = wlen; CompletionWindowManager.ShowWindow(this, '\0', completionList, CompletionWidget, CurrentCompletionContext); }
public void ShowCompletion(ICompletionDataList completionList) { currentCompletionContext = CompletionWidget.CreateCodeCompletionContext(Document.Editor.Caret.Offset); int cpos, wlen; if (!GetCompletionCommandOffset(out cpos, out wlen)) { cpos = Document.Editor.Caret.Offset; wlen = 0; } currentCompletionContext.TriggerOffset = cpos; currentCompletionContext.TriggerWordLength = wlen; CompletionWindowManager.ShowWindow('\0', completionList, CompletionWidget, currentCompletionContext, OnCompletionWindowClosed); }
} // CompleteConstructor public override ICompletionDataList CodeCompletionCommand( CodeCompletionContext completionContext) { if (null == (Document.Project as ValaProject)) { return(null); } int pos = completionContext.TriggerOffset; ICompletionDataList list = HandleCodeCompletion(completionContext, Editor.GetTextBetween(pos - 1, pos)[0]); if (null == list) { list = GlobalComplete(completionContext); } return(list); }
public virtual ICompletionDataList CodeCompletionCommand(CodeCompletionContext completionContext) { // This default implementation of CodeCompletionCommand calls HandleCodeCompletion providing // the char at the cursor position. If it returns a provider, just return it. int pos = completionContext.TriggerOffset; if (pos > 0) { char ch = Editor.GetCharAt(pos - 1); int triggerWordLength = completionContext.TriggerWordLength; ICompletionDataList completionList = HandleCodeCompletion(completionContext, ch, ref triggerWordLength); if (completionList != null) { return(completionList); } } return(null); }
internal void OnUpdateShowCodeTemplatesWindow(CommandInfo info) { ICompletionDataList completionList = null; int cpos, wlen; if (!GetCompletionCommandOffset(out cpos, out wlen)) { cpos = Editor.Caret.Offset; wlen = 0; } var ctx = CompletionWidget.CreateCodeCompletionContext(cpos); ctx.TriggerWordLength = wlen; completionList = Document.Editor.IsSomethingSelected ? ShowCodeSurroundingsCommand(ctx) : ShowCodeTemplatesCommand(ctx); info.Bypass = completionList == null; info.Text = Document.Editor.IsSomethingSelected ? GettextCatalog.GetString("_Surround With...") : GettextCatalog.GetString("I_nsert Template..."); }
/// <summary> /// Shows the completion window. The ShowListWindow method is internal /// so use reflection to call it. There are no public methods that can /// be used. /// </summary> public static bool ShowListWindow( this CompletionListWindow window, char firstChar, ICompletionDataList list, ICompletionWidget completionWidget, CodeCompletionContext completionContext) { MethodInfo[] methods = window.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance); foreach (MethodInfo method in methods) { if (method.Name == "ShowListWindow") { if (method.GetParameters().Length == 4) { return((bool)method.Invoke(window, new object[] { firstChar, list, completionWidget, completionContext })); } } } throw new NotImplementedException("CompletListWindow.ShowListWindow not found"); }
public virtual async Task TriggerCompletion(CompletionTriggerReason reason) { if (Editor.SelectionMode == SelectionMode.Block) { return; } if (CompletionWindowManager.IsVisible) { CompletionWindowManager.ToggleCategoryMode(); return; } Editor.EnsureCaretIsNotVirtual(); ICompletionDataList completionList = null; int cpos, wlen; if (!GetCompletionCommandOffset(out cpos, out wlen)) { cpos = Editor.CaretOffset; wlen = 0; } CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext(cpos); CurrentCompletionContext.TriggerWordLength = wlen; try { Counters.ProcessCodeCompletion.BeginTiming(); completionList = await DoHandleCodeCompletionAsync(CurrentCompletionContext, new CompletionTriggerInfo (reason)); if (completionList != null && completionList.TriggerWordStart >= 0) { CurrentCompletionContext.TriggerOffset = completionList.TriggerWordStart; CurrentCompletionContext.TriggerWordLength = completionList.TriggerWordLength; } if (completionList == null || !CompletionWindowManager.ShowWindow(this, (char)0, completionList, CompletionWidget, CurrentCompletionContext)) { CurrentCompletionContext = null; } } finally { Counters.ProcessCodeCompletion.EndTiming(); } }
protected override void OnDestroyed() { if (declarationviewwindow != null) { declarationviewwindow.Destroy(); declarationviewwindow = null; } if (mutableList != null) { mutableList.Changing -= OnCompletionDataChanging; mutableList.Changed -= OnCompletionDataChanged; mutableList = null; } if (completionDataList != null) { if (completionDataList is IDisposable) { ((IDisposable)completionDataList).Dispose(); } CloseCompletionList(); completionDataList = null; } if (closedDelegate != null) { closedDelegate(); closedDelegate = null; } HideDeclarationView(); if (declarationviewwindow != null) { declarationviewwindow.Destroy(); declarationviewwindow = null; } base.OnDestroyed(); }
internal void OnUpdateShowCodeTemplatesWindow(CommandInfo info) { ICompletionDataList completionList = null; int cpos, wlen; if (!GetCompletionCommandOffset(out cpos, out wlen)) { cpos = Editor.CaretOffset; wlen = 0; } try { var ctx = CompletionWidget.CreateCodeCompletionContext(cpos); ctx.TriggerWordLength = wlen; completionList = Editor.IsSomethingSelected ? ShowCodeSurroundingsCommand(ctx) : ShowCodeTemplatesCommand(ctx); info.Bypass = completionList == null; info.Text = Editor.IsSomethingSelected ? GettextCatalog.GetString("_Surround With...") : GettextCatalog.GetString("I_nsert Template..."); } catch (Exception e) { LoggingService.LogError("Error while update show code templates window", e); info.Bypass = true; } }
internal static bool ShowWindow(ICompletionDataList list, CodeCompletionContext completionContext) { if (wnd == null || !isShowing) { return(false); } var completionWidget = wnd.CompletionWidget; var ext = wnd.Extension; try { try { isShowing = false; if (!wnd.ShowListWindow(list, completionContext)) { if (list is IDisposable) { ((IDisposable)list).Dispose(); } HideWindow(); return(false); } if (IdeApp.Preferences.ForceSuggestionMode) { wnd.AutoSelect = false; } wnd.Show(); DesktopService.RemoveWindowShadow(wnd); OnWindowShown(EventArgs.Empty); return(true); } catch (Exception ex) { LoggingService.LogError(ex.ToString()); return(false); } } finally { ParameterInformationWindowManager.UpdateWindow(ext, completionWidget); } }
protected void ShowCompletion(ICompletionDataList completionList, int triggerWordLength, char keyChar) { if (CompletionWidget != null && currentCompletionContext == null) { currentCompletionContext = CompletionWidget.CurrentCodeCompletionContext; if (triggerWordLength > 0 && triggerWordLength < Editor.Caret.Offset) { currentCompletionContext = CompletionWidget.CreateCodeCompletionContext(Editor.Caret.Offset - triggerWordLength); currentCompletionContext.TriggerWordLength = triggerWordLength; } if (completionList != null) { CompletionWindowManager.ShowWindow(keyChar, completionList, CompletionWidget, currentCompletionContext, OnCompletionWindowClosed); } else { currentCompletionContext = null; } } autoHideCompletionWindow = true; }
public virtual void RunShowCodeTemplatesWindow() { ICompletionDataList completionList = null; int cpos, wlen; if (!GetCompletionCommandOffset(out cpos, out wlen)) { cpos = Editor.CaretOffset; wlen = 0; } var ctx = CompletionWidget.CreateCodeCompletionContext(cpos); ctx.TriggerWordLength = wlen; completionList = Editor.IsSomethingSelected ? ShowCodeSurroundingsCommand(ctx) : ShowCodeTemplatesCommand(ctx); if (completionList == null) { return; } var wnd = CompletionListWindow.CreateAsDialog(); wnd.Extension = this; wnd.ShowListWindow((char)0, completionList, CompletionWidget, ctx); }
public override ICompletionDataList HandleCodeCompletion(CodeCompletionContext completionContext, char completionChar, ref int triggerWordLength) { if (mCanRunCompletion && mCompletionEnabled) { switch (completionChar) { case '.': case '(': return(GetCompletionList(completionContext)); default: if (char.IsLetter(completionChar)) { // Aggressive completion ICompletionDataList list = GlobalComplete(); triggerWordLength = ResetTriggerOffset(completionContext); return(list); } break; } } return(null); }
public virtual void RunShowCodeTemplatesWindow() { ICompletionDataList completionList = null; int cpos, wlen; if (!GetCompletionCommandOffset(out cpos, out wlen)) { cpos = Editor.Caret.Offset; wlen = 0; } currentCompletionContext = CompletionWidget.CreateCodeCompletionContext(cpos); currentCompletionContext.TriggerWordLength = wlen; completionList = Document.Editor.IsSomethingSelected ? ShowCodeSurroundingsCommand(currentCompletionContext) : ShowCodeTemplatesCommand(currentCompletionContext); if (completionList != null) { CompletionWindowManager.ShowWindow(this, (char)0, completionList, CompletionWidget, currentCompletionContext); } else { currentCompletionContext = null; } }
public virtual void RunShowCodeTemplatesWindow() { ICompletionDataList completionList = null; int cpos, wlen; if (!GetCompletionCommandOffset(out cpos, out wlen)) { cpos = Editor.CursorPosition; wlen = 0; } currentCompletionContext = completionWidget.CreateCodeCompletionContext(cpos); currentCompletionContext.TriggerWordLength = wlen; completionList = Document.TextEditor.SelectionStartPosition != Document.TextEditor.SelectionEndPosition ? ShowCodeSurroundingsCommand(currentCompletionContext) : ShowCodeTemplatesCommand(currentCompletionContext); if (completionList != null) { CompletionWindowManager.ShowWindow((char)0, completionList, completionWidget, currentCompletionContext, OnCompletionWindowClosed); } else { currentCompletionContext = null; } }
internal bool ShowListWindow(char firstChar, ICompletionDataList list, ICompletionWidget completionWidget, CodeCompletionContext completionContext, System.Action closedDelegate) { if (mutableList != null) { mutableList.Changing -= OnCompletionDataChanging; mutableList.Changed -= OnCompletionDataChanged; HideFooter(); } //initialWordLength = 0; this.completionDataList = list; this.CompleteWithSpaceOrPunctuation = true; //MonoDevelop.Core.PropertyService.Get ("CompleteWithSpaceOrPunctuation", true); this.CodeCompletionContext = completionContext; this.closedDelegate = closedDelegate; mutableList = completionDataList as IMutableCompletionDataList; List.PreviewCompletionString = completionDataList.CompletionSelectionMode == CompletionSelectionMode.OwnTextField; if (mutableList != null) { mutableList.Changing += OnCompletionDataChanging; mutableList.Changed += OnCompletionDataChanged; if (mutableList.IsChanging) { OnCompletionDataChanging(null, null); } } this.CompletionWidget = completionWidget; if (FillList()) { // not neccessarry, because list window is not reused anymore: // Reset (true); this.AutoSelect = list.AutoSelect; this.AutoCompleteEmptyMatch = list.AutoCompleteEmptyMatch; // makes control-space in midle of words to work string text = completionWidget.GetCompletionText(completionContext, false); DefaultCompletionString = completionDataList.DefaultCompletionString ?? ""; if (text.Length == 0) { UpdateWordSelection(); initialWordLength = 0; //completionWidget.SelectedLength; ResetSizes(); ShowAll(); UpdateWordSelection(); //if there is only one matching result we take it by default if (completionDataList.AutoCompleteUniqueMatch && IsUniqueMatch && !IsChanging) { CompleteWord(); CompletionWindowManager.HideWindow(); } return(true); } initialWordLength = text.Length /*+ completionWidget.SelectedLength*/; PartialWord = text; UpdateWordSelection(); //if there is only one matching result we take it by default if (completionDataList.AutoCompleteUniqueMatch && IsUniqueMatch && !IsChanging) { CompleteWord(); CompletionWindowManager.HideWindow(); } else { ResetSizes(); ShowAll(); } return(true); } CompletionWindowManager.HideWindow(); return(false); }
public IListDataProvider<string> GetCollections () { var result = new List<CodeTemplateVariableValue> (); var ext = CurrentContext.DocumentContext.GetContent <CompletionTextEditorExtension> (); var analysisProject = TypeSystemService.GetCodeAnalysisProject (CurrentContext.DocumentContext.Project); var compilation = analysisProject != null ? analysisProject.GetCompilationAsync ().Result : null; if (ext != null) { if (list == null) list = ext.CodeCompletionCommand ( CurrentContext.DocumentContext.GetContent <MonoDevelop.Ide.CodeCompletion.ICompletionWidget> ().CurrentCodeCompletionContext).Result; foreach (var data in list.OfType<ISymbolCompletionData> ()) { if (GetElementType (compilation, data.Symbol.GetReturnType ()).TypeKind != TypeKind.Error) { var method = data as IMethodSymbol; if (method != null) { if (method.Parameters.Length == 0) result.Add (new CodeTemplateVariableValue (data.Symbol.Name + " ()", ((CompletionData)data).Icon)); continue; } result.Add (new CodeTemplateVariableValue (data.Symbol.Name, ((CompletionData)data).Icon)); } } foreach (var data in list.OfType<ISymbolCompletionData> ()) { var m = data.Symbol as IParameterSymbol; if (m != null) { if (GetElementType (compilation, m.Type).TypeKind != TypeKind.Error) result.Add (new CodeTemplateVariableValue (m.Name, ((CompletionData)data).Icon)); } } foreach (var sym in list.OfType<ISymbolCompletionData> ()) { var m = sym.Symbol as ILocalSymbol; if (m == null) continue; if (GetElementType (compilation, m.Type).TypeKind != TypeKind.Error) result.Add (new CodeTemplateVariableValue (m.Name, ((CompletionData)m).Icon)); } } return new CodeTemplateListDataProvider (result); }
static bool completionListContains(ICompletionDataList completionList, string expected) { foreach (CompletionData completionItem in completionList) { if (completionItem.DisplayText == expected) return true; } return false; }
// When a key is pressed, and before the key is processed by the editor, this method will be invoked. // Return true if the key press should be processed by the editor. public override bool KeyPress(Gdk.Key key, char keyChar, Gdk.ModifierType modifier) { bool res; if (currentCompletionContext != null) { if (CompletionWindowManager.PreProcessKeyEvent(key, keyChar, modifier)) { CompletionWindowManager.PostProcessKeyEvent(key, keyChar, modifier); autoHideCompletionWindow = true; return(false); } autoHideCompletionWindow = false; } if (ParameterInformationWindowManager.IsWindowVisible) { if (ParameterInformationWindowManager.ProcessKeyEvent(this, CompletionWidget, key, modifier)) { return(false); } autoHideCompletionWindow = false; } // int oldPos = Editor.CursorPosition; // int oldLen = Editor.TextLength; res = base.KeyPress(key, keyChar, modifier); CompletionWindowManager.PostProcessKeyEvent(key, keyChar, modifier); var ignoreMods = Gdk.ModifierType.ControlMask | Gdk.ModifierType.MetaMask | Gdk.ModifierType.Mod1Mask | Gdk.ModifierType.SuperMask; // Handle parameter completion if (ParameterInformationWindowManager.IsWindowVisible) { ParameterInformationWindowManager.PostProcessKeyEvent(this, CompletionWidget, key, modifier); } if ((modifier & ignoreMods) != 0) { return(res); } // don't complete on block selection if (!EnableCodeCompletion || Document.Editor.SelectionMode == Mono.TextEditor.SelectionMode.Block) { return(res); } // Handle code completion if (keyChar != '\0' && CompletionWidget != null && currentCompletionContext == null) { currentCompletionContext = CompletionWidget.CurrentCodeCompletionContext; int triggerWordLength = currentCompletionContext.TriggerWordLength; ICompletionDataList completionList = HandleCodeCompletion(currentCompletionContext, keyChar, ref triggerWordLength); if (triggerWordLength > 0 && (triggerWordLength < Editor.Caret.Offset || (triggerWordLength == 1 && Editor.Caret.Offset == 1))) { currentCompletionContext = CompletionWidget.CreateCodeCompletionContext(Editor.Caret.Offset - triggerWordLength); currentCompletionContext.TriggerWordLength = triggerWordLength; } if (completionList != null) { if (!CompletionWindowManager.ShowWindow(this, keyChar, completionList, CompletionWidget, currentCompletionContext)) { currentCompletionContext = null; } } else { currentCompletionContext = null; } } if (EnableParameterInsight && CompletionWidget != null) { CodeCompletionContext ctx = CompletionWidget.CurrentCodeCompletionContext; IParameterDataProvider paramProvider = HandleParameterCompletion(ctx, keyChar); if (paramProvider != null) { ParameterInformationWindowManager.ShowWindow(this, CompletionWidget, ctx, paramProvider); } } autoHideCompletionWindow = true; return(res); }
// ext may be null, but then parameter completion don't work internal static bool ShowWindow(CompletionTextEditorExtension ext, char firstChar, ICompletionDataList list, ICompletionWidget completionWidget, CodeCompletionContext completionContext) { PrepareShowWindow(ext, firstChar, completionWidget, completionContext); return(ShowWindow(list, completionContext)); }
protected void ShowCompletion (ICompletionDataList completionList, int triggerWordLength, char keyChar) { if (Editor.SelectionMode == SelectionMode.Block) return; if (CompletionWidget != null && CurrentCompletionContext == null) { CurrentCompletionContext = CompletionWidget.CurrentCodeCompletionContext; if (triggerWordLength > 0 && triggerWordLength < Editor.CaretOffset) { CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext (Editor.CaretOffset - triggerWordLength); CurrentCompletionContext.TriggerWordLength = triggerWordLength; } if (completionList != null) CompletionWindowManager.ShowWindow (this, keyChar, completionList, CompletionWidget, CurrentCompletionContext); else CurrentCompletionContext = null; } autoHideCompletionWindow = autoHideParameterWindow = true; }
internal bool ShowListWindow(char firstChar, ICompletionDataList list, ICompletionWidget completionWidget, CodeCompletionContext completionContext) { InitializeListWindow(completionWidget, completionContext); return(ShowListWindow(list, completionContext)); }
internal bool ShowListWindow(ICompletionDataList list, CodeCompletionContext completionContext) { return(window.ShowListWindow(list, completionContext)); }
internal bool ShowListWindow(char firstChar, ICompletionDataList list, ICompletionWidget completionWidget, CodeCompletionContext completionContext) { return(window.ShowListWindow(firstChar, list, completionWidget, completionContext)); }
public void FillCompletionList(ICompletionDataList completionList, CodeCompletionContext completionContext, char completionChar, ref int triggerWordLength) { }
internal static IComparer <CompletionData> GetComparerForCompletionList(ICompletionDataList dataList) { var concrete = dataList as CompletionDataList; return(concrete != null && concrete.Comparer != null ? concrete.Comparer : new DataItemComparer()); }
static CompletionListFilterResult DefaultFilterWords(ICompletionDataList dataList, List <int> filteredItems, string oldCompletionString, string CompletionString) { var newCategories = new List <CategorizedCompletionItems> (); var matcher = CompletionMatcher.CreateCompletionMatcher(CompletionString); if (oldCompletionString == null || !CompletionString.StartsWith(oldCompletionString, StringComparison.Ordinal)) { filteredItems.Clear(); for (int newSelection = 0; newSelection < dataList.Count; newSelection++) { if (string.IsNullOrEmpty(CompletionString) || matcher.IsMatch(dataList [newSelection].DisplayText)) { var completionCategory = dataList [newSelection].CompletionCategory; GetCategory(newCategories, completionCategory).Items.Add(newSelection); filteredItems.Add(newSelection); } } } else { var oldItems = filteredItems; filteredItems = new List <int> (); foreach (int newSelection in oldItems) { if (string.IsNullOrEmpty(CompletionString) || matcher.IsMatch(dataList [newSelection].DisplayText)) { var completionCategory = dataList [newSelection].CompletionCategory; GetCategory(newCategories, completionCategory).Items.Add(newSelection); filteredItems.Add(newSelection); } } } filteredItems.Sort(delegate(int left, int right) { int rank1, rank2; var data1 = dataList [left]; var data2 = dataList [right]; if (data1 == null || data2 == null) { return(0); } if (data1.PriorityGroup != data2.PriorityGroup) { return(data2.PriorityGroup.CompareTo(data1.PriorityGroup)); } if (string.IsNullOrEmpty(CompletionString)) { return(CompareTo(dataList, left, right)); } if (!matcher.CalcMatchRank(data1.CompletionText, out rank1)) { return(0); } if (!matcher.CalcMatchRank(data2.CompletionText, out rank2)) { return(0); } return(rank2.CompareTo(rank1)); }); // put the item from a lower priority group with the highest match rank always to position #2 if (filteredItems.Count > 0) { int idx = 0; int rank; var data = dataList[filteredItems [0]]; int firstGrp = data.PriorityGroup; matcher.CalcMatchRank(data.CompletionText, out rank); for (int i = 1; i < filteredItems.Count; i++) { var curData = dataList[filteredItems [i]]; if (curData.PriorityGroup == firstGrp) { continue; } int curRank; matcher.CalcMatchRank(curData.CompletionText, out curRank); if (curRank > rank) { idx = i; rank = curRank; } } if (idx != 0) { var tmp = filteredItems [idx]; for (int i = idx; i > 1; i--) { filteredItems [i] = filteredItems [i - 1]; } filteredItems [1] = tmp; } } newCategories.Sort(delegate(CategorizedCompletionItems left, CategorizedCompletionItems right) { if (left.CompletionCategory == null) { return(1); } if (right.CompletionCategory == null) { return(-1); } return(left.CompletionCategory.CompareTo(right.CompletionCategory)); }); return(new CompletionListFilterResult(filteredItems, newCategories)); }
static void ContinueSimulation (CompletionListWindow listWindow, ICompletionDataList list, ref TestCompletionWidget testCompletionWidget, string simulatedInput) { listWindow.ResetState (); listWindow.CodeCompletionContext = new CodeCompletionContext (); listWindow.CompletionDataList = list; listWindow.CompletionWidget = testCompletionWidget = new TestCompletionWidget (); listWindow.List.FilterWords (); listWindow.ResetSizes (); listWindow.UpdateWordSelection (); SimulateInput (listWindow, simulatedInput); listWindow.CompleteWord (); }
protected void ShowCompletion (ICompletionDataList completionList, int triggerWordLength, char keyChar) { if (CompletionWidget != null && currentCompletionContext == null) { currentCompletionContext = CompletionWidget.CurrentCodeCompletionContext; if (triggerWordLength > 0 && triggerWordLength < Editor.Caret.Offset) { currentCompletionContext = CompletionWidget.CreateCodeCompletionContext (Editor.Caret.Offset - triggerWordLength); currentCompletionContext.TriggerWordLength = triggerWordLength; } if (completionList != null) CompletionWindowManager.ShowWindow (keyChar, completionList, CompletionWidget, currentCompletionContext, OnCompletionWindowClosed); else currentCompletionContext = null; } autoHideCompletionWindow = true; }
// When a key is pressed, and before the key is processed by the editor, this method will be invoked. // Return true if the key press should be processed by the editor. public override bool KeyPress(Gdk.Key key, char keyChar, Gdk.ModifierType modifier) { bool res; KeyActions ka = KeyActions.None; if (currentCompletionContext != null) { if (CompletionWindowManager.PreProcessKeyEvent(key, keyChar, modifier, out ka)) { CompletionWindowManager.PostProcessKeyEvent(ka, key, keyChar, modifier); autoHideCompletionWindow = true; return(false); } autoHideCompletionWindow = false; } if (ParameterInformationWindowManager.IsWindowVisible) { if (ParameterInformationWindowManager.ProcessKeyEvent(CompletionWidget, key, modifier)) { return(false); } autoHideCompletionWindow = false; } // int oldPos = Editor.CursorPosition; // int oldLen = Editor.TextLength; res = base.KeyPress(key, keyChar, modifier); CompletionWindowManager.PostProcessKeyEvent(ka, key, keyChar, modifier); var ignoreMods = Gdk.ModifierType.ControlMask | Gdk.ModifierType.MetaMask | Gdk.ModifierType.Mod1Mask | Gdk.ModifierType.SuperMask; // Handle parameter completion if (ParameterInformationWindowManager.IsWindowVisible) { ParameterInformationWindowManager.PostProcessKeyEvent(CompletionWidget, key, modifier); } if ((modifier & ignoreMods) != 0) { return(res); } /* * if (Document.TextEditorData == null || Document.TextEditorData.IsSomethingSelected && Document.TextEditorData.SelectionMode != Mono.TextEditor.SelectionMode.Block) { * int posChange = Editor.CursorPosition - oldPos; * if (currentCompletionContext != null && (Math.Abs (posChange) > 1 || (Editor.TextLength - oldLen) != posChange)) { * currentCompletionContext = null; * CompletionWindowManager.HideWindow (); * ParameterInformationWindowManager.HideWindow (); * return res; * } * }*/ // don't complete on block selection if (!enableCodeCompletion || Document.Editor.SelectionMode == Mono.TextEditor.SelectionMode.Block) { return(res); } // Handle code completion if (keyChar != '\0' && CompletionWidget != null && currentCompletionContext == null) { currentCompletionContext = CompletionWidget.CurrentCodeCompletionContext; int triggerWordLength = currentCompletionContext.TriggerWordLength; ICompletionDataList completionList = HandleCodeCompletion(currentCompletionContext, keyChar, ref triggerWordLength); if (triggerWordLength > 0 && (triggerWordLength < Editor.Caret.Offset || (triggerWordLength == 1 && Editor.Caret.Offset == 1))) { currentCompletionContext = CompletionWidget.CreateCodeCompletionContext(Editor.Caret.Offset - triggerWordLength); currentCompletionContext.TriggerWordLength = triggerWordLength; } if (completionList != null) { if (!CompletionWindowManager.ShowWindow(keyChar, completionList, CompletionWidget, currentCompletionContext, OnCompletionWindowClosed)) { currentCompletionContext = null; } } else { currentCompletionContext = null; } } if (enableParameterInsight && CompletionWidget != null) { CodeCompletionContext ctx = CompletionWidget.CurrentCodeCompletionContext; IParameterDataProvider paramProvider = HandleParameterCompletion(ctx, keyChar); if (paramProvider != null) { ParameterInformationWindowManager.ShowWindow(CompletionWidget, ctx, paramProvider); } } autoHideCompletionWindow = true; return(res); }
internal bool ShowListWindow(ICompletionDataList list, CodeCompletionContext completionContext) { if (list == null) { throw new ArgumentNullException("list"); } CodeCompletionContext = completionContext; CompletionDataList = list; ResetState(); mutableList = completionDataList as IMutableCompletionDataList; PreviewCompletionString = completionDataList.CompletionSelectionMode == CompletionSelectionMode.OwnTextField; if (mutableList != null) { mutableList.Changing += OnCompletionDataChanging; mutableList.Changed += OnCompletionDataChanged; if (mutableList.IsChanging) { OnCompletionDataChanging(null, null); } } if (FillList()) { AutoSelect = list.AutoSelect; AutoCompleteEmptyMatch = list.AutoCompleteEmptyMatch; AutoCompleteEmptyMatchOnCurlyBrace = list.AutoCompleteEmptyMatchOnCurlyBrace; CloseOnSquareBrackets = list.CloseOnSquareBrackets; // makes control-space in midle of words to work string text = CompletionWidget.GetCompletionText(CodeCompletionContext); DefaultCompletionString = completionDataList.DefaultCompletionString ?? ""; if (text.Length == 0) { initialWordLength = 0; //completionWidget.SelectedLength; StartOffset = completionContext.TriggerOffset; UpdateWordSelection(); ResetSizes(); ShowAll(); UpdateWordSelection(); UpdateDeclarationView(); //if there is only one matching result we take it by default if (completionDataList.AutoCompleteUniqueMatch && IsUniqueMatch && !IsChanging) { CompleteWord(); CompletionWindowManager.HideWindow(); return(false); } return(true); } initialWordLength = CompletionWidget.SelectedLength > 0 ? 0 : text.Length; StartOffset = CompletionWidget.CaretOffset - initialWordLength; HideWhenWordDeleted = initialWordLength != 0; ResetSizes(); UpdateWordSelection(); //if there is only one matching result we take it by default if (completionDataList.AutoCompleteUniqueMatch && IsUniqueMatch && !IsChanging) { CompleteWord(); CompletionWindowManager.HideWindow(); return(false); } ShowAll(); UpdateDeclarationView(); return(true); } CompletionWindowManager.HideWindow(); return(false); }
public virtual CompletionSelectionStatus FindMatchedEntry(ICompletionDataList completionDataList, MruCache cache, string partialWord, List <int> filteredItems) { // default - word with highest match rating in the list. int idx = -1; if (DefaultCompletionString != null && DefaultCompletionString.StartsWith(partialWord, StringComparison.OrdinalIgnoreCase)) { partialWord = DefaultCompletionString; } StringMatcher matcher = null; if (!string.IsNullOrEmpty(partialWord)) { matcher = CompletionMatcher.CreateCompletionMatcher(partialWord); string bestWord = null; int bestRank = int.MinValue; int bestIndex = 0; int bestIndexPriority = int.MinValue; for (int i = 0; i < filteredItems.Count; i++) { int index = filteredItems [i]; var data = completionDataList [index]; if (bestIndexPriority > data.PriorityGroup) { continue; } string text = data.DisplayText; int rank; if (!matcher.CalcMatchRank(text, out rank)) { continue; } if (rank > bestRank || data.PriorityGroup > bestIndexPriority) { bestWord = text; bestRank = rank; bestIndex = i; bestIndexPriority = data.PriorityGroup; } } if (bestWord != null) { idx = bestIndex; // exact match found. if (string.Compare(bestWord, partialWord ?? "", true) == 0) { return(new CompletionSelectionStatus(idx)); } } } CompletionData currentData; int bestMruIndex; if (idx >= 0) { currentData = completionDataList [filteredItems [idx]]; bestMruIndex = cache.GetIndex(currentData); } else { bestMruIndex = int.MaxValue; currentData = null; } for (int i = 0; i < filteredItems.Count; i++) { var mruData = completionDataList [filteredItems [i]]; int curMruIndex = cache.GetIndex(mruData); if (curMruIndex == 1) { continue; } if (curMruIndex < bestMruIndex) { int r1 = 0, r2 = 0; if (currentData == null || matcher != null && matcher.CalcMatchRank(mruData.DisplayText, out r1) && matcher.CalcMatchRank(currentData.DisplayText, out r2)) { if (r1 >= r2 || partialWord.Length == 0 || partialWord.Length == 1 && mruData.DisplayText [0] == partialWord [0]) { bestMruIndex = curMruIndex; idx = i; currentData = mruData; } } } } return(new CompletionSelectionStatus(idx)); }
internal static bool ShowWindow (ICompletionDataList list, CodeCompletionContext completionContext) { if (wnd == null || !isShowing) return false; var completionWidget = wnd.CompletionWidget; var ext = wnd.Extension; try { try { isShowing = false; if (!wnd.ShowListWindow (list, completionContext)) { if (list is IDisposable) ((IDisposable)list).Dispose (); HideWindow (); return false; } if (IdeApp.Preferences.ForceSuggestionMode) wnd.AutoSelect = false; wnd.Show (); DesktopService.RemoveWindowShadow (wnd); OnWindowShown (EventArgs.Empty); return true; } catch (Exception ex) { LoggingService.LogError (ex.ToString ()); return false; } } finally { ParameterInformationWindowManager.UpdateWindow (ext, completionWidget); } }
// ext may be null, but then parameter completion don't work internal static bool ShowWindow (CompletionTextEditorExtension ext, char firstChar, ICompletionDataList list, ICompletionWidget completionWidget, CodeCompletionContext completionContext) { PrepareShowWindow (ext, firstChar, completionWidget, completionContext); return ShowWindow (list, completionContext); }
// ext may be null, but then parameter completion don't work public static bool ShowWindow(CompletionTextEditorExtension ext, char firstChar, ICompletionDataList list, ICompletionWidget completionWidget, CodeCompletionContext completionContext) { try { if (ext != null) { int inserted = ext.document.Editor.EnsureCaretIsNotVirtual(); if (inserted > 0) { completionContext.TriggerOffset = ext.document.Editor.Caret.Offset; } } if (wnd == null) { wnd = new CompletionListWindow(); wnd.WordCompleted += HandleWndWordCompleted; } wnd.Extension = ext; try { if (!wnd.ShowListWindow(firstChar, list, completionWidget, completionContext)) { if (list is IDisposable) { ((IDisposable)list).Dispose(); } HideWindow(); return(false); } if (ForceSuggestionMode) { wnd.AutoSelect = false; } wnd.Show(); DesktopService.RemoveWindowShadow(wnd); OnWindowShown(EventArgs.Empty); return(true); } catch (Exception ex) { LoggingService.LogError(ex.ToString()); return(false); } } finally { ParameterInformationWindowManager.UpdateWindow(ext, completionWidget); } }