public override async Task ProvideCompletionsAsync(CompletionContext context) { var document = context.Document; var position = context.Position; var cancellationToken = context.CancellationToken; var syntaxTree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); if (syntaxTree.IsInNonUserCode(position, cancellationToken)) { return; } var token = syntaxTree.FindTokenOnLeftOfPosition(position, cancellationToken); token = token.GetPreviousTokenIfTouchingWord(position); if (!token.IsKind(SyntaxKind.OpenParenToken, SyntaxKind.CommaToken)) { return; } var attributeArgumentList = token.Parent as AttributeArgumentListSyntax; var attributeSyntax = token.Parent.Parent as AttributeSyntax; if (attributeSyntax == null || attributeArgumentList == null) { return; } if (IsAfterNameColonArgument(token) || IsAfterNameEqualsArgument(token)) { context.IsExclusive = true; } // We actually want to collect two sets of named parameters to present the user. The // normal named parameters that come from the attribute constructors. These will be // presented like "foo:". And also the named parameters that come from the writable // fields/properties in the attribute. These will be presented like "bar =". var existingNamedParameters = GetExistingNamedParameters(attributeArgumentList, position); var workspace = document.Project.Solution.Workspace; var semanticModel = await document.GetSemanticModelForNodeAsync(attributeSyntax, cancellationToken).ConfigureAwait(false); var nameColonItems = await GetNameColonItemsAsync(context, semanticModel, token, attributeSyntax, existingNamedParameters).ConfigureAwait(false); var nameEqualsItems = await GetNameEqualsItemsAsync(context, semanticModel, token, attributeSyntax, existingNamedParameters).ConfigureAwait(false); context.AddItems(nameEqualsItems); // If we're after a name= parameter, then we only want to show name= parameters. // Otherwise, show name: parameters too. if (!IsAfterNameEqualsArgument(token)) { context.AddItems(nameColonItems); } }
public override async Task ProvideCompletionsAsync(CompletionContext context) { var document = context.Document; var position = context.Position; var options = context.Options; var cancellationToken = context.CancellationToken; using (Logger.LogBlock(FunctionId.Completion_SnippetCompletionProvider_GetItemsWorker_CSharp, cancellationToken)) { // TODO (https://github.com/dotnet/roslyn/issues/5107): Enable in Interactive. var workspace = document.Project.Solution.Workspace; if (!workspace.CanApplyChange(ApplyChangesKind.ChangeDocument) || workspace.Kind == WorkspaceKind.Debugger || workspace.Kind == WorkspaceKind.Interactive) { return; } var snippetCompletionItems = await document.GetUnionItemsFromDocumentAndLinkedDocumentsAsync( UnionCompletionItemComparer.Instance, (d, c) => GetSnippetsForDocumentAsync(d, position, context.DefaultItemSpan, workspace, c), cancellationToken).ConfigureAwait(false); context.AddItems(snippetCompletionItems); } }
public override async Task ProvideCompletionsAsync(CompletionContext context) { var document = context.Document; var position = context.Position; var options = context.Options; var cancellationToken = context.CancellationToken; var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); if (!tree.IsEntirelyWithinCrefSyntax(position, cancellationToken)) { return; } var token = tree.FindTokenOnLeftOfPosition(position, cancellationToken, includeDocumentationComments: true) .GetPreviousTokenIfTouchingWord(position); // To get a Speculative SemanticModel (which is much faster), we need to // walk up to the node the DocumentationTrivia is attached to. var parentNode = token.Parent.FirstAncestorOrSelf<DocumentationCommentTriviaSyntax>()?.ParentTrivia.Token.Parent; if (parentNode == null) { return; } var semanticModel = await document.GetSemanticModelForNodeAsync(parentNode, cancellationToken).ConfigureAwait(false); var symbols = GetSymbols(token, semanticModel, cancellationToken); symbols = symbols.FilterToVisibleAndBrowsableSymbols(options.GetOption(CompletionOptions.HideAdvancedMembers, semanticModel.Language), semanticModel.Compilation); if (!symbols.Any()) { return; } context.IsExclusive = true; var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); var span = GetCompletionItemSpan(text, position); var items = CreateCompletionItems(document.Project.Solution.Workspace, semanticModel, symbols, token, span); context.AddItems(items); }
void GenerateGuidFormatitems(Microsoft.CodeAnalysis.Completion.CompletionContext completionContext) { completionContext.AddItems(guidFormatItems); }
void GenerateTimeSpanFormatitems(Microsoft.CodeAnalysis.Completion.CompletionContext completionContext) { completionContext.AddItems(timeSpanFormatItems); }
public override async Task ProvideCompletionsAsync(CompletionContext 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: s_rules); 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: s_rules); 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)); }
void AddFormatCompletionData(Microsoft.CodeAnalysis.Completion.CompletionContext context, bool isVerbatimString) { context.AddItems(isVerbatimString ? verbatimFormatItems : formatItems); }
public override async Task ProvideCompletionsAsync(CompletionContext context) { var text = await context.Document.GetTextAsync(context.CancellationToken).ConfigureAwait(false); var items = GetItems(text, context.Document, context.Position, context.Trigger, context.CancellationToken); context.AddItems(items); }