本文整理汇总了C#中ITextEditor.ShowCompletionWindow方法的典型用法代码示例。如果您正苦于以下问题:C# ITextEditor.ShowCompletionWindow方法的具体用法?C# ITextEditor.ShowCompletionWindow怎么用?C# ITextEditor.ShowCompletionWindow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITextEditor
的用法示例。
在下文中一共展示了ITextEditor.ShowCompletionWindow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryComplete
public Tuple<bool, CodeCompletionKeyPressResult> TryComplete(ITextEditor editor, char ch, IInsightWindowHandler insightWindowHandler)
{
int cursor_offset = editor.Caret.Offset;
if(ch == '['){
var list = CompletionDataHelper.GenerateCompletionList(SemanticInfo.Keys.ToList(),
SemanticInfo.Select(info => BVE5ResourceManager.GetDocumentationString(info.Value.Doc)).ToList(),
null);
editor.ShowCompletionWindow(list);
return Tuple.Create(true, CodeCompletionKeyPressResult.Completed);
}else if(char.IsLetter(ch)){
var caret_line_num = editor.Caret.Line;
var tree = parser.Parse(editor.Document.GetText(0, editor.Document.PositionToOffset(caret_line_num, 1)), "<string>", true);
var section_stmts = tree.FindNodes(node => node.Type == NodeType.SectionStmt).OfType<SectionStatement>(); //retrieve all section statements up to the current caret position
var context_stmt = section_stmts.LastOrDefault();
//if the context statement is null, it must be in a vehicle parameters file
var section_name = (context_stmt != null) ? context_stmt.SectionName.Name : "Global";
var section_semantic_info = SemanticInfo[section_name];
var list = CompletionDataHelper.GenerateCompletionList(section_semantic_info.Keys.Select(key => key.Name).ToList(),
section_semantic_info.Keys.Select(key => BVE5ResourceManager.GetDocumentationString(key.Doc)).ToList(),
null);
editor.ShowCompletionWindow(list);
return Tuple.Create(true, CodeCompletionKeyPressResult.CompletedIncludeKeyInCompletion);
}
return Tuple.Create(false, CodeCompletionKeyPressResult.None);
}
示例2: HandleKeyPress
public CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch)
{
if (ch == ':') {
if (editor.Caret.Offset >= 5 && editor.Document.GetText(editor.Caret.Offset-5, 5) == "${res") {
IResourceFileContent content = ICSharpCodeCoreResourceResolver.GetICSharpCodeCoreLocalResourceSet(editor.FileName).ResourceFileContent;
#if DEBUG
if (content != null) {
LoggingService.Debug("ResourceToolkit: Found local ICSharpCode.Core resource file: "+content.FileName);
}
#endif
IResourceFileContent hostContent = ICSharpCodeCoreResourceResolver.GetICSharpCodeCoreHostResourceSet(editor.FileName).ResourceFileContent;
if (hostContent != null) {
#if DEBUG
LoggingService.Debug("ResourceToolkit: Found host ICSharpCode.Core resource file: "+hostContent.FileName);
#endif
if (content != null) {
content = new MergedResourceFileContent(content, new IResourceFileContent[] { hostContent });
} else {
content = hostContent;
}
}
if (content != null) {
editor.ShowCompletionWindow(new ResourceCodeCompletionItemList(content, null, null));
return CodeCompletionKeyPressResult.Completed;
}
}
} else if (ch == '$') {
// Provide ${res: as code completion
// in an ICSharpCode.Core application
if (ICSharpCodeCoreResourceResolver.GetICSharpCodeCoreHostResourceSet(editor.FileName).ResourceFileContent != null ||
ICSharpCodeCoreResourceResolver.GetICSharpCodeCoreLocalResourceSet(editor.FileName).ResourceFileContent != null) {
editor.ShowCompletionWindow(new ICSharpCodeCoreTagCompletionItemList(editor));
return CodeCompletionKeyPressResult.Completed;
}
}
return CodeCompletionKeyPressResult.None;
}
示例3: ProvideContextCompletion
protected bool ProvideContextCompletion(ITextEditor editor, IReturnType expected, char charTyped)
{
if (expected == null) return false;
IClass c = expected.GetUnderlyingClass();
if (c == null) return false;
if (c.ClassType == ClassType.Enum) {
CtrlSpaceCompletionItemProvider cdp = new NRefactoryCtrlSpaceCompletionItemProvider(languageProperties);
var ctrlSpaceList = cdp.GenerateCompletionList(editor);
if (ctrlSpaceList == null) return false;
ContextCompletionItemList contextList = new ContextCompletionItemList();
contextList.Items.AddRange(ctrlSpaceList.Items);
contextList.activationKey = charTyped;
foreach (CodeCompletionItem item in contextList.Items.OfType<CodeCompletionItem>()) {
IClass itemClass = item.Entity as IClass;
if (itemClass != null && c.FullyQualifiedName == itemClass.FullyQualifiedName && c.TypeParameters.Count == itemClass.TypeParameters.Count) {
contextList.SuggestedItem = item;
break;
}
}
if (contextList.SuggestedItem != null) {
if (charTyped != ' ') contextList.InsertSpace = true;
editor.ShowCompletionWindow(contextList);
return true;
}
}
return false;
}
示例4: HandleKeyPress
public CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch)
{
if (this.CompletionPossible(editor, ch)) {
ResourceResolveResult result = ResourceResolverService.Resolve(editor, ch);
if (result != null) {
IResourceFileContent content;
if ((content = result.ResourceFileContent) != null) {
// If the resolved resource set is the local ICSharpCode.Core resource set
// (this may happen through the ICSharpCodeCoreNRefactoryResourceResolver),
// we will have to merge in the host resource set (if available)
// for the code completion window.
if (result.ResourceSetReference.ResourceSetName == ICSharpCodeCoreResourceResolver.ICSharpCodeCoreLocalResourceSetName) {
IResourceFileContent hostContent = ICSharpCodeCoreResourceResolver.GetICSharpCodeCoreHostResourceSet(editor.FileName).ResourceFileContent;
if (hostContent != null) {
content = new MergedResourceFileContent(content, new IResourceFileContent[] { hostContent });
}
}
editor.ShowCompletionWindow(new ResourceCodeCompletionItemList(content, this.OutputVisitor, result.CallingClass != null ? result.CallingClass.Name+"." : null));
return CodeCompletionKeyPressResult.Completed;
}
}
}
return CodeCompletionKeyPressResult.None;
}
示例5: CtrlSpace
public bool CtrlSpace(ITextEditor editor)
{
int elementStartIndex = XmlParser.GetActiveElementStartIndex(editor.Document.Text, editor.Caret.Offset);
if (elementStartIndex <= -1)
return false;
if (ElementStartsWith("<!", elementStartIndex, editor.Document))
return false;
if (ElementStartsWith("<?", elementStartIndex, editor.Document))
return false;
XmlSchemaCompletion defaultSchema = schemaFileAssociations.GetSchemaCompletion(editor.FileName);
XmlCompletionItemCollection completionItems = GetCompletionItems(editor, defaultSchema);
if (completionItems.HasItems) {
completionItems.Sort();
string identifier = XmlParser.GetXmlIdentifierBeforeIndex(editor.Document, editor.Caret.Offset);
completionItems.PreselectionLength = identifier.Length;
ICompletionListWindow completionWindow = editor.ShowCompletionWindow(completionItems);
if (completionWindow != null) {
SetCompletionWindowWidth(completionWindow, completionItems);
}
return true;
}
return false;
}
示例6: ShowCompletion
/// <summary>
/// Shows code completion for the specified editor.
/// </summary>
public virtual void ShowCompletion(ITextEditor editor)
{
if (editor == null)
throw new ArgumentNullException("editor");
ICompletionItemList itemList = GenerateCompletionList(editor);
if (itemList != null)
editor.ShowCompletionWindow(itemList);
}
示例7: ShowCompletion
public bool ShowCompletion(ITextEditor editor, bool memberCompletion)
{
this.memberCompletion = memberCompletion;
ICompletionItemList list = GenerateCompletionList(editor);
if (list.Items.Any()) {
editor.ShowCompletionWindow(list);
return true;
}
return false;
}
示例8: TryComplete
public Tuple<bool, CodeCompletionKeyPressResult> TryComplete(ITextEditor editor, char ch, IInsightWindowHandler insightWindowHandler)
{
int cursor_offset = editor.Caret.Offset;
if(ch == '['){
var line = editor.Document.GetLineForOffset(cursor_offset);
current_context_type = line.Text.Trim();
var provider = new UserDefinedNameCompletionItemProvider(current_context_type);
var list = provider.Provide(editor);
if(list != null){
editor.ShowCompletionWindow(list);
return Tuple.Create(true, CodeCompletionKeyPressResult.Completed);
}else{
return Tuple.Create(false, CodeCompletionKeyPressResult.None);
}
}else if(ch == ',' && CodeCompletionOptions.InsightRefreshOnComma && CodeCompletionOptions.InsightEnabled){
IInsightWindow insight_window;
if(insightWindowHandler.InsightRefreshOnComma(editor, ch, out insight_window))
return Tuple.Create(true, CodeCompletionKeyPressResult.Completed);
}else if(ch == '.'){
var line = editor.Document.GetLineForOffset(cursor_offset);
var type_name = (current_context_type != null) ? current_context_type : line.Text.Trim();
var semantic_infos = BVE5ResourceManager.RouteFileSemanticInfos;
var result = CodeCompletionKeyPressResult.None;
if(semantic_infos.ContainsKey(type_name)){
var type_semantic_info = semantic_infos[type_name];
var names = type_semantic_info
.Where(member => member.Key != "indexer")
.Select(m => m.Key)
.Distinct()
.ToList();
var descriptions = type_semantic_info
.Where(member => member.Key != "indexer")
.Select(m => BVE5ResourceManager.GetDocumentationString(m.Value[0].Doc))
.ToList();
var list = CompletionDataHelper.GenerateCompletionList(names, descriptions);
editor.ShowCompletionWindow(list);
result = CodeCompletionKeyPressResult.Completed;
}
if(current_context_type != null) current_context_type = null;
return Tuple.Create(result != CodeCompletionKeyPressResult.None, result);
}else if(ch == '(' && CodeCompletionOptions.InsightEnabled){
var insight_window = editor.ShowInsightWindow(ProvideInsight(editor));
if(insight_window != null && insightWindowHandler != null){
insightWindowHandler.InitializeOpenedInsightWindow(editor, insight_window);
insightWindowHandler.HighlightParameter(insight_window, 0);
}
return Tuple.Create(true, CodeCompletionKeyPressResult.Completed);
}
if(char.IsLetter(ch) && CodeCompletionOptions.CompleteWhenTyping){
var builtin_type_names = BVE5ResourceManager.GetAllTypeNames();
var list = CompletionDataHelper.GenerateCompletionList(builtin_type_names);
list = AddTemplateCompletionItems(editor, list, ch);
editor.ShowCompletionWindow(list);
return Tuple.Create(true, CodeCompletionKeyPressResult.CompletedIncludeKeyInCompletion);
}
return Tuple.Create(false, CodeCompletionKeyPressResult.None);
}
示例9: HandleKeyPress
public CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch)
{
compilation = SD.ParserService.GetCompilationForFile(editor.FileName);
resolver = new XamlResolver(compilation);
XamlCompletionContext context = XamlContextResolver.ResolveCompletionContext(editor, ch);
XamlCompletionItemList list;
if (context.Description == XamlContextDescription.InComment || context.Description == XamlContextDescription.InCData)
return CodeCompletionKeyPressResult.None;
switch (ch) {
case '<':
context.Description = (context.Description == XamlContextDescription.None) ? XamlContextDescription.AtTag : context.Description;
list = generator.CreateListForContext(context);
editor.ShowCompletionWindow(list);
return CodeCompletionKeyPressResult.Completed;
case '>':
return CodeCompletionKeyPressResult.None;
case '\'':
case '"':
if (!XmlParser.IsInsideAttributeValue(editor.Document.Text, editor.Caret.Offset)) {
// count all " or ' chars before the next > char
int search = editor.Caret.Offset + 1;
int endMarkerCount = 1;
char curCh = editor.Document.GetCharAt(search);
while (search < editor.Document.TextLength - 1 && curCh != '>') {
if (curCh == ch)
endMarkerCount++;
search++;
curCh = editor.Document.GetCharAt(search);
}
// if the count is odd we need to add an additional " or ' char
if (endMarkerCount % 2 != 0) {
editor.Document.Insert(editor.Caret.Offset, ch.ToString());
editor.Caret.Offset--;
CtrlSpace(editor);
return CodeCompletionKeyPressResult.Completed;
}
}
break;
case '{': // starting point for Markup Extension Completion
if (context.Attribute != null
&& XmlParser.IsInsideAttributeValue(editor.Document.Text, editor.Caret.Offset)
&& !(context.RawAttributeValue.StartsWith("{}", StringComparison.OrdinalIgnoreCase) && context.RawAttributeValue.Length != 2)) {
if (editor.SelectionLength != 0)
editor.Document.Remove(editor.SelectionStart, editor.SelectionLength);
editor.Document.Insert(editor.Caret.Offset, "{}");
editor.Caret.Offset--;
this.CtrlSpace(editor);
return CodeCompletionKeyPressResult.EatKey;
}
break;
case '.':
switch (context.Description) {
case XamlContextDescription.AtTag:
case XamlContextDescription.InTag:
if (context.ActiveElement != null) {
list = generator.CreateListForContext(context);
editor.ShowCompletionWindow(list);
return CodeCompletionKeyPressResult.Completed;
}
break;
case XamlContextDescription.InMarkupExtension:
if (DoMarkupExtensionCompletion(context))
return CodeCompletionKeyPressResult.Completed;
break;
case XamlContextDescription.InAttributeValue:
if (editor.SelectionLength != 0)
editor.Document.Remove(editor.SelectionStart, editor.SelectionLength);
editor.Document.Insert(editor.Caret.Offset, ".");
this.CtrlSpace(editor);
return CodeCompletionKeyPressResult.EatKey;
}
break;
case '(':
case '[':
if (context.Description == XamlContextDescription.InAttributeValue) {
if (editor.SelectionLength != 0)
editor.Document.Remove(editor.SelectionStart, editor.SelectionLength);
if (ch == '(')
editor.Document.Insert(editor.Caret.Offset, "()");
if (ch == '[')
editor.Document.Insert(editor.Caret.Offset, "[]");
editor.Caret.Offset--;
CtrlSpace(editor);
return CodeCompletionKeyPressResult.EatKey;
}
break;
case ':':
if (context.ActiveElement != null && XmlParser.GetQualifiedAttributeNameAtIndex(editor.Document.Text, editor.Caret.Offset) == null) {
if (context.Attribute != null && !context.Attribute.Name.StartsWith("xmlns", StringComparison.OrdinalIgnoreCase)) {
list = generator.CreateListForContext(context);
//.........这里部分代码省略.........
示例10: CtrlSpace
bool CtrlSpace(ITextEditor editor, XamlCompletionContext context)
{
if (context.Description == XamlContextDescription.InComment
|| context.Description == XamlContextDescription.InCData
|| context.ActiveElement == null) {
return false;
}
if (!context.InAttributeValueOrMarkupExtension) {
XamlCompletionItemList list = generator.CreateListForContext(context);
string starter = editor.GetWordBeforeCaretExtended().TrimStart('/');
if (context.Description != XamlContextDescription.None && !string.IsNullOrEmpty(starter)) {
if (starter.Contains(".")) {
list.PreselectionLength = starter.Length - starter.IndexOf('.') - 1;
} else {
list.PreselectionLength = starter.Length;
}
}
editor.ShowCompletionWindow(list);
return true;
}
// DO NOT USE generator.CreateListForContext here!!! results in endless recursion!!!!
if (context.Attribute != null) {
if (!DoMarkupExtensionCompletion(context)) {
var completionList = new XamlCompletionItemList(context);
completionList.PreselectionLength = editor.GetWordBeforeCaretExtended().Length;
if ((context.ActiveElement.Name == "Setter" || context.ActiveElement.Name == "EventSetter") && (context.Attribute.Name == "Property" || context.Attribute.Name == "Value")) {
DoSetterAndEventSetterCompletion(context, completionList);
editor.ShowCompletionWindow(completionList);
} else if ((context.ActiveElement.Name.EndsWith("Trigger", StringComparison.Ordinal) || context.ActiveElement.Name == "Condition") && context.Attribute.Name == "Value") {
DoTriggerCompletion(context, completionList);
editor.ShowCompletionWindow(completionList);
} else if (!DoAttributeCompletion(context, completionList)) {
DoXmlAttributeCompletion(context, completionList);
}
return completionList.Items.Any();
}
return true;
}
return false;
}
示例11: ShowCompletion
bool ShowCompletion(ITextEditor editor, char completionChar, bool ctrlSpace)
{
var completionContext = CSharpCompletionContext.Get(editor);
if (completionContext == null)
return false;
var completionFactory = new CSharpCompletionDataFactory(completionContext, new CSharpResolver(completionContext.TypeResolveContextAtCaret));
CSharpCompletionEngine cce = new CSharpCompletionEngine(
editor.Document,
completionContext.CompletionContextProvider,
completionFactory,
completionContext.ProjectContent,
completionContext.TypeResolveContextAtCaret
);
cce.FormattingPolicy = FormattingOptionsFactory.CreateSharpDevelop();
cce.EolMarker = DocumentUtilities.GetLineTerminator(editor.Document, editor.Caret.Line);
cce.IndentString = editor.Options.IndentationString;
int startPos, triggerWordLength;
IEnumerable<ICompletionData> completionData;
if (ctrlSpace) {
if (!cce.TryGetCompletionWord(editor.Caret.Offset, out startPos, out triggerWordLength)) {
startPos = editor.Caret.Offset;
triggerWordLength = 0;
}
completionData = cce.GetCompletionData(startPos, true);
completionData = completionData.Concat(cce.GetImportCompletionData(startPos));
} else {
startPos = editor.Caret.Offset;
if (char.IsLetterOrDigit (completionChar) || completionChar == '_') {
if (startPos > 1 && char.IsLetterOrDigit (editor.Document.GetCharAt (startPos - 2)))
return false;
completionData = cce.GetCompletionData(startPos, false);
startPos--;
triggerWordLength = 1;
} else {
completionData = cce.GetCompletionData(startPos, false);
triggerWordLength = 0;
}
}
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 == cce.DefaultCompletionString);
editor.ShowCompletionWindow(list);
return true;
}
if (!ctrlSpace) {
// Method Insight
var pce = new CSharpParameterCompletionEngine(
editor.Document,
completionContext.CompletionContextProvider,
completionFactory,
completionContext.ProjectContent,
completionContext.TypeResolveContextAtCaret
);
var newInsight = pce.GetParameterDataProvider(editor.Caret.Offset, completionChar) as CSharpMethodInsight;
if (newInsight != null && newInsight.items.Count > 0) {
newInsight.UpdateHighlightedParameter(pce);
newInsight.Show();
return true;
}
}
return false;
}
示例12: showCompletionWindow
void showCompletionWindow(ITextEditor editor)
{
removeDuplicates(ref l.items);
editor.ShowCompletionWindow(l);
}
示例13: CtrlSpace
public bool CtrlSpace(ITextEditor editor)
{
XamlCompletionContext context = CompletionDataHelper.ResolveCompletionContext(editor, ' ');
context.Forced = trackForced;
if (context.Description == XamlContextDescription.InComment || context.Description == XamlContextDescription.InCData)
return false;
if (context.ActiveElement != null) {
if (!XmlParser.IsInsideAttributeValue(editor.Document.Text, editor.Caret.Offset) && context.Description != XamlContextDescription.InAttributeValue) {
XamlCompletionItemList list = CompletionDataHelper.CreateListForContext(context);
string starter = editor.GetWordBeforeCaretExtended().TrimStart('/');
if (context.Description != XamlContextDescription.None && !string.IsNullOrEmpty(starter)) {
if (starter.Contains("."))
list.PreselectionLength = starter.Length - starter.IndexOf('.') - 1;
else
list.PreselectionLength = starter.Length;
}
editor.ShowCompletionWindow(list);
return true;
} else {
// DO NOT USE CompletionDataHelper.CreateListForContext here!!! results in endless recursion!!!!
if (context.Attribute != null) {
if (!DoMarkupExtensionCompletion(context)) {
var completionList = new XamlCompletionItemList(context);
completionList.PreselectionLength = editor.GetWordBeforeCaretExtended().Length;
if ((context.ActiveElement.Name == "Setter" || context.ActiveElement.Name == "EventSetter") &&
(context.Attribute.Name == "Property" || context.Attribute.Name == "Value"))
DoSetterAndEventSetterCompletion(context, completionList);
else if ((context.ActiveElement.Name.EndsWith("Trigger") || context.ActiveElement.Name == "Condition") && context.Attribute.Name == "Value")
DoTriggerCompletion(context, completionList);
else {
if (context.Attribute.Name == "xml:space") {
completionList.Items.AddRange(new[] { new SpecialCompletionItem("preserve"),
new SpecialCompletionItem("default") });
}
var mrr = XamlResolver.Resolve(context.Attribute.Name, context) as MemberResolveResult;
if (mrr != null && mrr.ResolvedType != null) {
completionList.Items.AddRange(CompletionDataHelper.MemberCompletion(context, mrr.ResolvedType, string.Empty));
editor.ShowInsightWindow(CompletionDataHelper.MemberInsight(mrr));
if (mrr.ResolvedType.FullyQualifiedName == "System.Windows.PropertyPath") {
string start = editor.GetWordBeforeCaretExtended();
int index = start.LastIndexOfAny(PropertyPathTokenizer.ControlChars);
if (index + 1 < start.Length)
start = start.Substring(index + 1);
else
start = "";
completionList.PreselectionLength = start.Length;
} else if (mrr.ResolvedType.FullyQualifiedName == "System.Windows.Media.FontFamily") {
string text = context.ValueStartOffset > -1 ? context.RawAttributeValue.Substring(0, Math.Min(context.ValueStartOffset + 1, context.RawAttributeValue.Length)) : "";
int lastComma = text.LastIndexOf(',');
completionList.PreselectionLength = lastComma == -1 ? context.ValueStartOffset + 1 : context.ValueStartOffset - lastComma;
}
}
}
completionList.SortItems();
if (context.Attribute.Prefix.Equals("xmlns", StringComparison.OrdinalIgnoreCase) ||
context.Attribute.Name.Equals("xmlns", StringComparison.OrdinalIgnoreCase))
completionList.Items.AddRange(CompletionDataHelper.CreateListForXmlnsCompletion(context.ProjectContent));
ICompletionListWindow window = editor.ShowCompletionWindow(completionList);
if ((context.Attribute.Prefix.Equals("xmlns", StringComparison.OrdinalIgnoreCase) ||
context.Attribute.Name.Equals("xmlns", StringComparison.OrdinalIgnoreCase)) && window != null)
window.Width = 400;
return completionList.Items.Any();
}
return true;
}
}
}
return false;
}
示例14: ShowCompletion
bool ShowCompletion(ITextEditor editor, char completionChar, bool ctrlSpace)
{
CSharpCompletionContext completionContext;
if (fileContent == null) {
completionContext = CSharpCompletionContext.Get(editor);
} else {
completionContext = CSharpCompletionContext.Get(editor, context, currentLocation, fileContent);
}
if (completionContext == null)
return false;
int caretOffset;
if (fileContent == null) {
caretOffset = editor.Caret.Offset;
currentLocation = editor.Caret.Location;
} else {
caretOffset = completionContext.Document.GetOffset(currentLocation);
}
var completionFactory = new CSharpCompletionDataFactory(completionContext, new CSharpResolver(completionContext.TypeResolveContextAtCaret));
CSharpCompletionEngine cce = new CSharpCompletionEngine(
completionContext.Document,
completionContext.CompletionContextProvider,
completionFactory,
completionContext.ProjectContent,
completionContext.TypeResolveContextAtCaret
);
var formattingOptions = CSharpFormattingPolicies.Instance.GetProjectOptions(completionContext.Compilation.GetProject());
cce.FormattingPolicy = formattingOptions.OptionsContainer.GetEffectiveOptions();
cce.EolMarker = DocumentUtilities.GetLineTerminator(completionContext.Document, currentLocation.Line);
cce.IndentString = editor.Options.IndentationString;
int startPos, triggerWordLength;
IEnumerable<ICompletionData> completionData;
if (ctrlSpace) {
if (!cce.TryGetCompletionWord(caretOffset, out startPos, out triggerWordLength)) {
startPos = caretOffset;
triggerWordLength = 0;
}
completionData = cce.GetCompletionData(startPos, true);
completionData = completionData.Concat(cce.GetImportCompletionData(startPos));
} else {
startPos = caretOffset;
if (char.IsLetterOrDigit (completionChar) || completionChar == '_') {
if (!CodeCompletionOptions.CompleteWhenTyping) return false;
if (startPos > 1 && char.IsLetterOrDigit (completionContext.Document.GetCharAt (startPos - 2)))
return false;
completionData = cce.GetCompletionData(startPos, false);
startPos--;
triggerWordLength = 1;
} else {
completionData = cce.GetCompletionData(startPos, false);
triggerWordLength = 0;
}
}
DefaultCompletionItemList list = new DefaultCompletionItemList();
list.Items.AddRange(FilterAndAddTemplates(editor, completionData.Cast<ICompletionItem>().ToList()));
if (list.Items.Count > 0 && (ctrlSpace || cce.AutoCompleteEmptyMatch)) {
list.SortItems();
list.PreselectionLength = caretOffset - startPos;
list.PostselectionLength = Math.Max(0, startPos + triggerWordLength - caretOffset);
list.SuggestedItem = list.Items.FirstOrDefault(i => i.Text == cce.DefaultCompletionString);
editor.ShowCompletionWindow(list);
return true;
}
if (CodeCompletionOptions.InsightEnabled && !ctrlSpace) {
// Method Insight
var pce = new CSharpParameterCompletionEngine(
completionContext.Document,
completionContext.CompletionContextProvider,
completionFactory,
completionContext.ProjectContent,
completionContext.TypeResolveContextAtCaret
);
var newInsight = pce.GetParameterDataProvider(caretOffset, completionChar) as CSharpMethodInsight;
if (newInsight != null && newInsight.items.Count > 0) {
newInsight.UpdateHighlightedParameter(pce);
newInsight.Show();
return true;
}
}
return false;
}
示例15: ShowCompletion
static void ShowCompletion(ExpressionResult result, ITextEditor editor, char ch)
{
VBNetCompletionItemList list = CompletionDataHelper.GenerateCompletionData(result, editor, ch);
list.Editor = editor;
list.Window = editor.ShowCompletionWindow(list);
}