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; ITimeTracker timer = null; bool failure = false; try { timer = Counters.ProcessCodeCompletion.BeginTiming(); 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) { failure = true; throw; } finally { Counters.ProcessCodeCompletion.EndTiming(); if (failure) { completionStats.OnFailure(timer.Duration); } else { completionStats.OnSuccess(timer.Duration); } } }
public virtual void RunCompletionCommand() { if (Document.Editor.SelectionMode == Mono.TextEditor.SelectionMode.Block) { return; } if (CompletionWindowManager.IsVisible) { CompletionWindowManager.Wnd.ToggleCategoryMode(); return; } 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 = CodeCompletionCommand(currentCompletionContext); if (completionList != null) { CompletionWindowManager.ShowWindow(this, (char)0, completionList, CompletionWidget, currentCompletionContext); } else { currentCompletionContext = null; } }
public override Task <ICompletionDataList> HandleCodeCompletionAsync(CodeCompletionContext completionContext, CompletionTriggerInfo triggerInfo, CancellationToken token = default(CancellationToken)) { if (triggerInfo.CompletionTriggerReason == CompletionTriggerReason.CharTyped) { int pos = completionContext.TriggerOffset; char ch = CompletionWidget != null?CompletionWidget.GetChar(pos - 1) : Editor.GetCharAt(pos - 1); if (pos > 0 && ch == triggerInfo.TriggerCharacter.Value) { tracker.UpdateEngine(); return(HandleCodeCompletion(completionContext, false, token)); } } else if (triggerInfo.CompletionTriggerReason == CompletionTriggerReason.CompletionCommand) { int pos = completionContext.TriggerOffset; if (pos <= 0) { return(null); } tracker.UpdateEngine(); return(HandleCodeCompletion(completionContext, true, default(CancellationToken))); } return(null); }
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; }
public virtual async Task TriggerCompletion(CompletionTriggerReason reason) { if (Editor.SelectionMode == SelectionMode.Block) { return; } if (CompletionWindowManager.IsVisible) { CompletionWindowManager.Wnd.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; completionList = await HandleCodeCompletionAsync(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; } }
public virtual void RunShowCodeTemplatesWindow() { Editor.EnsureCaretIsNotVirtual(); 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 virtual async void RunCompletionCommand() { if (Editor.SelectionMode == SelectionMode.Block) { return; } if (CompletionWindowManager.IsVisible) { CompletionWindowManager.Wnd.ToggleCategoryMode(); return; } ICompletionDataList completionList = null; int cpos, wlen; if (!GetCompletionCommandOffset(out cpos, out wlen)) { cpos = Editor.CaretOffset; wlen = 0; } CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext(cpos); CurrentCompletionContext.TriggerWordLength = wlen; completionList = await CodeCompletionCommand(CurrentCompletionContext); if (completionList == null || !CompletionWindowManager.ShowWindow(this, (char)0, completionList, CompletionWidget, CurrentCompletionContext)) { CurrentCompletionContext = null; } }
public virtual void RunShowCodeTemplatesWindow() { 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); if (completionList == null) { return; } var wnd = new CompletionListWindow(Gtk.WindowType.Toplevel); wnd.TypeHint = Gdk.WindowTypeHint.Dialog; wnd.SkipPagerHint = true; wnd.SkipTaskbarHint = true; wnd.Decorated = false; wnd.Extension = this; wnd.ShowListWindow((char)0, completionList, CompletionWidget, ctx); }
public override Task<ICompletionDataList> HandleCodeCompletionAsync (CodeCompletionContext completionContext, char completionChar, CancellationToken token = default(CancellationToken)) { int pos = completionContext.TriggerOffset; char ch = CompletionWidget != null ? CompletionWidget.GetChar (pos - 1) : Editor.GetCharAt (pos - 1); if (pos > 0 && ch == completionChar) { tracker.UpdateEngine (); return HandleCodeCompletion (completionContext, false, token); } return null; }
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 override ICompletionDataList HandleCodeCompletion( CodeCompletionContext completionContext, char completionChar, ref int triggerWordLength) { int pos = completionContext.TriggerOffset; char ch = CompletionWidget != null?CompletionWidget.GetChar(pos - 1) : Editor.GetCharAt(pos - 1); if (pos > 0 && ch == completionChar) { tracker.UpdateEngine(); return(HandleCodeCompletion(completionContext, false, ref triggerWordLength)); } return(null); }
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 virtual async void RunParameterCompletionCommand() { if (Editor.SelectionMode == SelectionMode.Block || CompletionWidget == null) { return; } ParameterHintingResult cp = null; int cpos = Editor.CaretOffset; CodeCompletionContext ctx = CompletionWidget.CreateCodeCompletionContext(cpos); cp = await ParameterCompletionCommand(ctx); if (cp != null) { ParameterInformationWindowManager.ShowWindow(this, CompletionWidget, ctx, cp); ParameterInformationWindowManager.PostProcessKeyEvent(this, CompletionWidget, KeyDescriptor.FromGtk(Gdk.Key.F, 'f', Gdk.ModifierType.None)); } }
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..."); }
public override bool KeyPress(Gdk.Key key, char keyChar, Gdk.ModifierType modifier) { updater.BeginUpdate(); if (this.CompletionWidget != null) { switch (keyChar) { case '(': case ')': case ';': case ']': ParameterInformationWindowManager.HideWindow(this, CompletionWidget); break; default: if (lastTriggerOffset >= 0 && char.IsDigit(keyChar)) { bool containsDigitsOnly = true; for (int offset = lastTriggerOffset; offset < CompletionWidget.CaretOffset; offset++) { if (!char.IsDigit(CompletionWidget.GetChar(offset))) { containsDigitsOnly = false; break; } } if (containsDigitsOnly) { CompletionWindowManager.HideWindow(); } } break; } } var ret = base.KeyPress(key, keyChar, modifier); updater.FinishUpdate(); return(ret); }
internal void OnUpdateSelectionSurroundWith(CommandInfo info) { info.Enabled = Editor.IsSomethingSelected && !string.IsNullOrWhiteSpace(Editor.SelectedText); info.Bypass = !IsActiveExtension() || !info.Enabled; if (info.Enabled) { if (!GetCompletionCommandOffset(out var cpos, out var wlen)) { cpos = Editor.CaretOffset; wlen = 0; } try { var ctx = CompletionWidget.CreateCodeCompletionContext(cpos); ctx.TriggerWordLength = wlen; info.Bypass = ShowCodeSurroundingsCommand(ctx) == null; } catch (Exception e) { LoggingService.LogError("Error while update show code surroundings window", e); info.Bypass = true; } } }
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; } }
public virtual void RunParameterCompletionCommand() { if (Document.Editor.SelectionMode == Mono.TextEditor.SelectionMode.Block || CompletionWidget == null) { return; } ParameterDataProvider cp = null; int cpos; if (!GetParameterCompletionCommandOffset(out cpos)) { cpos = Editor.Caret.Offset; } CodeCompletionContext ctx = CompletionWidget.CreateCodeCompletionContext(cpos); cp = ParameterCompletionCommand(ctx); if (cp != null) { ParameterInformationWindowManager.ShowWindow(this, CompletionWidget, ctx, cp); ParameterInformationWindowManager.PostProcessKeyEvent(this, CompletionWidget, Gdk.Key.F, Gdk.ModifierType.None); } }
internal void OnUpdateShowCodeTemplatesWindow(CommandInfo info) { info.Enabled = !Editor.IsSomethingSelected; info.Bypass = !IsActiveExtension() || !info.Enabled; if (info.Enabled) { int cpos, wlen; if (!GetCompletionCommandOffset(out cpos, out wlen)) { cpos = Editor.CaretOffset; wlen = 0; } try { var ctx = CompletionWidget.CreateCodeCompletionContext(cpos); ctx.TriggerWordLength = wlen; info.Bypass = ShowCodeTemplatesCommand(ctx) == null; } catch (Exception e) { LoggingService.LogError("Error while update show code templates window", e); info.Bypass = true; } } }
async void ImportSymbolCommand() { if (Editor.SelectionMode == SelectionMode.Block) { return; } var analysisDocument = DocumentContext.AnalysisDocument; if (analysisDocument == null) { return; } var offset = Editor.CaretOffset; int cpos, wlen; if (!GetCompletionCommandOffset(out cpos, out wlen)) { cpos = Editor.CaretOffset; wlen = 0; } CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext(cpos); CurrentCompletionContext.TriggerWordLength = wlen; int triggerWordLength = 0; char ch = CurrentCompletionContext.TriggerOffset > 0 ? Editor.GetCharAt(CurrentCompletionContext.TriggerOffset - 1) : '\0'; var completionList = await InternalHandleCodeCompletion(CurrentCompletionContext, new CompletionTriggerInfo (CompletionTriggerReason.CompletionCommand, ch), triggerWordLength, default(CancellationToken), true); if (completionList != null) { CompletionWindowManager.ShowWindow(this, (char)0, completionList, CompletionWidget, CurrentCompletionContext); } else { CurrentCompletionContext = null; } }
// 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(KeyDescriptor descriptor) { if (!IsActiveExtension()) { return(base.KeyPress(descriptor)); } bool res; if (CurrentCompletionContext != null) { if (CompletionWindowManager.PreProcessKeyEvent(descriptor)) { CompletionWindowManager.PostProcessKeyEvent(descriptor); autoHideCompletionWindow = true; // in named parameter case leave the parameter window open. autoHideParameterWindow = descriptor.KeyChar != ':'; if (!autoHideParameterWindow && ParameterInformationWindowManager.IsWindowVisible) { ParameterInformationWindowManager.PostProcessKeyEvent(this, CompletionWidget, descriptor); } return(false); } autoHideCompletionWindow = autoHideParameterWindow = false; } if (ParameterInformationWindowManager.IsWindowVisible) { if (ParameterInformationWindowManager.ProcessKeyEvent(this, CompletionWidget, descriptor)) { return(false); } autoHideCompletionWindow = autoHideParameterWindow = false; } // int oldPos = Editor.CursorPosition; // int oldLen = Editor.TextLength; char deleteOrBackspaceTriggerChar = '\0'; if (descriptor.SpecialKey == SpecialKey.Delete && Editor.CaretOffset < Editor.Length) { deleteOrBackspaceTriggerChar = Editor.GetCharAt(Editor.CaretOffset); } if (descriptor.SpecialKey == SpecialKey.BackSpace && Editor.CaretOffset > 0) { deleteOrBackspaceTriggerChar = Editor.GetCharAt(Editor.CaretOffset - 1); } res = base.KeyPress(descriptor); if (Editor.EditMode == EditMode.TextLink && Editor.TextLinkPurpose == TextLinkPurpose.Rename) { return(res); } if (descriptor.KeyChar == (char)16 || descriptor.KeyChar == (char)17) { return(res); } CompletionWindowManager.PostProcessKeyEvent(descriptor); var ignoreMods = ModifierKeys.Control | ModifierKeys.Alt | ModifierKeys.Command; // Handle parameter completion if (ParameterInformationWindowManager.IsWindowVisible) { ParameterInformationWindowManager.PostProcessKeyEvent(this, CompletionWidget, descriptor); } if ((descriptor.ModifierKeys & ignoreMods) != 0) { return(res); } // don't complete on block selection if (/*!EnableCodeCompletion ||*/ Editor.SelectionMode == MonoDevelop.Ide.Editor.SelectionMode.Block) { return(res); } // Handle code completion if (descriptor.KeyChar != '\0' && CompletionWidget != null && !CompletionWindowManager.IsVisible) { completionTokenSrc.Cancel(); CurrentCompletionContext = CompletionWidget.CurrentCodeCompletionContext; completionTokenSrc = new CancellationTokenSource(); var caretOffset = Editor.CaretOffset; var token = completionTokenSrc.Token; try { var task = HandleCodeCompletionAsync(CurrentCompletionContext, new CompletionTriggerInfo(CompletionTriggerReason.CharTyped, descriptor.KeyChar), token); if (task != null) { // Show the completion window in two steps. The call to PrepareShowWindow creates the window but // it doesn't show it. It is used only to process the keys while the completion data is being retrieved. CompletionWindowManager.PrepareShowWindow(this, descriptor.KeyChar, CompletionWidget, CurrentCompletionContext); EventHandler windowClosed = delegate(object o, EventArgs a) { completionTokenSrc.Cancel(); }; CompletionWindowManager.WindowClosed += windowClosed; task.ContinueWith(t => { CompletionWindowManager.WindowClosed -= windowClosed; if (token.IsCancellationRequested) { return; } var result = t.Result; if (result != null) { int triggerWordLength = result.TriggerWordLength + (Editor.CaretOffset - caretOffset); if (triggerWordLength > 0 && (triggerWordLength < Editor.CaretOffset || (triggerWordLength == 1 && Editor.CaretOffset == 1))) { CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext(Editor.CaretOffset - triggerWordLength); if (result.TriggerWordStart >= 0) { CurrentCompletionContext.TriggerOffset = result.TriggerWordStart; } CurrentCompletionContext.TriggerWordLength = triggerWordLength; } // Now show the window for real. if (!CompletionWindowManager.ShowWindow(result, CurrentCompletionContext)) { CurrentCompletionContext = null; } } else { CompletionWindowManager.HideWindow(); CurrentCompletionContext = null; } }, Runtime.MainTaskScheduler); } else { CurrentCompletionContext = null; } } catch (TaskCanceledException) { } catch (AggregateException) { } } if ((descriptor.SpecialKey == SpecialKey.Delete || descriptor.SpecialKey == SpecialKey.BackSpace) && CompletionWidget != null && !CompletionWindowManager.IsVisible) { if (!char.IsLetterOrDigit(deleteOrBackspaceTriggerChar) && deleteOrBackspaceTriggerChar != '_') { return(res); } CurrentCompletionContext = CompletionWidget.CurrentCodeCompletionContext; int cpos, wlen; if (!GetCompletionCommandOffset(out cpos, out wlen)) { cpos = Editor.CaretOffset; wlen = 0; } CurrentCompletionContext.TriggerOffset = cpos; CurrentCompletionContext.TriggerWordLength = wlen; completionTokenSrc.Cancel(); completionTokenSrc = new CancellationTokenSource(); var caretOffset = Editor.CaretOffset; var token = completionTokenSrc.Token; try { var task = HandleCodeCompletionAsync(CurrentCompletionContext, new CompletionTriggerInfo(CompletionTriggerReason.BackspaceOrDeleteCommand, deleteOrBackspaceTriggerChar), token); if (task != null) { // Show the completion window in two steps. The call to PrepareShowWindow creates the window but // it doesn't show it. It is used only to process the keys while the completion data is being retrieved. CompletionWindowManager.PrepareShowWindow(this, descriptor.KeyChar, CompletionWidget, CurrentCompletionContext); EventHandler windowClosed = delegate(object o, EventArgs a) { completionTokenSrc.Cancel(); }; CompletionWindowManager.WindowClosed += windowClosed; task.ContinueWith(t => { CompletionWindowManager.WindowClosed -= windowClosed; if (token.IsCancellationRequested) { return; } var result = t.Result; if (result != null) { int triggerWordLength = result.TriggerWordLength + (Editor.CaretOffset - caretOffset); if (triggerWordLength > 0 && (triggerWordLength < Editor.CaretOffset || (triggerWordLength == 1 && Editor.CaretOffset == 1))) { CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext(Editor.CaretOffset - triggerWordLength); if (result.TriggerWordStart >= 0) { CurrentCompletionContext.TriggerOffset = result.TriggerWordStart; } CurrentCompletionContext.TriggerWordLength = triggerWordLength; } // Now show the window for real. if (!CompletionWindowManager.ShowWindow(result, CurrentCompletionContext)) { CurrentCompletionContext = null; } else { CompletionWindowManager.Wnd.StartOffset = CurrentCompletionContext.TriggerOffset; } } else { CompletionWindowManager.HideWindow(); CurrentCompletionContext = null; } }, Runtime.MainTaskScheduler); } else { CurrentCompletionContext = null; } } catch (TaskCanceledException) { CurrentCompletionContext = null; } catch (AggregateException) { CurrentCompletionContext = null; } } if (CompletionWidget != null) { CodeCompletionContext ctx = CompletionWidget.CurrentCodeCompletionContext; var newparameterHintingSrc = new CancellationTokenSource(); var token = newparameterHintingSrc.Token; try { var task = HandleParameterCompletionAsync(ctx, descriptor.KeyChar, token); if (task != null) { parameterHintingSrc.Cancel(); parameterHintingSrc = newparameterHintingSrc; parameterHingtingCursorPositionChanged = false; task.ContinueWith(t => { if (!token.IsCancellationRequested && t.Result != null) { ParameterInformationWindowManager.ShowWindow(this, CompletionWidget, ctx, t.Result); if (parameterHingtingCursorPositionChanged) { ParameterInformationWindowManager.UpdateCursorPosition(this, CompletionWidget); } } }, token, TaskContinuationOptions.None, Runtime.MainTaskScheduler); } else { //Key was typed that was filtered out, no heavy processing will be performed(task==null) //but we still want to update ParameterInfo window to avoid displaying it outside method call parameterHingtingCursorPositionChanged = true; } } catch (TaskCanceledException) { } catch (AggregateException) { } } return(res); }
// 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; // in named parameter case leave the parameter window open. autoHideParameterWindow = keyChar != ':'; if (!autoHideParameterWindow && ParameterInformationWindowManager.IsWindowVisible) { ParameterInformationWindowManager.PostProcessKeyEvent(this, CompletionWidget, key, modifier); } return(false); } autoHideCompletionWindow = autoHideParameterWindow = false; } if (ParameterInformationWindowManager.IsWindowVisible) { if (ParameterInformationWindowManager.ProcessKeyEvent(this, CompletionWidget, key, modifier)) { return(false); } autoHideCompletionWindow = autoHideParameterWindow = 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 && !CompletionWindowManager.IsVisible) { 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; var paramProvider = HandleParameterCompletion(ctx, keyChar); if (paramProvider != null) { ParameterInformationWindowManager.ShowWindow(this, CompletionWidget, ctx, paramProvider); } } /* autoHideCompletionWindow = true; * autoHideParameterWindow = keyChar != ':';*/ return(res); }
int GetCurrentParameterIndex(int startOffset) { int cursor = CompletionWidget.CurrentCodeCompletionContext.TriggerOffset; int i = startOffset; if (i < 0 || i >= Editor.Length) { return(-1); } if (i > cursor) { return(-1); } else if (i == cursor) { return(0); } // step over to the opening parenthesis at function call // if this fails, that means the paranthesis has been removed after invoking parameter hinting // and its safe to return -1 (and destroy the PH widget) try { while (Editor.GetCharAt(i) != '(') { i++; } } catch { return(-1); } int parameterIndex = 1; int inTemplateSpecifier = 0; int inCurvyBracket = 0; int inParentesis = 0; int inBracket = 0; while (i++ < cursor) { if (i >= CompletionWidget.TextLength) { break; } char ch = CompletionWidget.GetChar(i); switch (ch) { case '<': ++inTemplateSpecifier; break; case '>': --inTemplateSpecifier; break; case '(': ++inParentesis; break; case ')': --inParentesis; if (inParentesis == 0) { return(-1); } break; case '[': ++inBracket; break; case ']': --inBracket; break; case '{': ++inCurvyBracket; break; case '}': --inCurvyBracket; break; case ',': if (inTemplateSpecifier == 0 && inParentesis == 0 && inBracket == 0 && inCurvyBracket == 0) { parameterIndex++; } break; } } return(parameterIndex); }
public override bool KeyPress(Gdk.Key key, char keyChar, Gdk.ModifierType modifier) { var buffer = EditableBuffer; if (CompletionWindowManager.IsVisible) { // do some things to minimize keystrokes with code completion if (keyChar == '=') { // we're in an attribute completion, so automatically add the quote and show completions (if available) var ret = base.KeyPress(key, keyChar, modifier); if (!ret) { base.KeyPress((Gdk.Key) 0, '"', Gdk.ModifierType.None); buffer.InsertText(buffer.CursorPosition, "\""); buffer.CursorPosition--; } return(ret); } if (key == Gdk.Key.Return && modifier == Gdk.ModifierType.None && isParameterValueCompletion) { // finish completion base.KeyPress(key, keyChar, modifier); // if double quote already exists, skip it! if (buffer.GetCharAt(buffer.CursorPosition) == '"') { buffer.CursorPosition++; return(false); } // no double quote yet, so add it return(base.KeyPress((Gdk.Key) 0, '"', Gdk.ModifierType.None)); } if (keyChar == '"' || keyChar == '\'') { // finish completion with double quote base.KeyPress(Gdk.Key.Return, '\0', Gdk.ModifierType.None); // if double quote already exists, skip it! if (buffer.GetCharAt(buffer.CursorPosition) == keyChar) { buffer.CursorPosition++; return(false); } return(base.KeyPress(key, keyChar, modifier)); } } if (keyChar == '>') { // finish completion first if (CompletionWindowManager.IsVisible) { base.KeyPress(Gdk.Key.Return, '\0', Gdk.ModifierType.None); } // add self-closing tag if there is no content for the control if (!HasContentAtCurrentElement()) { base.KeyPress((Gdk.Key) 0, '/', Gdk.ModifierType.None); //buffer.InsertText(buffer.CursorPosition++, "/"); return(base.KeyPress(key, keyChar, modifier)); } } if (keyChar == '"' || keyChar == '\'') { // if double quote already exists, skip it! if (buffer.GetCharAt(buffer.CursorPosition) == keyChar) { buffer.CursorPosition++; return(false); } } if (keyChar == '.') { var result = base.KeyPress(key, keyChar, modifier); // provide completions for <Control.Property> elements var completionContext = CompletionWidget.CurrentCodeCompletionContext; var offset = completionContext.TriggerOffset - 1; var ch = CompletionWidget.GetChar(offset); while (ch != '\0' && (XmlConvert.IsNCNameChar(ch) || ch == ':') && offset > 0) { offset--; ch = CompletionWidget.GetChar(offset); } if (ch != '\0' && ch != '<') { return(result); } offset++; var len = completionContext.TriggerOffset - offset; var name = Editor.GetTextAt(offset, len); try { XmlConvert.VerifyName(name); } catch (XmlException) { // not a valid xml name return(result); } var xobject = Tracker.Engine.Nodes.Peek(1) as IAttributedXObject; if (xobject == null) { string prefix = null; var nsidx = name.IndexOf(':'); if (nsidx > 0) { prefix = name.Substring(0, nsidx); name = name.Substring(nsidx + 1); } name = name.TrimEnd('.'); xobject = new XElement(Tracker.Engine.Location, new XName(prefix, name)); } var attributeDictionary = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); if (xobject.Attributes != null) { foreach (XAttribute current in xobject.Attributes) { attributeDictionary[current.Name.FullName] = current.Value ?? string.Empty; } } var completions = GetAttributeCompletions(xobject, attributeDictionary, XmlCompletionData.DataType.XmlElement, true); if (completions != null) { ShowCompletion(completions); return(false); } } return(base.KeyPress(key, keyChar, modifier)); }
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); }
// 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(KeyDescriptor descriptor) { bool res; if (CurrentCompletionContext != null) { if (CompletionWindowManager.PreProcessKeyEvent(descriptor)) { CompletionWindowManager.PostProcessKeyEvent(descriptor); autoHideCompletionWindow = true; // in named parameter case leave the parameter window open. autoHideParameterWindow = descriptor.KeyChar != ':'; if (!autoHideParameterWindow && ParameterInformationWindowManager.IsWindowVisible) { ParameterInformationWindowManager.PostProcessKeyEvent(this, CompletionWidget, descriptor); } return(false); } autoHideCompletionWindow = autoHideParameterWindow = false; } if (ParameterInformationWindowManager.IsWindowVisible) { if (ParameterInformationWindowManager.ProcessKeyEvent(this, CompletionWidget, descriptor)) { return(false); } autoHideCompletionWindow = autoHideParameterWindow = false; } // int oldPos = Editor.CursorPosition; // int oldLen = Editor.TextLength; char deleteOrBackspaceTriggerChar = '\0'; if (descriptor.SpecialKey == SpecialKey.Delete && Editor.CaretOffset < Editor.Length) { deleteOrBackspaceTriggerChar = Editor.GetCharAt(Editor.CaretOffset); } if (descriptor.SpecialKey == SpecialKey.BackSpace && Editor.CaretOffset > 0) { deleteOrBackspaceTriggerChar = Editor.GetCharAt(Editor.CaretOffset - 1); } res = base.KeyPress(descriptor); CompletionWindowManager.PostProcessKeyEvent(descriptor); var ignoreMods = ModifierKeys.Control | ModifierKeys.Alt | ModifierKeys.Command; // Handle parameter completion if (ParameterInformationWindowManager.IsWindowVisible) { ParameterInformationWindowManager.PostProcessKeyEvent(this, CompletionWidget, descriptor); } if ((descriptor.ModifierKeys & ignoreMods) != 0) { return(res); } // don't complete on block selection if (/*!EnableCodeCompletion ||*/ Editor.SelectionMode == MonoDevelop.Ide.Editor.SelectionMode.Block) { return(res); } // Handle code completion if (descriptor.KeyChar != '\0' && CompletionWidget != null && !CompletionWindowManager.IsVisible) { CurrentCompletionContext = CompletionWidget.CurrentCodeCompletionContext; completionTokenSrc.Cancel(); completionTokenSrc = new CancellationTokenSource(); var caretOffset = Editor.CaretOffset; var token = completionTokenSrc.Token; try { var task = HandleCodeCompletionAsync(CurrentCompletionContext, descriptor.KeyChar, token); if (task != null) { // Show the completion window in two steps. The call to PrepareShowWindow creates the window but // it doesn't show it. It is used only to process the keys while the completion data is being retrieved. CompletionWindowManager.PrepareShowWindow(this, descriptor.KeyChar, CompletionWidget, CurrentCompletionContext); EventHandler windowClosed = delegate(object o, EventArgs a) { completionTokenSrc.Cancel(); }; CompletionWindowManager.WindowClosed += windowClosed; task.ContinueWith(t => { CompletionWindowManager.WindowClosed -= windowClosed; if (token.IsCancellationRequested) { return; } var result = t.Result; if (result != null) { int triggerWordLength = result.TriggerWordLength + (Editor.CaretOffset - caretOffset); if (triggerWordLength > 0 && (triggerWordLength < Editor.CaretOffset || (triggerWordLength == 1 && Editor.CaretOffset == 1))) { CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext(Editor.CaretOffset - triggerWordLength); CurrentCompletionContext.TriggerWordLength = triggerWordLength; } // Now show the window for real. if (!CompletionWindowManager.ShowWindow(result, CurrentCompletionContext)) { CurrentCompletionContext = null; } } else { CompletionWindowManager.HideWindow(); CurrentCompletionContext = null; } }, Runtime.MainTaskScheduler); } else { CurrentCompletionContext = null; } } catch (TaskCanceledException) { CurrentCompletionContext = null; } catch (AggregateException) { CurrentCompletionContext = null; } } if ((descriptor.SpecialKey == SpecialKey.Delete || descriptor.SpecialKey == SpecialKey.BackSpace) && CompletionWidget != null && !CompletionWindowManager.IsVisible) { CurrentCompletionContext = CompletionWidget.CurrentCodeCompletionContext; int cpos, wlen; if (!GetCompletionCommandOffset(out cpos, out wlen)) { cpos = Editor.CaretOffset; wlen = 0; } CurrentCompletionContext.TriggerOffset = cpos; CurrentCompletionContext.TriggerWordLength = wlen; completionTokenSrc.Cancel(); completionTokenSrc = new CancellationTokenSource(); var caretOffset = Editor.CaretOffset; var token = completionTokenSrc.Token; try { var task = HandleBackspaceOrDeleteCodeCompletionAsync(CurrentCompletionContext, descriptor.SpecialKey, deleteOrBackspaceTriggerChar, token); if (task != null) { // Show the completion window in two steps. The call to PrepareShowWindow creates the window but // it doesn't show it. It is used only to process the keys while the completion data is being retrieved. CompletionWindowManager.PrepareShowWindow(this, descriptor.KeyChar, CompletionWidget, CurrentCompletionContext); EventHandler windowClosed = delegate(object o, EventArgs a) { completionTokenSrc.Cancel(); }; CompletionWindowManager.WindowClosed += windowClosed; task.ContinueWith(t => { CompletionWindowManager.WindowClosed -= windowClosed; if (token.IsCancellationRequested) { return; } var result = t.Result; if (result != null) { int triggerWordLength = result.TriggerWordLength + (Editor.CaretOffset - caretOffset); if (triggerWordLength > 0 && (triggerWordLength < Editor.CaretOffset || (triggerWordLength == 1 && Editor.CaretOffset == 1))) { CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext(Editor.CaretOffset - triggerWordLength); CurrentCompletionContext.TriggerWordLength = triggerWordLength; } // Now show the window for real. if (!CompletionWindowManager.ShowWindow(result, CurrentCompletionContext)) { CurrentCompletionContext = null; } else { CompletionWindowManager.Wnd.StartOffset = CurrentCompletionContext.TriggerOffset; CompletionWindowManager.Wnd.EndOffset = Editor.CaretOffset; } } else { CompletionWindowManager.HideWindow(); CurrentCompletionContext = null; } }, Runtime.MainTaskScheduler); } else { CurrentCompletionContext = null; } } catch (TaskCanceledException) { CurrentCompletionContext = null; } catch (AggregateException) { CurrentCompletionContext = null; } } if (CompletionWidget != null) { CodeCompletionContext ctx = CompletionWidget.CurrentCodeCompletionContext; parameterHintingSrc.Cancel(); parameterHintingSrc = new CancellationTokenSource(); var token = parameterHintingSrc.Token; try { var task = HandleParameterCompletionAsync(ctx, descriptor.KeyChar, token); if (task != null) { task.ContinueWith(t => { if (!token.IsCancellationRequested && t.Result != null) { ParameterInformationWindowManager.ShowWindow(this, CompletionWidget, ctx, t.Result); } }, Runtime.MainTaskScheduler); } } catch (TaskCanceledException) { } catch (AggregateException) { } } /* autoHideCompletionWindow = true; * autoHideParameterWindow = keyChar != ':';*/ return(res); }