Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 6ce54b8

Browse files
nikmrward
authored andcommitted
The method insight window can be invoked by pressing the "Control|Shift|Space" combination.
Cherry-picked from pull request #728
1 parent 1443fe0 commit 6ce54b8

File tree

7 files changed

+113
-12
lines changed

7 files changed

+113
-12
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ public bool CtrlSpace(ITextEditor editor)
4848
return false;
4949
}
5050

51+
public bool CtrlShiftSpace(ITextEditor editor)
52+
{
53+
return false;
54+
}
55+
5156
public CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch)
5257
{
5358
// We use HandleKeyPressed instead.

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

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,43 @@ public bool CtrlSpace(ITextEditor editor)
7070
{
7171
return ShowCompletion(editor, '\0', true);
7272
}
73-
74-
bool ShowCompletion(ITextEditor editor, char completionChar, bool ctrlSpace)
73+
74+
public bool CtrlShiftSpace(ITextEditor editor)
75+
{
76+
return ShowInsight(editor);
77+
}
78+
79+
private int GetCaretOffset(ITextEditor editor, CSharpCompletionContext completionContext)
80+
{
81+
int caretOffset;
82+
if (fileContent == null) {
83+
caretOffset = editor.Caret.Offset;
84+
currentLocation = editor.Caret.Location;
85+
} else {
86+
caretOffset = completionContext.Document.GetOffset(currentLocation);
87+
}
88+
return caretOffset;
89+
}
90+
91+
CSharpCompletionContext GetCompletionContext(ITextEditor editor)
7592
{
7693
CSharpCompletionContext completionContext;
7794
if (fileContent == null) {
7895
completionContext = CSharpCompletionContext.Get(editor);
7996
} else {
8097
completionContext = CSharpCompletionContext.Get(editor, context, currentLocation, fileContent);
8198
}
99+
return completionContext;
100+
}
101+
102+
bool ShowCompletion(ITextEditor editor, char completionChar, bool ctrlSpace)
103+
{
104+
var completionContext = GetCompletionContext(editor);
82105
if (completionContext == null)
83106
return false;
84-
85-
int caretOffset;
86-
if (fileContent == null) {
87-
caretOffset = editor.Caret.Offset;
88-
currentLocation = editor.Caret.Location;
89-
} else {
90-
caretOffset = completionContext.Document.GetOffset(currentLocation);
91-
}
92-
107+
108+
int caretOffset = GetCaretOffset(editor, completionContext);
109+
93110
var completionFactory = new CSharpCompletionDataFactory(completionContext, new CSharpResolver(completionContext.TypeResolveContextAtCaret));
94111

95112
CSharpCompletionEngine cce = new CSharpCompletionEngine(
@@ -139,7 +156,36 @@ bool ShowCompletion(ITextEditor editor, char completionChar, bool ctrlSpace)
139156
return true;
140157
}
141158

142-
if (CodeCompletionOptions.InsightEnabled && !ctrlSpace) {
159+
if (!ctrlSpace) {
160+
// Method Insight
161+
// Method Insight
162+
return ShowInsight(caretOffset, completionContext, completionFactory, completionChar);
163+
}
164+
return false;
165+
}
166+
167+
bool ShowInsight(ITextEditor editor)
168+
{
169+
var completionContext = GetCompletionContext(editor);
170+
if (completionContext == null)
171+
return false;
172+
173+
int caretOffset = GetCaretOffset(editor, completionContext);
174+
175+
var completionFactory = new CSharpCompletionDataFactory(
176+
completionContext,
177+
new CSharpResolver(completionContext.TypeResolveContextAtCaret));
178+
179+
return ShowInsight(caretOffset, completionContext, completionFactory, '(');
180+
}
181+
182+
bool ShowInsight(
183+
int caretOffset,
184+
CSharpCompletionContext completionContext,
185+
CSharpCompletionDataFactory completionFactory,
186+
char completionChar)
187+
{
188+
if (CodeCompletionOptions.InsightEnabled) {
143189
// Method Insight
144190
var pce = new CSharpParameterCompletionEngine(
145191
completionContext.Document,

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@ bool CtrlSpace(ITextEditor editor, XamlCompletionContext context)
244244
return false;
245245
}
246246

247+
public bool CtrlShiftSpace(ITextEditor editor)
248+
{
249+
return false;
250+
}
251+
247252
void DoTriggerCompletion(XamlCompletionContext context, XamlCompletionItemList completionList)
248253
{
249254
bool isExplicit;

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ protected virtual CodeEditorView CreateTextEditor()
229229
codeEditorView.TextArea.SelectionChanged += TextAreaSelectionChanged;
230230
codeEditorView.TextArea.DefaultInputHandler.CommandBindings.Add(
231231
new CommandBinding(CustomCommands.CtrlSpaceCompletion, OnCodeCompletion));
232+
codeEditorView.TextArea.DefaultInputHandler.CommandBindings.Add(
233+
new CommandBinding(CustomCommands.CtrlShiftSpaceInsight, OnCodeInsight));
232234
SearchPanel.Install(codeEditorView.TextArea);
233235

234236
textView.BackgroundRenderers.Add(textMarkerService);
@@ -618,6 +620,24 @@ void OnCodeCompletion(object sender, ExecutedRoutedEventArgs e)
618620
}
619621
}
620622
}
623+
624+
void OnCodeInsight(object sender, ExecutedRoutedEventArgs e)
625+
{
626+
if (InsightWindow != null)
627+
InsightWindow.Close();
628+
629+
// disable all code insight bindings when Insight is disabled
630+
if (!CodeCompletionOptions.InsightEnabled)
631+
return;
632+
633+
CodeEditorView textEditor = GetTextEditorFromSender(sender);
634+
foreach (ICodeCompletionBinding cc in CodeCompletionBindings) {
635+
if (cc.CtrlShiftSpace(textEditor.Adapter)) {
636+
e.Handled = true;
637+
break;
638+
}
639+
}
640+
}
621641

622642
void FetchParseInformation()
623643
{

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,11 @@ public static class CustomCommands
3131
new InputGestureCollection {
3232
new KeyGesture(Key.Space, ModifierKeys.Control)
3333
});
34+
35+
public static readonly RoutedCommand CtrlShiftSpaceInsight = new RoutedCommand(
36+
"CtrlShiftSpaceInsight", typeof(CodeEditor),
37+
new InputGestureCollection {
38+
new KeyGesture(Key.Space, ModifierKeys.Control | ModifierKeys.Shift)
39+
});
3440
}
3541
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ public bool CtrlSpace(ITextEditor editor)
9898
}
9999
return false;
100100
}
101+
102+
public bool CtrlShiftSpace(ITextEditor editor)
103+
{
104+
return false;
105+
}
101106

102107
bool ElementStartsWith(string text, int elementStartIndex, ITextSource document)
103108
{

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ public interface ICodeCompletionBinding
5151
/// </summary>
5252
/// <returns>Returns whether the completion binding has shown code completion.</returns>
5353
bool CtrlSpace(ITextEditor editor);
54+
55+
/// <summary>
56+
/// Invokes ctrl-shift-space code insight.
57+
/// </summary>
58+
/// <returns>Returns whether the completion binding has shown code insight.</returns>
59+
bool CtrlShiftSpace(ITextEditor editor);
5460
}
5561

5662
/// <summary>
@@ -165,5 +171,13 @@ public bool CtrlSpace(ITextEditor editor)
165171
else
166172
return false;
167173
}
174+
175+
public bool CtrlShiftSpace(ITextEditor editor)
176+
{
177+
if (MatchesExtension(editor))
178+
return binding.CtrlShiftSpace(editor);
179+
else
180+
return false;
181+
}
168182
}
169183
}

0 commit comments

Comments
 (0)