bool ShowInsight( int caretOffset, CSharpCompletionContext completionContext, CSharpCompletionDataFactory completionFactory, char completionChar) { if (CodeCompletionOptions.InsightEnabled) { // 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); }
void window_CaretPositionChanged(object sender, EventArgs e) { var completionContext = CSharpCompletionContext.Get(editor); if (completionContext == null) { window.Close(); return; } var completionFactory = new CSharpCompletionDataFactory(completionContext, new CSharpResolver(completionContext.TypeResolveContextAtCaret)); var pce = new CSharpParameterCompletionEngine( editor.Document, completionContext.CompletionContextProvider, completionFactory, completionContext.ProjectContent, completionContext.TypeResolveContextAtCaret ); UpdateHighlightedParameter(pce); }
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, '(')); }
void window_CaretPositionChanged(object sender, EventArgs e) { var completionContext = CSharpCompletionContext.Get(editor); if (completionContext == null) { window.Close(); return; } var completionFactory = new CSharpCompletionDataFactory(completionContext, new CSharpResolver(completionContext.TypeResolveContextAtCaret)); var pce = new CSharpParameterCompletionEngine( editor.Document, completionContext.CompletionContextProvider, completionFactory, completionContext.ProjectContent, completionContext.TypeResolveContextAtCaret ); UpdateHighlightedParameter(pce); }
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; }
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 (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 (!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); }
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; }
bool ShowInsight( int caretOffset, CSharpCompletionContext completionContext, CSharpCompletionDataFactory completionFactory, char completionChar) { if (CodeCompletionOptions.InsightEnabled) { // 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; }
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, '('); }