protected sealed override async Task <SignatureHelpItems> GetItemsWorkerAsync(LogicalDocument document, int position, SignatureHelpTriggerInfo triggerInfo, CancellationToken cancellationToken) { var syntaxTree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); var sourceLocation = syntaxTree.MapRootFilePosition(position); var token = ((SyntaxNode)syntaxTree.Root).FindTokenOnLeft(sourceLocation); var node = token.Parent .AncestorsAndSelf() .OfType <TNode>() .FirstOrDefault(c => c.IsBetweenParentheses(sourceLocation)); if (node == null) { return(null); } var rootSpan = node.GetTextSpanRoot(); if (rootSpan == null) { return(null); } var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); if (semanticModel == null) { return(null); } return(GetModel((SemanticModel)semanticModel, node, sourceLocation)); }
public async Task <QuickInfoItem> GetItemAsync( LogicalDocument document, int position, CancellationToken cancellationToken) { var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); var sourceLocation = tree.MapRootFilePosition(position); var token = await tree.GetTouchingTokenAsync(sourceLocation, cancellationToken, findInsideTrivia : true).ConfigureAwait(false); if (token == null) { return(null); } var state = await GetQuickInfoItemAsync(document, tree, token, sourceLocation, cancellationToken).ConfigureAwait(false); if (state != null) { return(state); } if (ShouldCheckPreviousToken(token)) { var previousToken = token.GetPreviousToken(); if ((state = await GetQuickInfoItemAsync(document, tree, previousToken, sourceLocation, cancellationToken).ConfigureAwait(false)) != null) { return(state); } } return(null); }
protected override async Task <ImmutableArray <DefinitionItem> > GetSyntacticDefinitionsAsync(LogicalDocument document, int position, CancellationToken cancellationToken) { var syntaxTree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); var sourceLocation = syntaxTree.MapRootFilePosition(position); var syntaxFacts = document.GetLanguageService <ISyntaxFactsService>(); var syntaxToken = (SyntaxToken)await syntaxTree.GetTouchingTokenAsync(sourceLocation, x => true, cancellationToken, findInsideTrivia : true).ConfigureAwait(false); if (syntaxToken == null) { return(ImmutableArray <DefinitionItem> .Empty); } if (syntaxToken.MacroReference != null) { return(GetMacroDefinitionItem(document, sourceLocation, syntaxToken)); } if (syntaxToken.Parent.IsKind(SyntaxKind.IncludeDirectiveTrivia)) { return(GetIncludeDefinitionItem(document, syntaxToken)); } return(ImmutableArray <DefinitionItem> .Empty); }
public async Task <ImmutableArray <BlockSpan> > ProvideBlockStructureAsync(LogicalDocument document, CancellationToken cancellationToken) { var results = ImmutableArray.CreateBuilder <BlockSpan>(); var outliningVisitor = new OutliningVisitor(document.SourceText, results, cancellationToken); var syntaxTree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); if (syntaxTree != null) { outliningVisitor.VisitCompilationUnit((CompilationUnitSyntax)syntaxTree.Root); } return(results.ToImmutable()); }
public async Task <ImmutableArray <INavigateToSearchResult> > SearchDocumentAsync(LogicalDocument document, string searchPattern, CancellationToken cancellationToken) { var result = ArrayBuilder <INavigateToSearchResult> .GetInstance(); cancellationToken.ThrowIfCancellationRequested(); var syntaxTree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); if (semanticModel == null) { return(ImmutableArray <INavigateToSearchResult> .Empty); } foreach (var node in syntaxTree.Root.DescendantNodesAndSelf()) { cancellationToken.ThrowIfCancellationRequested(); var declaredSymbol = semanticModel.GetDeclaredSymbol(node); if (declaredSymbol != null && declaredSymbol.Kind != SymbolKind.Parameter && (declaredSymbol.Kind != SymbolKind.Variable || declaredSymbol.Parent == null || declaredSymbol.Parent.Kind != SymbolKind.Function) && Contains(declaredSymbol.Name, searchPattern)) { var matchKind = declaredSymbol.Name.StartsWith(searchPattern, StringComparison.CurrentCultureIgnoreCase) ? NavigateToMatchKind.Prefix : (declaredSymbol.Name == searchPattern) ? NavigateToMatchKind.Exact : NavigateToMatchKind.Substring; result.AddRange(ConvertResult(declaredSymbol, document, syntaxTree, matchKind)); } } return(result.ToImmutableAndFree()); }