Browse Source

The method insight window can be invoked by pressing the "Control|Shift|Space" combination.

Cherry-picked from pull request #728
pull/730/head
nik 10 years ago committed by Matt Ward
parent
commit
6ce54b8031
  1. 5
      src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpCompletionBinding.cs
  2. 64
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionBinding.cs
  3. 5
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCodeCompletionBinding.cs
  4. 20
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs
  5. 6
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomCommands.cs
  6. 5
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlCodeCompletionBinding.cs
  7. 14
      src/Main/Base/Project/Editor/CodeCompletion/CodeCompletionBinding.cs

5
src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpCompletionBinding.cs

@ -48,6 +48,11 @@ namespace ICSharpCode.AspNet.Mvc.Completion
return false; return false;
} }
public bool CtrlShiftSpace(ITextEditor editor)
{
return false;
}
public CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch) public CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch)
{ {
// We use HandleKeyPressed instead. // We use HandleKeyPressed instead.

64
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionBinding.cs

@ -71,17 +71,13 @@ namespace CSharpBinding.Completion
return ShowCompletion(editor, '\0', true); return ShowCompletion(editor, '\0', true);
} }
bool ShowCompletion(ITextEditor editor, char completionChar, bool ctrlSpace) public bool CtrlShiftSpace(ITextEditor editor)
{ {
CSharpCompletionContext completionContext; return ShowInsight(editor);
if (fileContent == null) {
completionContext = CSharpCompletionContext.Get(editor);
} else {
completionContext = CSharpCompletionContext.Get(editor, context, currentLocation, fileContent);
} }
if (completionContext == null)
return false;
private int GetCaretOffset(ITextEditor editor, CSharpCompletionContext completionContext)
{
int caretOffset; int caretOffset;
if (fileContent == null) { if (fileContent == null) {
caretOffset = editor.Caret.Offset; caretOffset = editor.Caret.Offset;
@ -89,6 +85,27 @@ namespace CSharpBinding.Completion
} else { } else {
caretOffset = completionContext.Document.GetOffset(currentLocation); caretOffset = completionContext.Document.GetOffset(currentLocation);
} }
return caretOffset;
}
CSharpCompletionContext GetCompletionContext(ITextEditor editor)
{
CSharpCompletionContext completionContext;
if (fileContent == null) {
completionContext = CSharpCompletionContext.Get(editor);
} 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 = GetCaretOffset(editor, completionContext);
var completionFactory = new CSharpCompletionDataFactory(completionContext, new CSharpResolver(completionContext.TypeResolveContextAtCaret)); var completionFactory = new CSharpCompletionDataFactory(completionContext, new CSharpResolver(completionContext.TypeResolveContextAtCaret));
@ -139,7 +156,36 @@ namespace CSharpBinding.Completion
return true; 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 // Method Insight
var pce = new CSharpParameterCompletionEngine( var pce = new CSharpParameterCompletionEngine(
completionContext.Document, completionContext.Document,

5
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCodeCompletionBinding.cs

@ -244,6 +244,11 @@ namespace ICSharpCode.XamlBinding
return false; return false;
} }
public bool CtrlShiftSpace(ITextEditor editor)
{
return false;
}
void DoTriggerCompletion(XamlCompletionContext context, XamlCompletionItemList completionList) void DoTriggerCompletion(XamlCompletionContext context, XamlCompletionItemList completionList)
{ {
bool isExplicit; bool isExplicit;

20
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs

@ -229,6 +229,8 @@ namespace ICSharpCode.AvalonEdit.AddIn
codeEditorView.TextArea.SelectionChanged += TextAreaSelectionChanged; codeEditorView.TextArea.SelectionChanged += TextAreaSelectionChanged;
codeEditorView.TextArea.DefaultInputHandler.CommandBindings.Add( codeEditorView.TextArea.DefaultInputHandler.CommandBindings.Add(
new CommandBinding(CustomCommands.CtrlSpaceCompletion, OnCodeCompletion)); new CommandBinding(CustomCommands.CtrlSpaceCompletion, OnCodeCompletion));
codeEditorView.TextArea.DefaultInputHandler.CommandBindings.Add(
new CommandBinding(CustomCommands.CtrlShiftSpaceInsight, OnCodeInsight));
SearchPanel.Install(codeEditorView.TextArea); SearchPanel.Install(codeEditorView.TextArea);
textView.BackgroundRenderers.Add(textMarkerService); textView.BackgroundRenderers.Add(textMarkerService);
@ -619,6 +621,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() void FetchParseInformation()
{ {
ParseInformation parseInfo = SD.ParserService.GetCachedParseInformation(this.FileName); ParseInformation parseInfo = SD.ParserService.GetCachedParseInformation(this.FileName);

6
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomCommands.cs

@ -31,5 +31,11 @@ namespace ICSharpCode.AvalonEdit.AddIn
new InputGestureCollection { new InputGestureCollection {
new KeyGesture(Key.Space, ModifierKeys.Control) 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)
});
} }
} }

5
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlCodeCompletionBinding.cs

@ -99,6 +99,11 @@ namespace ICSharpCode.XmlEditor
return false; return false;
} }
public bool CtrlShiftSpace(ITextEditor editor)
{
return false;
}
bool ElementStartsWith(string text, int elementStartIndex, ITextSource document) bool ElementStartsWith(string text, int elementStartIndex, ITextSource document)
{ {
int textLength = Math.Min(text.Length, document.TextLength - elementStartIndex); int textLength = Math.Min(text.Length, document.TextLength - elementStartIndex);

14
src/Main/Base/Project/Editor/CodeCompletion/CodeCompletionBinding.cs

@ -51,6 +51,12 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
/// </summary> /// </summary>
/// <returns>Returns whether the completion binding has shown code completion.</returns> /// <returns>Returns whether the completion binding has shown code completion.</returns>
bool CtrlSpace(ITextEditor editor); bool CtrlSpace(ITextEditor editor);
/// <summary>
/// Invokes ctrl-shift-space code insight.
/// </summary>
/// <returns>Returns whether the completion binding has shown code insight.</returns>
bool CtrlShiftSpace(ITextEditor editor);
} }
/// <summary> /// <summary>
@ -165,5 +171,13 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
else else
return false; return false;
} }
public bool CtrlShiftSpace(ITextEditor editor)
{
if (MatchesExtension(editor))
return binding.CtrlShiftSpace(editor);
else
return false;
}
} }
} }

Loading…
Cancel
Save