protected async Task <QuickInfoContent> CreateContentAsync( Workspace workspace, ISyntaxToken token, SemanticModelBase semanticModel, IEnumerable <ISymbol> symbols, CancellationToken cancellationToken) { var descriptionService = workspace.Services.GetLanguageServices(token.Language).GetService <ISymbolDisplayService>(); var sections = await descriptionService.ToDescriptionGroupsAsync(workspace, semanticModel, token.FileSpan.Span.Start, symbols.ToImmutableArray(), cancellationToken).ConfigureAwait(false); var mainDescriptionBuilder = new List <TaggedText>(); if (sections.ContainsKey(SymbolDescriptionGroups.MainDescription)) { mainDescriptionBuilder.AddRange(sections[SymbolDescriptionGroups.MainDescription]); } var documentationContent = GetDocumentationContent(symbols, sections); return(new QuickInfoDisplayContent( semanticModel.Language, glyph: symbols?.First().GetGlyph() ?? Glyph.None, mainDescription: ImmutableArray.CreateRange(mainDescriptionBuilder), documentation: documentationContent)); }
public static Func <CancellationToken, Task <CompletionDescription> > CreateDescriptionFactory( Workspace workspace, SemanticModelBase semanticModel, int position, ISymbol symbol) { return(CreateDescriptionFactory(workspace, semanticModel, position, new[] { symbol })); }
public ISymbol GetDeclaredSymbol(SemanticModelBase semanticModel, ISyntaxToken token, CancellationToken cancellationToken) { var location = token.SourceRange; var q = from node in ((SyntaxToken)token).Ancestors() let symbol = semanticModel.GetDeclaredSymbol(node) where symbol != null && symbol.Locations.Contains(location) select symbol; return(q.FirstOrDefault()); }
private static ISymbol GetGlobalMember(SemanticModelBase semanticModel, SyntaxNodeBase node) { switch (node) { case FunctionSyntax t: return(semanticModel.GetDeclaredSymbol(t)); case VariableDeclaratorSyntax t: return(semanticModel.GetDeclaredSymbol(t)); } return(null); }
private static void AddDocumentationPart( List <TaggedText> textContentBuilder, ISymbol symbol, SemanticModelBase semanticModel, int position, CancellationToken cancellationToken) { var documentation = symbol.GetDocumentationParts(semanticModel, position, cancellationToken); if (documentation.Any()) { textContentBuilder.AddLineBreak(); textContentBuilder.AddRange(documentation); } }
public SymbolSpan?FindSymbol(SemanticModelBase semanticModel, SourceLocation position) { if (semanticModel == null) { throw new ArgumentNullException(nameof(semanticModel)); } var syntaxTreeRoot = (SyntaxNode)semanticModel.SyntaxTree.Root; return(syntaxTreeRoot.FindNodes(position) .SelectMany(n => GetSymbolSpans((SemanticModel)semanticModel, n)) .Where(s => s.Span.File.IsRootFile && s.SourceRange.ContainsOrTouches(position)) .Select(s => s).Cast <SymbolSpan?>().FirstOrDefault()); }
private static ISymbol GetType(SemanticModelBase semanticModel, SyntaxNodeBase node) { switch (node) { case ConstantBufferSyntax t: return(semanticModel.GetDeclaredSymbol(t)); case NamespaceSyntax t: return(semanticModel.GetDeclaredSymbol(t)); case TechniqueSyntax t: return(semanticModel.GetDeclaredSymbol(t)); case TypeDefinitionSyntax t: return(semanticModel.GetDeclaredSymbol(t)); } return(null); }
private static IEnumerable <ISymbol> GetGlobalMembers(SemanticModelBase semanticModel, CancellationToken cancellationToken) { //using (Logger.LogBlock(FunctionId.NavigationBar_ItemService_GetTypesInFile_CSharp, cancellationToken)) { var members = new HashSet <ISymbol>(); var nodesToVisit = new Stack <SyntaxNodeBase>(); nodesToVisit.Push(semanticModel.SyntaxTree.Root); while (!nodesToVisit.IsEmpty()) { if (cancellationToken.IsCancellationRequested) { return(SpecializedCollections.EmptyEnumerable <ISymbol>()); } var node = nodesToVisit.Pop(); var member = GetGlobalMember(semanticModel, node); if (member != null) { members.Add(member); } if (node is FunctionSyntax || node is TypeDeclarationStatementSyntax || node is ExpressionSyntax || node is TechniqueSyntax || node is ConstantBufferSyntax) { // quick bail out to prevent us from visiting every node in current file continue; } foreach (var child in node.ChildNodes) { if (!child.IsToken) { nodesToVisit.Push(child); } } } return(members); } }
public static async Task <CompletionDescription> CreateDescriptionAsync( Workspace workspace, SemanticModelBase semanticModel, int position, IReadOnlyList <ISymbol> symbols, CancellationToken cancellationToken) { var symbolDisplayService = workspace.Services.GetLanguageServices(semanticModel.Language).GetService <ISymbolDisplayService>(); // TODO(cyrusn): Figure out a way to cancel this. var symbol = symbols[0]; var sections = await symbolDisplayService.ToDescriptionGroupsAsync(workspace, semanticModel, position, ImmutableArray.Create(symbol), cancellationToken).ConfigureAwait(false); if (!sections.ContainsKey(SymbolDescriptionGroups.MainDescription)) { return(CompletionDescription.Empty); } var textContentBuilder = new List <TaggedText>(); textContentBuilder.AddRange(sections[SymbolDescriptionGroups.MainDescription]); switch (symbol.Kind) { case SymbolKind.Function: if (symbols.Count > 1) { var overloadCount = symbols.Count - 1; var isGeneric = false; textContentBuilder.AddSpace(); textContentBuilder.AddPunctuation("("); textContentBuilder.AddPunctuation("+"); textContentBuilder.AddText(NonBreakingSpaceString + overloadCount.ToString()); AddOverloadPart(textContentBuilder, overloadCount, isGeneric); textContentBuilder.AddPunctuation(")"); } break; } AddDocumentationPart(textContentBuilder, symbol, semanticModel, position, cancellationToken); return(CompletionDescription.Create(textContentBuilder.AsImmutable())); }
internal static async Task <TokenSemanticInfo> GetSemanticInfoAtPositionAsync( SemanticModelBase semanticModel, int position, Workspace workspace, CancellationToken cancellationToken) { var syntaxTree = semanticModel.SyntaxTree; var sourceLocation = syntaxTree.MapRootFilePosition(position); var syntaxFacts = workspace.Services.GetLanguageServices(semanticModel.Language).GetService <ISyntaxFactsService>(); var token = await syntaxTree.GetTouchingTokenAsync(sourceLocation, syntaxFacts.IsBindableToken, cancellationToken, findInsideTrivia : true).ConfigureAwait(false); if (token != null && token.FileSpan.Span.IntersectsWith(position)) { return(semanticModel.GetSemanticInfo(token, workspace, cancellationToken)); } return(TokenSemanticInfo.Empty); }
public ImmutableArray <SymbolSpan> FindUsages(SemanticModelBase semanticModel, ISymbol symbol) { if (semanticModel == null) { throw new ArgumentNullException(nameof(semanticModel)); } if (symbol == null) { throw new ArgumentNullException(nameof(symbol)); } var syntaxTreeRoot = (SyntaxNode)semanticModel.SyntaxTree.Root; return((from n in syntaxTreeRoot.DescendantNodes() from s in GetSymbolSpans((SemanticModel)semanticModel, (SyntaxNode)n) where s.Symbol.Equals(symbol) select s).ToImmutableArray()); }
public static TokenSemanticInfo GetSemanticInfo( this SemanticModelBase semanticModel, ISyntaxToken token, Workspace workspace, CancellationToken cancellationToken) { var languageServices = workspace.Services.GetLanguageServices(token.Language); var syntaxFacts = languageServices.GetService <ISyntaxFactsService>(); if (!syntaxFacts.IsBindableToken(token)) { return(TokenSemanticInfo.Empty); } var semanticFacts = languageServices.GetService <ISemanticFactsService>(); return(GetSemanticInfo( semanticModel, semanticFacts, syntaxFacts, token, cancellationToken)); }
private static TokenSemanticInfo GetSemanticInfo( SemanticModelBase semanticModel, ISemanticFactsService semanticFacts, ISyntaxFactsService syntaxFacts, ISyntaxToken token, CancellationToken cancellationToken) { //var aliasSymbol = semanticModel.GetAliasInfo(token.Parent, cancellationToken); IAliasSymbol aliasSymbol = null; var bindableParent = syntaxFacts.GetBindableParent(token); var type = semanticModel.GetTypeInfo(bindableParent).Type; var declaredSymbol = semanticFacts.GetDeclaredSymbol(semanticModel, token, cancellationToken); var allSymbols = semanticModel.GetSymbolInfo(bindableParent) .GetBestOrAllSymbols() .WhereAsArray(s => !s.Equals(declaredSymbol)) .SelectAsArray(s => s); return(new TokenSemanticInfo(declaredSymbol, aliasSymbol, allSymbols, type)); }
public static IEnumerable <TaggedText> GetDocumentationParts(this ISymbol symbol, SemanticModelBase semanticModel, int position, CancellationToken cancellationToken) { string documentation = GetDocumentation(symbol, cancellationToken); return(documentation != null ? SpecializedCollections.SingletonEnumerable(new TaggedText(TextTags.Text, documentation)) : SpecializedCollections.EmptyEnumerable <TaggedText>()); }
public Task <IDictionary <SymbolDescriptionGroups, ImmutableArray <TaggedText> > > ToDescriptionGroupsAsync(Workspace workspace, SemanticModelBase semanticModel, int position, ImmutableArray <ISymbol> symbols, CancellationToken cancellationToken) { return(Task.FromResult((IDictionary <SymbolDescriptionGroups, ImmutableArray <TaggedText> >) new Dictionary <SymbolDescriptionGroups, ImmutableArray <TaggedText> > { { SymbolDescriptionGroups.MainDescription, symbols[0].ToMarkup().Tokens.ToTaggedText() } })); }
public static Func <CancellationToken, Task <CompletionDescription> > CreateDescriptionFactory( Workspace workspace, SemanticModelBase semanticModel, int position, IReadOnlyList <ISymbol> symbols) { return(c => CreateDescriptionAsync(workspace, semanticModel, position, symbols, cancellationToken: c)); }
public abstract void AddSemanticClassifications(SemanticModelBase semanticModel, TextSpan textSpan, Workspace workspace, List <ClassifiedSpan> result, CancellationToken cancellationToken);
public override void AddSemanticClassifications(SemanticModelBase semanticModel, TextSpan textSpan, Workspace workspace, List <ClassifiedSpan> result, CancellationToken cancellationToken) { var semanticTaggerVisitor = new SemanticTaggerVisitor((SemanticModel)semanticModel, result, cancellationToken); semanticTaggerVisitor.VisitCompilationUnit((CompilationUnitSyntax)semanticModel.SyntaxTree.Root); }
public override void AddSemanticClassifications(SemanticModelBase semanticModel, TextSpan textSpan, Workspace workspace, List <ClassifiedSpan> result, CancellationToken cancellationToken) { // TODO }