private async Task <NameDeclarationInfo> GetResultsAsync(string markup) { var(document, position) = ApplyChangesToFixture(markup); var result = await NameDeclarationInfo.GetDeclarationInfo(document, position, CancellationToken.None); return(result); }
public override async Task ProvideCompletionsAsync(CompletionContext completionContext) { try { var position = completionContext.Position; var document = completionContext.Document; var cancellationToken = completionContext.CancellationToken; var semanticModel = await document.GetSemanticModelForSpanAsync(new Text.TextSpan(position, 0), cancellationToken).ConfigureAwait(false); if (!completionContext.Options.GetOption(CompletionOptions.ShowNameSuggestions, LanguageNames.Stark)) { return; } var context = CSharpSyntaxContext.CreateContext(document.Project.Solution.Workspace, semanticModel, position, cancellationToken); if (context.IsInNonUserCode) { return; } var nameInfo = await NameDeclarationInfo.GetDeclarationInfo(document, position, cancellationToken).ConfigureAwait(false); var baseNames = GetBaseNames(semanticModel, nameInfo); if (baseNames == default) { return; } var recommendedNames = await GetRecommendedNamesAsync(baseNames, nameInfo, context, document, cancellationToken).ConfigureAwait(false); int sortValue = 0; foreach (var(name, kind) in recommendedNames) { // We've produced items in the desired order, add a sort text to each item to prevent alphabetization completionContext.AddItem(CreateCompletionItem(name, GetGlyph(kind, nameInfo.DeclaredAccessibility), sortValue.ToString("D8"))); sortValue++; } completionContext.SuggestionModeItem = CommonCompletionItem.Create( CSharpFeaturesResources.Name, displayTextSuffix: "", CompletionItemRules.Default); } catch (Exception e) when(FatalError.ReportWithoutCrashUnlessCanceled(e)) { // nop } }
public override async Task ProvideCompletionsAsync(CompletionContext completionContext) { var position = completionContext.Position; var document = completionContext.Document; var cancellationToken = completionContext.CancellationToken; var semanticModel = await document.GetSemanticModelForSpanAsync(new Text.TextSpan(position, 0), cancellationToken).ConfigureAwait(false); var context = CSharpSyntaxContext.CreateContext(document.Project.Solution.Workspace, semanticModel, position, cancellationToken); if (context.IsInNonUserCode) { return; } var nameInfo = await NameDeclarationInfo.GetDeclarationInfo(document, position, cancellationToken).ConfigureAwait(false); if (!IsValidType(nameInfo.Type)) { return; } var type = UnwrapType(nameInfo.Type, semanticModel.Compilation); var baseNames = NameGenerator.GetBaseNames(type); var recommendedNames = await GetRecommendedNamesAsync(baseNames, nameInfo, context, document, cancellationToken).ConfigureAwait(false); int sortValue = 0; foreach (var(name, kind) in recommendedNames) { // We've produced items in the desired order, add a sort text to each item to prevent alphabetization completionContext.AddItem(CreateCompletionItem(name, GetGlyph(kind, nameInfo.DeclaredAccessibility), sortValue.ToString("D8"))); sortValue++; } completionContext.SuggestionModeItem = CommonCompletionItem.Create(CSharpFeaturesResources.Name, CompletionItemRules.Default); }