public void Update(CSharpCodeCompletionContext completionContext) { var completionFactory = new CSharpCodeCompletionDataFactory(completionContext); var pce = new CSharpParameterCompletionEngine( completionContext.Document, completionContext.CompletionContextProvider, completionFactory, completionContext.ProjectContent, completionContext.TypeResolveContextAtCaret ); int parameterIndex = pce.GetCurrentParameterIndex(startOffset, completionContext.Offset); if (parameterIndex < 0 || !items.Any()) { RequestClose = true; return; } else { if (parameterIndex > items[selectedIndex].Method.Parameters.Count) { var newItem = items.FirstOrDefault(i => parameterIndex <= i.Method.Parameters.Count); SelectedIndex = items.IndexOf(newItem); } if (parameterIndex > 0) { parameterIndex--; // NR returns 1-based parameter index } foreach (var item in items) { item.HighlightParameter(parameterIndex); } } }
public void UpdateHighlightedParameter(CSharpParameterCompletionEngine pce) { int parameterIndex = pce.GetCurrentParameterIndex(window != null ? window.StartOffset : startOffset, editor.Caret.Offset); if (parameterIndex < 0 && window != null) { window.Close(); } else { if (window == null || parameterIndex > ((CSharpInsightItem)window.SelectedItem).Method.Parameters.Count) { var newItem = items.FirstOrDefault(i => parameterIndex <= i.Method.Parameters.Count); if (newItem != null) { if (window != null) { window.SelectedItem = newItem; } else { initiallySelectedItem = newItem; } } } if (parameterIndex > 0) { parameterIndex--; // NR returns 1-based parameter index } foreach (var item in items) { item.HighlightParameter(parameterIndex); } } }
static int GetIndex(string text) { var editorText = new StringBuilder(); int trigger = 0, end = 0; for (int i = 0; i < text.Length; i++) { if (text[i] == '@') { trigger = editorText.Length; continue; } if (text[i] == '$') { end = editorText.Length; continue; } editorText.Append(text [i]); } var doc = new ReadOnlyDocument(editorText.ToString()); var pctx = new CSharpProjectContent(); var rctx = new CSharpTypeResolveContext(pctx.CreateCompilation().MainAssembly); var ctxProvider = new DefaultCompletionContextProvider(doc, new CSharpUnresolvedFile()); var engine = new CSharpParameterCompletionEngine(doc, ctxProvider, new ParameterCompletionTests.TestFactory(pctx), pctx, rctx); return(engine.GetCurrentParameterIndex(trigger, end)); }
public override int GetCurrentParameterIndex(int startOffset) { var engine = new CSharpParameterCompletionEngine( TextEditorData.Document, typeSystemSegmentTree, this, Document.GetProjectContext(), CSharpUnresolvedFile.GetTypeResolveContext(Document.Compilation, document.Editor.Caret.Location) as CSharpTypeResolveContext ); return(engine.GetCurrentParameterIndex(startOffset, document.Editor.Caret.Offset)); }
public override int GuessBestMethodOverload(IParameterDataProvider provider, int currentOverload) { var engine = new CSharpParameterCompletionEngine( TextEditorData.Document, typeSystemSegmentTree, this, Document.GetProjectContext(), CSharpUnresolvedFile.GetTypeResolveContext(Document.Compilation, document.Editor.Caret.Location) as CSharpTypeResolveContext ); List <string> list; int cparam = engine.GetCurrentParameterIndex(provider.StartOffset, document.Editor.Caret.Offset, out list); if (cparam > provider.GetParameterCount(currentOverload) && !provider.AllowParameterList(currentOverload) || !HasAllUsedParameters(provider, list, currentOverload)) { // Look for an overload which has more parameters int bestOverload = -1; int bestParamCount = int.MaxValue; for (int n = 0; n < provider.Count; n++) { int pc = provider.GetParameterCount(n); if (pc < bestParamCount && pc >= cparam) { if (HasAllUsedParameters(provider, list, n)) { bestOverload = n; bestParamCount = pc; } } } if (bestOverload == -1) { for (int n = 0; n < provider.Count; n++) { if (provider.AllowParameterList(n) && HasAllUsedParameters(provider, list, n)) { bestOverload = n; break; } } } return(bestOverload); } return(-1); }