protected override async Task <CompletionDataList> GetAttributeValueCompletions(IAttributedXObject attributedOb, XAttribute att, CancellationToken token) { isParameterValueCompletion = true; var list = await base.GetAttributeValueCompletions(attributedOb, att, token); var currentPath = GetCurrentPath(); var path = GetPath(currentPath); var namespaces = GetNamespaces(currentPath); var objectName = attributedOb.Name.FullName; foreach (var completion in Completion.GetCompletions(namespaces)) { foreach (var item in completion.GetPropertyValues(objectName, att.Name.FullName, path)) { var xmlCompletion = new XmlCompletionData(item.Name, item.Description, XmlCompletionData.DataType.XmlAttributeValue); xmlCompletion.Icon = GetIcon(item.Type); list.Add(xmlCompletion); } } return(list); }
protected override async Task <CompletionDataList> GetElementCompletions(System.Threading.CancellationToken token) { var list = await base.GetElementCompletions(token); var currentPath = GetCurrentPath(); var path = GetPath(currentPath); var namespaces = GetNamespaces(currentPath); var completions = Completion.GetCompletions(namespaces).ToList(); var filter = completions.Select(r => r.GetFilter(path)).FirstOrDefault(r => r != null); foreach (var completion in completions) { foreach (var item in completion.GetClasses(path, filter)) { var xmlCompletion = new XmlCompletionData(item.Name, item.Description, XmlCompletionData.DataType.XmlElement); xmlCompletion.Icon = Stock.Class; list.Add(xmlCompletion); } } AddMiscBeginTags(list); return(list); }
CompletionDataList GetAttributeCompletions(IAttributedXObject attributedOb, Dictionary <string, string> existingAtts, XmlCompletionData.DataType type, bool elementNamespacesOnly) { var list = base.GetAttributeCompletions(attributedOb, existingAtts) ?? new CompletionDataList(); var currentPath = GetCurrentPath(); var path = GetPath(currentPath); var namespaces = GetNamespaces(currentPath); var objectName = attributedOb.Name.FullName; if (elementNamespacesOnly) { namespaces = namespaces.Where(r => (r.Prefix ?? string.Empty) == (attributedOb.Name.Prefix ?? string.Empty)).ToList(); } foreach (var completion in Completion.GetCompletions(namespaces)) { foreach (var item in completion.GetProperties(objectName, path).Where(r => !existingAtts.ContainsKey(r.Name))) { var xmlCompletion = new XmlCompletionData(item.Name, item.Description, type); xmlCompletion.Icon = GetIcon(item.Type); list.Add(xmlCompletion); } } return(list); }
private void ShowCompletion(string enteredText, bool controlSpace) { if (!controlSpace) { Debug.WriteLine("Code Completion: TextEntered: " + enteredText); } else { Debug.WriteLine("Code Completion: Ctrl+Space"); } //only process csharp files and if there is a code completion engine available if (String.IsNullOrEmpty(FileName)) { Debug.WriteLine("No document file name, cannot run code completion"); return; } if (Completion == null) { Debug.WriteLine("Code completion is null, cannot run code completion"); return; } var fileExtension = Path.GetExtension(FileName); fileExtension = fileExtension != null?fileExtension.ToLower() : null; //check file extension to be a c# file (.cs, .csx, etc.) if (fileExtension == null || (!fileExtension.StartsWith(".cs"))) { Debug.WriteLine("Wrong file extension, cannot run code completion"); return; } if (completionWindow == null) { CodeCompletionResult results = null; try { var offset = 0; var doc = GetCompletionDocument(out offset); results = Completion.GetCompletions(doc, offset, controlSpace); } catch (Exception exception) { Debug.WriteLine("Error in getting completion: " + exception); } if (results == null) { return; } if (insightWindow == null && results.OverloadProvider != null) { insightWindow = new OverloadInsightWindow(TextArea); insightWindow.Provider = results.OverloadProvider; insightWindow.Show(); insightWindow.Closed += (o, args) => insightWindow = null; return; } if (completionWindow == null && results != null && results.CompletionData.Any()) { // Open code completion after the user has pressed dot: completionWindow = new CompletionWindow(TextArea); completionWindow.CloseWhenCaretAtBeginning = controlSpace; completionWindow.StartOffset -= results.TriggerWordLength; //completionWindow.EndOffset -= results.TriggerWordLength; IList <ICompletionData> data = completionWindow.CompletionList.CompletionData; foreach (var completion in results.CompletionData.OrderBy(item => item.Text)) { data.Add(completion); } if (results.TriggerWordLength > 0) { //completionWindow.CompletionList.IsFiltering = false; completionWindow.CompletionList.SelectItem(results.TriggerWord); } completionWindow.Show(); completionWindow.Closed += (o, args) => completionWindow = null; } }//end if //update the insight window if (!string.IsNullOrEmpty(enteredText) && insightWindow != null) { //whenver text is entered update the provider var provider = insightWindow.Provider as CSharpOverloadProvider; if (provider != null) { //since the text has not been added yet we need to tread it as if the char has already been inserted var offset = 0; var doc = GetCompletionDocument(out offset); provider.Update(doc, offset); //if the windows is requested to be closed we do it here if (provider.RequestClose) { insightWindow.Close(); insightWindow = null; } } } }//end method