protected override async Task ProvideCompletionsAsync(CompletionContext context, string pathThroughLastSlash) { var resolver = context.Document.Project.CompilationOptions.MetadataReferenceResolver as RuntimeMetadataReferenceResolver; if (resolver != null && pathThroughLastSlash.IndexOfAny(s_pathIndicators) < 0) { foreach (var(name, path) in resolver.TrustedPlatformAssemblies) { context.AddItem(CommonCompletionItem.Create(name, displayTextSuffix: "", glyph: Glyph.Assembly, rules: s_rules)); context.AddItem(CommonCompletionItem.Create(PathUtilities.GetFileName(path, includeExtension: true), displayTextSuffix: "", glyph: Glyph.Assembly, rules: s_rules)); } if (resolver.GacFileResolver is object) { var gacHelper = new GlobalAssemblyCacheCompletionHelper(s_rules); context.AddItems(await gacHelper.GetItemsAsync(pathThroughLastSlash, context.CancellationToken).ConfigureAwait(false)); } } if (pathThroughLastSlash.IndexOf(',') < 0) { var helper = GetFileSystemCompletionHelper(context.Document, Glyph.Assembly, RuntimeMetadataReferenceResolver.AssemblyExtensions, s_rules); context.AddItems(await helper.GetItemsAsync(pathThroughLastSlash, context.CancellationToken).ConfigureAwait(false)); } }
protected override async Task ProvideCompletionsAsync(CompletionContext context, string pathThroughLastSlash) { if (GacFileResolver.IsAvailable && pathThroughLastSlash.IndexOfAny(s_pathIndicators) < 0) { var gacHelper = new GlobalAssemblyCacheCompletionHelper(s_rules); context.AddItems(await gacHelper.GetItemsAsync(pathThroughLastSlash, context.CancellationToken).ConfigureAwait(false)); } if (pathThroughLastSlash.IndexOf(',') < 0) { var helper = GetFileSystemCompletionHelper(context.Document, Glyph.Assembly, ImmutableArray.Create(".dll", ".exe"), s_rules); context.AddItems(await helper.GetItemsAsync(pathThroughLastSlash, context.CancellationToken).ConfigureAwait(false)); } }
protected override async Task ProvideCompletionsAsync(CompletionContext context, string pathThroughLastSlash) { if (GacFileResolver.IsAvailable && pathThroughLastSlash.IndexOfAny(s_pathIndicators) < 0) { var gacHelper = new GlobalAssemblyCacheCompletionHelper(s_rules); context.AddItems(await gacHelper.GetItemsAsync(pathThroughLastSlash, context.CancellationToken).ConfigureAwait(false)); } if (pathThroughLastSlash.IndexOf(',') < 0) { var text = await context.Document.GetTextAsync(context.CancellationToken).ConfigureAwait(false); var fileSystemHelper = GetFileSystemCompletionHelper(text, context.Document); context.AddItems(await fileSystemHelper.GetItemsAsync(pathThroughLastSlash, context.CancellationToken).ConfigureAwait(false)); } }
public override async Task ProduceCompletionListAsync(CompletionListContext context) { var document = context.Document; var position = context.Position; var cancellationToken = context.CancellationToken; var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); // first try to get the #r string literal token. If we couldn't, then we're not in a #r // reference directive and we immediately bail. SyntaxToken stringLiteral; if (!TryGetStringLiteralToken(tree, position, out stringLiteral, cancellationToken)) { return; } var textChangeSpan = this.GetTextChangeSpan(stringLiteral, position); var gacHelper = new GlobalAssemblyCacheCompletionHelper(this, textChangeSpan, ItemRules.Instance); var text = await document.GetTextAsync(context.CancellationToken).ConfigureAwait(false); var snapshot = text.FindCorrespondingEditorTextSnapshot(); if (snapshot == null) { // Passing null to GetFileSystemDiscoveryService raises an exception. // Instead, return here since there is no longer snapshot for this document. return; } var referenceResolver = document.Project.CompilationOptions.MetadataReferenceResolver; // TODO: https://github.com/dotnet/roslyn/issues/5263 // Avoid dependency on a specific resolvers. // The search paths should be provided by specialized workspaces: // - InteractiveWorkspace for interactive window // - ScriptWorkspace for loose .csx files (we don't have such workspace today) ImmutableArray<string> searchPaths; RuntimeMetadataReferenceResolver rtResolver; WorkspaceMetadataFileReferenceResolver workspaceResolver; if ((rtResolver = referenceResolver as RuntimeMetadataReferenceResolver) != null) { searchPaths = rtResolver.PathResolver.SearchPaths; } else if ((workspaceResolver = referenceResolver as WorkspaceMetadataFileReferenceResolver) != null) { searchPaths = workspaceResolver.PathResolver.SearchPaths; } else { return; } var fileSystemHelper = new FileSystemCompletionHelper( this, textChangeSpan, GetFileSystemDiscoveryService(snapshot), Glyph.OpenFolder, Glyph.Assembly, searchPaths: searchPaths, allowableExtensions: new[] { ".dll", ".exe" }, exclude: path => path.Contains(","), itemRules: ItemRules.Instance); var pathThroughLastSlash = GetPathThroughLastSlash(stringLiteral, position); var documentPath = document.Project.IsSubmission ? null : document.FilePath; context.AddItems(gacHelper.GetItems(pathThroughLastSlash, documentPath)); context.AddItems(fileSystemHelper.GetItems(pathThroughLastSlash, documentPath)); }
public override async Task ProduceCompletionListAsync(CompletionListContext context) { var document = context.Document; var position = context.Position; var cancellationToken = context.CancellationToken; var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); // first try to get the #r string literal token. If we couldn't, then we're not in a #r // reference directive and we immediately bail. SyntaxToken stringLiteral; if (!TryGetStringLiteralToken(tree, position, out stringLiteral, cancellationToken)) { return; } var textChangeSpan = this.GetTextChangeSpan(stringLiteral, position); var gacHelper = new GlobalAssemblyCacheCompletionHelper(this, textChangeSpan, ItemRules.Instance); var text = await document.GetTextAsync(context.CancellationToken).ConfigureAwait(false); var snapshot = text.FindCorrespondingEditorTextSnapshot(); if (snapshot == null) { // Passing null to GetFileSystemDiscoveryService raises an exception. // Instead, return here since there is no longer snapshot for this document. return; } var referenceResolver = document.Project.CompilationOptions.MetadataReferenceResolver; // TODO: https://github.com/dotnet/roslyn/issues/5263 // Avoid dependency on a specific resolvers. // The search paths should be provided by specialized workspaces: // - InteractiveWorkspace for interactive window // - ScriptWorkspace for loose .csx files (we don't have such workspace today) ImmutableArray <string> searchPaths; RuntimeMetadataReferenceResolver rtResolver; WorkspaceMetadataFileReferenceResolver workspaceResolver; if ((rtResolver = referenceResolver as RuntimeMetadataReferenceResolver) != null) { searchPaths = rtResolver.PathResolver.SearchPaths; } else if ((workspaceResolver = referenceResolver as WorkspaceMetadataFileReferenceResolver) != null) { searchPaths = workspaceResolver.PathResolver.SearchPaths; } else { return; } var fileSystemHelper = new FileSystemCompletionHelper( this, textChangeSpan, GetFileSystemDiscoveryService(snapshot), Glyph.OpenFolder, Glyph.Assembly, searchPaths: searchPaths, allowableExtensions: new[] { ".dll", ".exe" }, exclude: path => path.Contains(","), itemRules: ItemRules.Instance); var pathThroughLastSlash = GetPathThroughLastSlash(stringLiteral, position); var documentPath = document.Project.IsSubmission ? null : document.FilePath; context.AddItems(gacHelper.GetItems(pathThroughLastSlash, documentPath)); context.AddItems(fileSystemHelper.GetItems(pathThroughLastSlash, documentPath)); }
private static IEnumerable<CompletionItem> GetItems(string pathSoFar) { var helper = new GlobalAssemblyCacheCompletionHelper(null, new TextSpan()); return helper.GetItems(pathSoFar, documentPath: null); }