protected override async Task <IEnumerable <CompletionItem> > GetItemsWorkerAsync( Document document, int position, CompletionTriggerInfo triggerInfo, CancellationToken cancellationToken) { if (document != null && document.SourceCodeKind == SourceCodeKind.Interactive) { // the provider might be invoked in non-interactive context: Workspace ws; if (Workspace.TryGetWorkspace(document.GetTextAsync(cancellationToken).WaitAndGetResult(cancellationToken).Container, out ws)) { var workspace = ws as InteractiveWorkspace; if (workspace != null) { var window = workspace.Engine.CurrentWindow; var tree = await document.GetCSharpSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); if (tree.IsBeforeFirstToken(position, cancellationToken) && tree.IsPreProcessorKeywordContext(position, cancellationToken)) { var textChangeSpan = await this.GetTextChangeSpanAsync(document, position, cancellationToken).ConfigureAwait(false); var list = new List <CompletionItem>(); IInteractiveWindowCommands commands = window.GetInteractiveCommands(); if (commands != null) { foreach (var command in commands.GetCommands()) { foreach (var commandName in command.Names) { list.Add(new CSharpCompletionItem( workspace, this, commandName, textChangeSpan, c => Task.FromResult(command.Description.ToSymbolDisplayParts()), glyph: Glyph.Intrinsic)); } } } return(list); } } } } return(SpecializedCollections.EmptyEnumerable <CompletionItem>()); }
public override async Task ProduceCompletionListAsync(CompletionListContext context) { var document = context.Document; var position = context.Position; var cancellationToken = context.CancellationToken; if (document != null && document.SourceCodeKind == SourceCodeKind.Interactive) { // the provider might be invoked in non-interactive context: Workspace ws; if (Workspace.TryGetWorkspace(document.GetTextAsync(cancellationToken).WaitAndGetResult(cancellationToken).Container, out ws)) { var workspace = ws as InteractiveWorkspace; if (workspace != null) { var window = workspace.Engine.CurrentWindow; var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); if (tree.IsBeforeFirstToken(position, cancellationToken) && tree.IsPreProcessorKeywordContext(position, cancellationToken)) { var filterSpan = await this.GetTextChangeSpanAsync(document, position, cancellationToken).ConfigureAwait(false); IInteractiveWindowCommands commands = window.GetInteractiveCommands(); if (commands != null) { foreach (var command in commands.GetCommands()) { foreach (var commandName in command.Names) { context.AddItem(new CompletionItem( this, commandName, filterSpan, c => Task.FromResult(command.Description.ToSymbolDisplayParts()), glyph: Glyph.Intrinsic)); } } } } } } } }
public override async Task ProduceCompletionListAsync(CompletionListContext context) { var document = context.Document; var position = context.Position; var cancellationToken = context.CancellationToken; // the provider might be invoked in non-interactive context: Workspace ws; SourceText sourceText = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); if (Workspace.TryGetWorkspace(sourceText.Container, out ws)) { var workspace = ws as InteractiveWorkspace; if (workspace != null) { var window = workspace.Engine.CurrentWindow; var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); if (await ShouldDisplayCommandCompletionsAsync(tree, position, cancellationToken).ConfigureAwait(false)) { var filterSpan = await this.GetTextChangeSpanAsync(document, position, cancellationToken).ConfigureAwait(false); IInteractiveWindowCommands commands = window.GetInteractiveCommands(); if (commands != null) { foreach (var command in commands.GetCommands()) { foreach (var commandName in command.Names) { string completion = GetCompletionString(commandName); context.AddItem(new CompletionItem( this, completion, filterSpan, c => Task.FromResult(command.Description.ToSymbolDisplayParts()), glyph: Glyph.Intrinsic)); } } } } } } }
public override async Task ProvideCompletionsAsync(CompletionContext context) { var document = context.Document; var position = context.Position; var cancellationToken = context.CancellationToken; // the provider might be invoked in non-interactive context: Workspace ws; SourceText sourceText = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); if (Workspace.TryGetWorkspace(sourceText.Container, out ws)) { var workspace = ws as InteractiveWorkspace; if (workspace != null) { var window = workspace.Window; var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); if (await ShouldDisplayCommandCompletionsAsync(tree, position, cancellationToken).ConfigureAwait(false)) { IInteractiveWindowCommands commands = window.GetInteractiveCommands(); if (commands != null) { foreach (var command in commands.GetCommands()) { foreach (var commandName in command.Names) { string completion = GetCompletionString(commandName); context.AddItem(CommonCompletionItem.Create( completion, CompletionItemRules.Default, description: command.Description.ToSymbolDisplayParts(), glyph: Glyph.Intrinsic)); } } } } } } }