diff --git a/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpCompletionBinding.cs b/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpCompletionBinding.cs index 1ab287f0cb..38e75098ea 100644 --- a/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpCompletionBinding.cs +++ b/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpCompletionBinding.cs @@ -48,6 +48,11 @@ namespace ICSharpCode.AspNet.Mvc.Completion return false; } + public bool CtrlShiftSpace(ITextEditor editor) + { + return false; + } + public CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch) { // We use HandleKeyPressed instead. diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionBinding.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionBinding.cs index 69cba35ecd..560c97e755 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionBinding.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionBinding.cs @@ -70,8 +70,25 @@ namespace CSharpBinding.Completion { return ShowCompletion(editor, '\0', true); } - - bool ShowCompletion(ITextEditor editor, char completionChar, bool ctrlSpace) + + public bool CtrlShiftSpace(ITextEditor editor) + { + return ShowInsight(editor); + } + + private int GetCaretOffset(ITextEditor editor, CSharpCompletionContext completionContext) + { + int caretOffset; + if (fileContent == null) { + caretOffset = editor.Caret.Offset; + currentLocation = editor.Caret.Location; + } else { + caretOffset = completionContext.Document.GetOffset(currentLocation); + } + return caretOffset; + } + + CSharpCompletionContext GetCompletionContext(ITextEditor editor) { CSharpCompletionContext completionContext; if (fileContent == null) { @@ -79,17 +96,17 @@ namespace CSharpBinding.Completion } else { completionContext = CSharpCompletionContext.Get(editor, context, currentLocation, fileContent); } + return completionContext; + } + + bool ShowCompletion(ITextEditor editor, char completionChar, bool ctrlSpace) + { + var completionContext = GetCompletionContext(editor); if (completionContext == null) return false; - - int caretOffset; - if (fileContent == null) { - caretOffset = editor.Caret.Offset; - currentLocation = editor.Caret.Location; - } else { - caretOffset = completionContext.Document.GetOffset(currentLocation); - } - + + int caretOffset = GetCaretOffset(editor, completionContext); + var completionFactory = new CSharpCompletionDataFactory(completionContext, new CSharpResolver(completionContext.TypeResolveContextAtCaret)); CSharpCompletionEngine cce = new CSharpCompletionEngine( @@ -139,7 +156,36 @@ namespace CSharpBinding.Completion return true; } - if (CodeCompletionOptions.InsightEnabled && !ctrlSpace) { + if (!ctrlSpace) { + // Method Insight + // Method Insight + return ShowInsight(caretOffset, completionContext, completionFactory, completionChar); + } + return false; + } + + bool ShowInsight(ITextEditor editor) + { + var completionContext = GetCompletionContext(editor); + if (completionContext == null) + return false; + + int caretOffset = GetCaretOffset(editor, completionContext); + + var completionFactory = new CSharpCompletionDataFactory( + completionContext, + new CSharpResolver(completionContext.TypeResolveContextAtCaret)); + + return ShowInsight(caretOffset, completionContext, completionFactory, '('); + } + + bool ShowInsight( + int caretOffset, + CSharpCompletionContext completionContext, + CSharpCompletionDataFactory completionFactory, + char completionChar) + { + if (CodeCompletionOptions.InsightEnabled) { // Method Insight var pce = new CSharpParameterCompletionEngine( completionContext.Document, diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCodeCompletionBinding.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCodeCompletionBinding.cs index 29b182a409..2d8820b3e8 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCodeCompletionBinding.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCodeCompletionBinding.cs @@ -244,6 +244,11 @@ namespace ICSharpCode.XamlBinding return false; } + public bool CtrlShiftSpace(ITextEditor editor) + { + return false; + } + void DoTriggerCompletion(XamlCompletionContext context, XamlCompletionItemList completionList) { bool isExplicit; diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs index df011392f8..7d2faa25b9 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs @@ -229,6 +229,8 @@ namespace ICSharpCode.AvalonEdit.AddIn codeEditorView.TextArea.SelectionChanged += TextAreaSelectionChanged; codeEditorView.TextArea.DefaultInputHandler.CommandBindings.Add( new CommandBinding(CustomCommands.CtrlSpaceCompletion, OnCodeCompletion)); + codeEditorView.TextArea.DefaultInputHandler.CommandBindings.Add( + new CommandBinding(CustomCommands.CtrlShiftSpaceInsight, OnCodeInsight)); SearchPanel.Install(codeEditorView.TextArea); textView.BackgroundRenderers.Add(textMarkerService); @@ -618,6 +620,24 @@ namespace ICSharpCode.AvalonEdit.AddIn } } } + + void OnCodeInsight(object sender, ExecutedRoutedEventArgs e) + { + if (InsightWindow != null) + InsightWindow.Close(); + + // disable all code insight bindings when Insight is disabled + if (!CodeCompletionOptions.InsightEnabled) + return; + + CodeEditorView textEditor = GetTextEditorFromSender(sender); + foreach (ICodeCompletionBinding cc in CodeCompletionBindings) { + if (cc.CtrlShiftSpace(textEditor.Adapter)) { + e.Handled = true; + break; + } + } + } void FetchParseInformation() { diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomCommands.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomCommands.cs index 6fb562088f..31e1aa0af5 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomCommands.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomCommands.cs @@ -31,5 +31,11 @@ namespace ICSharpCode.AvalonEdit.AddIn new InputGestureCollection { new KeyGesture(Key.Space, ModifierKeys.Control) }); + + public static readonly RoutedCommand CtrlShiftSpaceInsight = new RoutedCommand( + "CtrlShiftSpaceInsight", typeof(CodeEditor), + new InputGestureCollection { + new KeyGesture(Key.Space, ModifierKeys.Control | ModifierKeys.Shift) + }); } } diff --git a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlCodeCompletionBinding.cs b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlCodeCompletionBinding.cs index 8dd5897fac..0f8af3a278 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlCodeCompletionBinding.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlCodeCompletionBinding.cs @@ -98,6 +98,11 @@ namespace ICSharpCode.XmlEditor } return false; } + + public bool CtrlShiftSpace(ITextEditor editor) + { + return false; + } bool ElementStartsWith(string text, int elementStartIndex, ITextSource document) { diff --git a/src/Main/Base/Project/Editor/CodeCompletion/CodeCompletionBinding.cs b/src/Main/Base/Project/Editor/CodeCompletion/CodeCompletionBinding.cs index 43d12c570f..087a80a9a6 100644 --- a/src/Main/Base/Project/Editor/CodeCompletion/CodeCompletionBinding.cs +++ b/src/Main/Base/Project/Editor/CodeCompletion/CodeCompletionBinding.cs @@ -51,6 +51,12 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion /// /// Returns whether the completion binding has shown code completion. bool CtrlSpace(ITextEditor editor); + + /// + /// Invokes ctrl-shift-space code insight. + /// + /// Returns whether the completion binding has shown code insight. + bool CtrlShiftSpace(ITextEditor editor); } /// @@ -165,5 +171,13 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion else return false; } + + public bool CtrlShiftSpace(ITextEditor editor) + { + if (MatchesExtension(editor)) + return binding.CtrlShiftSpace(editor); + else + return false; + } } }