|
|
|
|
@ -2,7 +2,9 @@
@@ -2,7 +2,9 @@
|
|
|
|
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
|
|
|
|
|
|
|
|
|
using System; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.Linq; |
|
|
|
|
|
|
|
|
|
using CSharpBinding.Parser; |
|
|
|
|
using ICSharpCode.NRefactory.Completion; |
|
|
|
|
using ICSharpCode.NRefactory.CSharp.Completion; |
|
|
|
|
@ -22,6 +24,18 @@ namespace CSharpBinding.Completion
@@ -22,6 +24,18 @@ namespace CSharpBinding.Completion
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public bool HandleKeyPressed(ITextEditor editor, char ch) |
|
|
|
|
{ |
|
|
|
|
if (editor.ActiveCompletionWindow != null) |
|
|
|
|
return false; |
|
|
|
|
return ShowCompletion(editor, ch, false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public bool CtrlSpace(ITextEditor editor) |
|
|
|
|
{ |
|
|
|
|
return ShowCompletion(editor, '\0', true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool ShowCompletion(ITextEditor editor, char completionChar, bool ctrlSpace) |
|
|
|
|
{ |
|
|
|
|
// Don't require the very latest parse information, an older cached version is OK.
|
|
|
|
|
var parseInfo = ParserService.GetCachedParseInformation(editor.FileName) as CSharpFullParseInformation; |
|
|
|
|
@ -43,30 +57,45 @@ namespace CSharpBinding.Completion
@@ -43,30 +57,45 @@ namespace CSharpBinding.Completion
|
|
|
|
|
parseInfo.CompilationUnit, |
|
|
|
|
parseInfo.ParsedFile |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
//cc.FormattingPolicy = ?
|
|
|
|
|
cc.EolMarker = DocumentUtilitites.GetLineTerminator(editor.Document, editor.Caret.Line); |
|
|
|
|
//cc.IndentString = ?
|
|
|
|
|
DefaultCompletionItemList list = new DefaultCompletionItemList(); |
|
|
|
|
|
|
|
|
|
if (char.IsLetterOrDigit (ch) || ch == '_') { |
|
|
|
|
//if (completionContext.TriggerOffset > 1 && char.IsLetterOrDigit (document.Editor.GetCharAt (completionContext.TriggerOffset - 2)))
|
|
|
|
|
// return null;
|
|
|
|
|
list.PreselectionLength = 1; |
|
|
|
|
int startPos, triggerWordLength; |
|
|
|
|
IEnumerable<ICompletionData> completionData; |
|
|
|
|
if (ctrlSpace) { |
|
|
|
|
if (!cc.TryGetCompletionWord(editor.Caret.Offset, out startPos, out triggerWordLength)) { |
|
|
|
|
startPos = editor.Caret.Offset; |
|
|
|
|
triggerWordLength = 0; |
|
|
|
|
} |
|
|
|
|
completionData = cc.GetCompletionData(startPos, true); |
|
|
|
|
} else { |
|
|
|
|
startPos = editor.Caret.Offset; |
|
|
|
|
if (char.IsLetterOrDigit (completionChar) || completionChar == '_') { |
|
|
|
|
if (startPos > 1 && char.IsLetterOrDigit (editor.Document.GetCharAt (startPos - 2))) |
|
|
|
|
return false; |
|
|
|
|
completionData = cc.GetCompletionData(startPos, false); |
|
|
|
|
startPos--; |
|
|
|
|
triggerWordLength = 1; |
|
|
|
|
} else { |
|
|
|
|
completionData = cc.GetCompletionData(startPos, false); |
|
|
|
|
triggerWordLength = 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
list.Items.AddRange(cc.GetCompletionData(editor.Caret.Offset, false).Cast<ICompletionItem>()); |
|
|
|
|
|
|
|
|
|
DefaultCompletionItemList list = new DefaultCompletionItemList(); |
|
|
|
|
list.Items.AddRange(completionData.Cast<ICompletionItem>()); |
|
|
|
|
if (list.Items.Count > 0) { |
|
|
|
|
list.SortItems(); |
|
|
|
|
list.PreselectionLength = editor.Caret.Offset - startPos; |
|
|
|
|
list.PostselectionLength = Math.Max(0, startPos + triggerWordLength - editor.Caret.Offset); |
|
|
|
|
list.SuggestedItem = list.Items.FirstOrDefault(i => i.Text == cc.DefaultCompletionString); |
|
|
|
|
editor.ShowCompletionWindow(list); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public bool CtrlSpace(ITextEditor editor) |
|
|
|
|
{ |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|