Make more context available to completion subclasses

This commit is contained in:
Mikayla Hutchinson 2019-06-20 22:51:41 -04:00
Родитель e5f628c992
Коммит e30c77b000
4 изменённых файлов: 23 добавлений и 15 удалений

Просмотреть файл

@ -32,6 +32,8 @@ using Microsoft.VisualStudio.Language.Intellisense.AsyncCompletion.Data;
using System.Threading.Tasks;
using Microsoft.VisualStudio.Text.Adornments;
using Microsoft.VisualStudio.Language.StandardClassification;
using System.Threading;
using Microsoft.VisualStudio.Language.Intellisense.AsyncCompletion;
namespace MonoDevelop.Xml.Editor.Completion
{
@ -42,8 +44,8 @@ namespace MonoDevelop.Xml.Editor.Completion
{
static readonly Type DocsKey = typeof (ICompletionDocumentationProvider);
static AnnotationDocumentationProvider annotationProvider = new AnnotationDocumentationProvider ();
static StringXmlDocumentationProvider stringProvider = new StringXmlDocumentationProvider ();
static readonly AnnotationDocumentationProvider annotationProvider = new AnnotationDocumentationProvider ();
static readonly StringXmlDocumentationProvider stringProvider = new StringXmlDocumentationProvider ();
public static void AddDocumentationProvider (this CompletionItem item, ICompletionDocumentationProvider docsProvider)
{
@ -62,17 +64,17 @@ namespace MonoDevelop.Xml.Editor.Completion
item.Properties.AddProperty (annotationProvider, annotation);
}
public static Task<object> GetDocumentationAsync (this CompletionItem item)
public static Task<object> GetDocumentationAsync (this CompletionItem item, IAsyncCompletionSession session, CancellationToken token)
{
if (item.Properties.TryGetProperty<ICompletionDocumentationProvider> (DocsKey, out var provider)) {
return provider.GetDocumentationAsync (item);
return provider.GetDocumentationAsync (session, item, token);
}
return null;
}
class StringXmlDocumentationProvider : ICompletionDocumentationProvider
{
public Task<object> GetDocumentationAsync (CompletionItem item)
public Task<object> GetDocumentationAsync (IAsyncCompletionSession session, CompletionItem item, CancellationToken token)
{
var desc = item.Properties.GetProperty<string> (this);
var content = new ClassifiedTextElement (
@ -84,7 +86,7 @@ namespace MonoDevelop.Xml.Editor.Completion
class AnnotationDocumentationProvider : ICompletionDocumentationProvider
{
public Task<object> GetDocumentationAsync (CompletionItem item)
public Task<object> GetDocumentationAsync (IAsyncCompletionSession session, CompletionItem item, CancellationToken token)
{
var annotation = item.Properties.GetProperty<XmlSchemaAnnotation> (this);
@ -116,6 +118,6 @@ namespace MonoDevelop.Xml.Editor.Completion
/// </summary>
public interface ICompletionDocumentationProvider
{
Task<object> GetDocumentationAsync (CompletionItem item);
Task<object> GetDocumentationAsync (IAsyncCompletionSession session, CompletionItem item, CancellationToken token);
}
}

Просмотреть файл

@ -48,25 +48,25 @@ namespace MonoDevelop.Xml.Editor.Completion
//TODO: if it's on the first or second line and there's no DTD declaration, add the DTDs, or at least <!DOCTYPE
//TODO: add closing tags // AddCloseTag (list, spine.Nodes);
//TODO: add snippets // MonoDevelop.Ide.CodeTemplates.CodeTemplateService.AddCompletionDataForFileName (DocumentContext.Name, list);
return await GetElementCompletionsAsync (triggerLocation, nodePath, triggerResult.kind == XmlCompletionTrigger.ElementWithBracket, token);
return await GetElementCompletionsAsync (session, triggerLocation, nodePath, triggerResult.kind == XmlCompletionTrigger.ElementWithBracket, token);
case XmlCompletionTrigger.Attribute:
IAttributedXObject attributedOb = (spine.Nodes.Peek () as IAttributedXObject) ?? spine.Nodes.Peek (1) as IAttributedXObject;
return await GetAttributeCompletionsAsync (triggerLocation, nodePath, attributedOb, GetExistingAttributes (spine, triggerLocation.Snapshot, attributedOb), token);
return await GetAttributeCompletionsAsync (session, triggerLocation, nodePath, attributedOb, GetExistingAttributes (spine, triggerLocation.Snapshot, attributedOb), token);
case XmlCompletionTrigger.AttributeValue:
if (spine.Nodes.Peek () is XAttribute att && spine.Nodes.Peek (1) is IAttributedXObject attributedObject) {
return await GetAttributeValueCompletionsAsync (triggerLocation, nodePath, attributedObject, att, token);
return await GetAttributeValueCompletionsAsync (session, triggerLocation, nodePath, attributedObject, att, token);
}
break;
case XmlCompletionTrigger.Entity:
return await GetEntityCompletionsAsync (triggerLocation, nodePath, token);
return await GetEntityCompletionsAsync (session, triggerLocation, nodePath, token);
case XmlCompletionTrigger.DocType:
case XmlCompletionTrigger.DocTypeOrCData:
// we delegate adding the CDATA completion to the subclass as only it knows whether character data is valid in that position
return await GetDocTypeCompletionsAsync (triggerLocation, nodePath, triggerResult.kind == XmlCompletionTrigger.DocTypeOrCData, token);
return await GetDocTypeCompletionsAsync (session, triggerLocation, nodePath, triggerResult.kind == XmlCompletionTrigger.DocTypeOrCData, token);
}
}
@ -78,7 +78,7 @@ namespace MonoDevelop.Xml.Editor.Completion
CompletionItem item,
CancellationToken token)
{
return item.GetDocumentationAsync ();
return item.GetDocumentationAsync (session, token);
}
public CompletionStartData InitializeCompletion (CompletionTrigger trigger, SnapshotPoint triggerLocation, CancellationToken token)
@ -102,6 +102,7 @@ namespace MonoDevelop.Xml.Editor.Completion
}
protected virtual Task<CompletionContext> GetElementCompletionsAsync (
IAsyncCompletionSession session,
SnapshotPoint triggerLocation,
List<XObject> nodePath,
bool includeBracket,
@ -110,6 +111,7 @@ namespace MonoDevelop.Xml.Editor.Completion
=> Task.FromResult (CompletionContext.Empty);
protected virtual Task<CompletionContext> GetAttributeCompletionsAsync (
IAsyncCompletionSession session,
SnapshotPoint triggerLocation,
List<XObject> nodePath,
IAttributedXObject attributedObject,
@ -119,6 +121,7 @@ namespace MonoDevelop.Xml.Editor.Completion
=> Task.FromResult (CompletionContext.Empty);
protected virtual Task<CompletionContext> GetAttributeValueCompletionsAsync (
IAsyncCompletionSession session,
SnapshotPoint triggerLocation,
List<XObject> nodePath,
IAttributedXObject attributedObject,
@ -128,6 +131,7 @@ namespace MonoDevelop.Xml.Editor.Completion
=> Task.FromResult (CompletionContext.Empty);
protected virtual Task<CompletionContext> GetEntityCompletionsAsync (
IAsyncCompletionSession session,
SnapshotPoint triggerLocation,
List<XObject> nodePath,
CancellationToken token
@ -135,6 +139,7 @@ namespace MonoDevelop.Xml.Editor.Completion
=> Task.FromResult (CompletionContext.Empty);
protected virtual Task<CompletionContext> GetDocTypeCompletionsAsync (
IAsyncCompletionSession session,
SnapshotPoint triggerLocation,
List<XObject> nodePath,
bool includeCData,

Просмотреть файл

@ -43,6 +43,7 @@ namespace MonoDevelop.Xml.Tests.Completion
}
protected override Task<CompletionContext> GetElementCompletionsAsync (
IAsyncCompletionSession session,
SnapshotPoint triggerLocation,
List<XObject> nodePath,
bool includeBracket,

Просмотреть файл

@ -74,7 +74,7 @@ namespace MonoDevelop.Xml.Tests.Schema
foreach (var data in items.Items) {
if (data.DisplayText == name) {
var descEl = await data.GetDocumentationAsync () as ClassifiedTextElement;
var descEl = await data.GetDocumentationAsync (null, default) as ClassifiedTextElement;
if (descEl != null && descEl.Runs.FirstOrDefault()?.Text == description) {
Contains = true;
break;
@ -123,7 +123,7 @@ namespace MonoDevelop.Xml.Tests.Schema
protected async Task AssertDescription(string expected, CompletionItem item)
{
var description = (ClassifiedTextElement) await item.GetDocumentationAsync ();
var description = (ClassifiedTextElement) await item.GetDocumentationAsync (null, default);
Assert.AreEqual (expected, description.Runs.First ().Text);
}
}