static void CopyTest2 <T>(TemporaryArray <TemporaryArray <T> > array) { CopyTest(array); var a = array[0]; Assert.NotNull(a.Array); }
protected override void CollectBlockSpans( ConversionOperatorDeclarationSyntax operatorDeclaration, ref TemporaryArray <BlockSpan> spans, BlockStructureOptionProvider optionProvider, CancellationToken cancellationToken) { CSharpStructureHelpers.CollectCommentBlockSpans(operatorDeclaration, ref spans, optionProvider); // fault tolerance if (operatorDeclaration.Body == null || operatorDeclaration.Body.OpenBraceToken.IsMissing || operatorDeclaration.Body.CloseBraceToken.IsMissing) { return; } SyntaxNodeOrToken current = operatorDeclaration; var nextSibling = current.GetNextSibling(); // Check IsNode to compress blank lines after this node if it is the last child of the parent. // // Whitespace between conversion operators is collapsed in Metadata as Source. var compressEmptyLines = optionProvider.IsMetadataAsSource && (!nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.ConversionOperatorDeclaration)); spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( operatorDeclaration, operatorDeclaration.ParameterList.GetLastToken(includeZeroWidth: true), compressEmptyLines: compressEmptyLines, autoCollapse: true, type: BlockTypes.Member, isCollapsible: true)); }
protected override void CollectBlockSpans( DestructorDeclarationSyntax destructorDeclaration, ref TemporaryArray <BlockSpan> spans, BlockStructureOptionProvider optionProvider, CancellationToken cancellationToken ) { CSharpStructureHelpers.CollectCommentBlockSpans( destructorDeclaration, ref spans, optionProvider ); // fault tolerance if ( destructorDeclaration.Body == null || destructorDeclaration.Body.OpenBraceToken.IsMissing || destructorDeclaration.Body.CloseBraceToken.IsMissing ) { return; } spans.AddIfNotNull( CSharpStructureHelpers.CreateBlockSpan( destructorDeclaration, destructorDeclaration.ParameterList.GetLastToken(includeZeroWidth: true), compressEmptyLines: false, autoCollapse: true, type: BlockTypes.Member, isCollapsible: true ) ); }
protected override void CollectBlockSpans( SyntaxToken previousToken, DocumentationCommentTriviaSyntax documentationComment, ref TemporaryArray <BlockSpan> spans, BlockStructureOptionProvider optionProvider, CancellationToken cancellationToken) { var startPos = documentationComment.FullSpan.Start; // The trailing newline is included in XmlDocCommentSyntax, so we need to strip it. var endPos = documentationComment.SpanStart + documentationComment.ToString().TrimEnd().Length; var span = TextSpan.FromBounds(startPos, endPos); var bannerLength = optionProvider.GetOption(BlockStructureOptions.MaximumBannerLength, LanguageNames.CSharp); var bannerText = CSharpSyntaxFacts.Instance.GetBannerText( documentationComment, bannerLength, cancellationToken); spans.Add(new BlockSpan( isCollapsible: true, textSpan: span, type: BlockTypes.Comment, bannerText: bannerText, autoCollapse: true)); }
private async Task UpdateReferencesAsync(Project project, CancellationToken cancellationToken) { // Process all metadata references. If it remote workspace, do this in parallel. using var pendingTasks = new TemporaryArray <Task>(); foreach (var reference in project.MetadataReferences) { if (reference is not PortableExecutableReference portableExecutableReference) { continue; } if (cancellationToken.IsCancellationRequested) { // Break out of this loop to make sure other pending operations process cancellation before // returning. break; } var updateTask = UpdateReferenceAsync(_metadataIdToInfo, project, portableExecutableReference, cancellationToken); if (updateTask.Status != TaskStatus.RanToCompletion) { pendingTasks.Add(updateTask); } } if (pendingTasks.Count > 0) { // If any update operations did not complete synchronously (including any cancelled operations), // wait for them to complete now. await Task.WhenAll(pendingTasks.ToImmutableAndClear()).ConfigureAwait(false); }
static void CopyTest <T>(TemporaryArray <T> array) { Assert.NotNull(array.Array); var a = array; Assert.NotNull(a.Array); }
protected override void CollectBlockSpans( SyntaxToken previousToken, DocumentationCommentTriviaSyntax documentationComment, ref TemporaryArray <BlockSpan> spans, BlockStructureOptions options, CancellationToken cancellationToken) { // In metadata as source we want to treat documentation comments slightly differently, and collapse them // to just "..." in front of the decalaration they're attached to. That happens in CSharpStructureHelper.CollectCommentBlockSpans // so we don't need to do anything here if (options.IsMetadataAsSource) { return; } var startPos = documentationComment.FullSpan.Start; // The trailing newline is included in XmlDocCommentSyntax, so we need to strip it. var endPos = documentationComment.SpanStart + documentationComment.ToString().TrimEnd().Length; var span = TextSpan.FromBounds(startPos, endPos); var bannerLength = options.MaximumBannerLength; var bannerText = CSharpFileBannerFacts.Instance.GetBannerText( documentationComment, bannerLength, cancellationToken); spans.Add(new BlockSpan( isCollapsible: true, textSpan: span, type: BlockTypes.Comment, bannerText: bannerText, autoCollapse: true)); }
protected override void CollectBlockSpans( SyntaxToken previousToken, AccessorDeclarationSyntax accessorDeclaration, ref TemporaryArray <BlockSpan> spans, BlockStructureOptions options, CancellationToken cancellationToken) { CSharpStructureHelpers.CollectCommentBlockSpans(accessorDeclaration, ref spans, options); // fault tolerance if (accessorDeclaration.Body == null || accessorDeclaration.Body.OpenBraceToken.IsMissing || accessorDeclaration.Body.CloseBraceToken.IsMissing) { return; } SyntaxNodeOrToken current = accessorDeclaration; var nextSibling = current.GetNextSibling(); // Check IsNode to compress blank lines after this node if it is the last child of the parent. // // All accessor kinds are grouped together in Metadata as Source. var compressEmptyLines = options.IsMetadataAsSource && (!nextSibling.IsNode || nextSibling.AsNode() is AccessorDeclarationSyntax); spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( accessorDeclaration, accessorDeclaration.Keyword, compressEmptyLines: compressEmptyLines, autoCollapse: true, type: BlockTypes.Member, isCollapsible: true)); }
protected override void CollectBlockSpans( PropertyDeclarationSyntax propertyDeclaration, ref TemporaryArray <BlockSpan> spans, BlockStructureOptionProvider optionProvider, CancellationToken cancellationToken) { CSharpStructureHelpers.CollectCommentBlockSpans(propertyDeclaration, ref spans, optionProvider); // fault tolerance if (propertyDeclaration.AccessorList == null || propertyDeclaration.AccessorList.OpenBraceToken.IsMissing || propertyDeclaration.AccessorList.CloseBraceToken.IsMissing) { return; } SyntaxNodeOrToken current = propertyDeclaration; var nextSibling = current.GetNextSibling(); // Check IsNode to compress blank lines after this node if it is the last child of the parent. // // Properties are grouped together with indexers in Metadata as Source. var compressEmptyLines = optionProvider.IsMetadataAsSource && (!nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.PropertyDeclaration) || nextSibling.IsKind(SyntaxKind.IndexerDeclaration)); spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( propertyDeclaration, propertyDeclaration.Identifier, compressEmptyLines: compressEmptyLines, autoCollapse: true, type: BlockTypes.Member, isCollapsible: true)); }
protected override void CollectBlockSpans( SyntaxToken previousToken, CompilationUnitSyntax compilationUnit, ref TemporaryArray <BlockSpan> spans, BlockStructureOptions options, CancellationToken cancellationToken) { CSharpStructureHelpers.CollectCommentBlockSpans(compilationUnit, ref spans, options); // extern aliases and usings are outlined in a single region var externsAndUsings = new List <SyntaxNode>(); externsAndUsings.AddRange(compilationUnit.Externs); externsAndUsings.AddRange(compilationUnit.Usings); externsAndUsings.Sort((node1, node2) => node1.SpanStart.CompareTo(node2.SpanStart)); spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( externsAndUsings, compressEmptyLines: false, autoCollapse: true, type: BlockTypes.Imports, isCollapsible: true)); if (compilationUnit.Usings.Count > 0 || compilationUnit.Externs.Count > 0 || compilationUnit.Members.Count > 0 || compilationUnit.AttributeLists.Count > 0) { CSharpStructureHelpers.CollectCommentBlockSpans(compilationUnit.EndOfFileToken.LeadingTrivia, ref spans); } }
private static bool AllChangesCanBeApplied( SimpleIntervalTree <TextChange, IntervalIntrospector> cumulativeChanges, ImmutableArray <TextChange> currentChanges, ref TemporaryArray <TextChange> overlappingSpans, ref TemporaryArray <TextChange> intersectingSpans) { foreach (var change in currentChanges) { overlappingSpans.Clear(); intersectingSpans.Clear(); cumulativeChanges.FillWithIntervalsThatOverlapWith( change.Span.Start, change.Span.Length, ref overlappingSpans); cumulativeChanges.FillWithIntervalsThatIntersectWith( change.Span.Start, change.Span.Length, ref intersectingSpans); var value = ChangeCanBeApplied(change, overlappingSpans: in overlappingSpans, intersectingSpans: in intersectingSpans); if (!value) { return(false); } } // All the changes would merge in fine. We can absorb this. return(true); }
protected override void CollectBlockSpans( SyntaxToken previousToken, AnonymousMethodExpressionSyntax anonymousMethod, ref TemporaryArray <BlockSpan> spans, BlockStructureOptionProvider optionProvider, CancellationToken cancellationToken) { // fault tolerance if (anonymousMethod.Block.IsMissing || anonymousMethod.Block.OpenBraceToken.IsMissing || anonymousMethod.Block.CloseBraceToken.IsMissing) { return; } var lastToken = CSharpStructureHelpers.GetLastInlineMethodBlockToken(anonymousMethod); if (lastToken.Kind() == SyntaxKind.None) { return; } var startToken = anonymousMethod.ParameterList != null ? anonymousMethod.ParameterList.GetLastToken(includeZeroWidth : true) : anonymousMethod.DelegateKeyword; spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( anonymousMethod, startToken, lastToken, compressEmptyLines: false, autoCollapse: false, type: BlockTypes.Expression, isCollapsible: true)); }
protected override void CollectBlockSpans( RegionDirectiveTriviaSyntax regionDirective, ref TemporaryArray <BlockSpan> spans, BlockStructureOptionProvider optionProvider, CancellationToken cancellationToken) { var match = regionDirective.GetMatchingDirective(cancellationToken); if (match != null) { // Always auto-collapse regions for Metadata As Source. These generated files only have one region at // the top of the file, which has content like the following: // // #region Assembly System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a // // C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\3.1.0\ref\netcoreapp3.1\System.Runtime.dll // #endregion // // For other files, auto-collapse regions based on the user option. var autoCollapse = optionProvider.IsMetadataAsSource || optionProvider.GetOption( BlockStructureOptions.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.CSharp); spans.Add(new BlockSpan( isCollapsible: true, textSpan: TextSpan.FromBounds(regionDirective.SpanStart, match.Span.End), type: BlockTypes.PreprocessorRegion, bannerText: GetBannerText(regionDirective), autoCollapse: autoCollapse, isDefaultCollapsed: !optionProvider.IsMetadataAsSource)); } }
protected override void CollectBlockSpans( ParenthesizedLambdaExpressionSyntax lambdaExpression, ref TemporaryArray <BlockSpan> spans, BlockStructureOptionProvider optionProvider, CancellationToken cancellationToken) { // fault tolerance if (lambdaExpression.Body.IsMissing) { return; } if (!(lambdaExpression.Body is BlockSyntax lambdaBlock) || lambdaBlock.OpenBraceToken.IsMissing || lambdaBlock.CloseBraceToken.IsMissing) { return; } var lastToken = CSharpStructureHelpers.GetLastInlineMethodBlockToken(lambdaExpression); if (lastToken.Kind() == SyntaxKind.None) { return; } spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( lambdaExpression, lambdaExpression.ArrowToken, lastToken, compressEmptyLines: false, autoCollapse: false, type: BlockTypes.Expression, isCollapsible: true)); }
protected override void CollectBlockSpans( SyntaxToken previousToken, BlockSyntax node, ref TemporaryArray <BlockSpan> spans, BlockStructureOptions options, CancellationToken cancellationToken) { var parentKind = node.Parent.Kind(); // For most types of statements, just consider the block 'attached' to the // parent node. That means we'll show the parent node header when doing // things like hovering over the indent guide. // // This also works nicely as the close brace for these constructs will always // align with the start of these statements. if (IsNonBlockStatement(node.Parent) || parentKind == SyntaxKind.ElseClause) { var type = GetType(node.Parent); if (type != null) { spans.Add(new BlockSpan( isCollapsible: true, textSpan: GetTextSpan(node), hintSpan: GetHintSpan(node), type: type, autoCollapse: parentKind == SyntaxKind.LocalFunctionStatement && node.Parent.IsParentKind(SyntaxKind.GlobalStatement))); } } // Nested blocks aren't attached to anything. Just collapse them as is. // Switch sections are also special. Say you have the following: // // case 0: // { // // } // // We don't want to consider the block parented by the case, because // that would cause us to draw the following: // // case 0: // | { // | // | } // // Which would obviously be wonky. So in this case, we just use the // spanof the block alone, without consideration for the case clause. if (parentKind is SyntaxKind.Block or SyntaxKind.SwitchSection) { var type = GetType(node.Parent); spans.Add(new BlockSpan( isCollapsible: true, textSpan: node.Span, hintSpan: node.Span, type: type)); } }
public override void CollectBlockSpans( SyntaxTrivia trivia, ref TemporaryArray <BlockSpan> spans, BlockStructureOptions options, CancellationToken cancellationToken) { CollectBlockSpans(trivia.SyntaxTree, trivia, ref spans, cancellationToken); }
public sealed override void CollectBlockSpans( SyntaxTrivia trivia, ref TemporaryArray <BlockSpan> spans, BlockStructureOptions options, CancellationToken cancellationToken) { throw new NotSupportedException(); }
protected override void CollectBlockSpans( EventFieldDeclarationSyntax eventFieldDeclaration, ref TemporaryArray <BlockSpan> spans, BlockStructureOptionProvider optionProvider, CancellationToken cancellationToken) { CSharpStructureHelpers.CollectCommentBlockSpans(eventFieldDeclaration, ref spans, optionProvider); }
public sealed override void CollectBlockSpans( SyntaxNode node, ref TemporaryArray <BlockSpan> spans, BlockStructureOptionProvider optionProvider, CancellationToken cancellationToken) { throw new NotSupportedException(); }
protected override void CollectBlockSpans( InitializerExpressionSyntax node, ref TemporaryArray <BlockSpan> spans, BlockStructureOptionProvider optionProvider, CancellationToken cancellationToken ) { if (node.Parent is InitializerExpressionSyntax) { // We have something like: // // new Dictionary<int, string> // { // ... // { // ... // }, // ... // } // // In this case, we want to collapse the "{ ... }," (including the comma). var nextToken = node.CloseBraceToken.GetNextToken(); var end = nextToken.Kind() == SyntaxKind.CommaToken ? nextToken.Span.End : node.Span.End; spans.Add( new BlockSpan( isCollapsible: true, textSpan: TextSpan.FromBounds(node.SpanStart, end), hintSpan: TextSpan.FromBounds(node.SpanStart, end), type: BlockTypes.Expression ) ); } else { // Parent is something like: // // new Dictionary<int, string> { // ... // } // // The collapsed textspan should be from the > to the } // // However, the hint span should be the entire object creation. var previousToken = node.OpenBraceToken.GetPreviousToken(); spans.Add( new BlockSpan( isCollapsible: true, textSpan: TextSpan.FromBounds(previousToken.Span.End, node.Span.End), hintSpan: node.Parent.Span, type: BlockTypes.Expression ) ); } }
protected override void CollectBlockSpans( SyntaxToken previousToken, EnumMemberDeclarationSyntax enumMemberDeclaration, ref TemporaryArray <BlockSpan> spans, BlockStructureOptionProvider optionProvider, CancellationToken cancellationToken) { CSharpStructureHelpers.CollectCommentBlockSpans(enumMemberDeclaration, ref spans, optionProvider); }
protected override void CollectBlockSpans( SyntaxToken previousToken, FieldDeclarationSyntax fieldDeclaration, ref TemporaryArray <BlockSpan> spans, BlockStructureOptions options, CancellationToken cancellationToken) { CSharpStructureHelpers.CollectCommentBlockSpans(fieldDeclaration, ref spans, options); }
public override bool AddMatches(string container, ref TemporaryArray <PatternMatch> matches) { if (SkipMatch(container)) { return(false); } return(AddMatches(container, ref matches, fuzzyMatch: false) || AddMatches(container, ref matches, fuzzyMatch: true)); }
public override bool AddMatches(string candidate, ref TemporaryArray <PatternMatch> matches) { if (SkipMatch(candidate)) { return(false); } return(MatchPatternSegment(candidate, in _fullPatternSegment, ref matches, fuzzyMatch: false) || MatchPatternSegment(candidate, in _fullPatternSegment, ref matches, fuzzyMatch: true)); }
public static void CollectBlockSpans( SyntaxTree syntaxTree, SyntaxTrivia trivia, ref TemporaryArray <BlockSpan> spans, CancellationToken cancellationToken ) { // We'll always be leading trivia of some token. var startPos = trivia.FullSpan.Start; var parentTriviaList = trivia.Token.LeadingTrivia; var indexInParent = parentTriviaList.IndexOf(trivia); // Note: in some error cases (for example when all future tokens end up being skipped) // the parser may end up attaching pre-processor directives as trailing trivia to a // preceding token. if (indexInParent < 0) { parentTriviaList = trivia.Token.TrailingTrivia; indexInParent = parentTriviaList.IndexOf(trivia); } if (indexInParent <= 0) { return; } if ( !parentTriviaList[indexInParent - 1].IsKind(SyntaxKind.IfDirectiveTrivia) && !parentTriviaList[indexInParent - 1].IsKind(SyntaxKind.ElifDirectiveTrivia) && !parentTriviaList[indexInParent - 1].IsKind(SyntaxKind.ElseDirectiveTrivia) ) { return; } var endTrivia = GetCorrespondingEndTrivia(trivia, parentTriviaList, indexInParent); var endPos = GetEndPositionExludingLastNewLine( syntaxTree, endTrivia, cancellationToken ); var span = TextSpan.FromBounds(startPos, endPos); spans.Add( new BlockSpan( isCollapsible: true, textSpan: span, type: BlockTypes.PreprocessorRegion, bannerText: CSharpStructureHelpers.Ellipsis, autoCollapse: true ) ); }
protected override void CollectBlockSpans( TypeDeclarationSyntax typeDeclaration, ref TemporaryArray <BlockSpan> spans, BlockStructureOptionProvider optionProvider, CancellationToken cancellationToken ) { CSharpStructureHelpers.CollectCommentBlockSpans( typeDeclaration, ref spans, optionProvider ); if ( !typeDeclaration.OpenBraceToken.IsMissing && !typeDeclaration.CloseBraceToken.IsMissing ) { var lastToken = typeDeclaration.TypeParameterList == null ? typeDeclaration.Identifier : typeDeclaration.TypeParameterList.GetLastToken(includeZeroWidth: true); SyntaxNodeOrToken current = typeDeclaration; var nextSibling = current.GetNextSibling(); // Check IsNode to compress blank lines after this node if it is the last child of the parent. // // Collapse to Definitions doesn't collapse type nodes, but a Toggle All Outlining would collapse groups // of types to the compressed form of not showing blank lines. All kinds of types are grouped together // in Metadata as Source. var compressEmptyLines = optionProvider.IsMetadataAsSource && (!nextSibling.IsNode || nextSibling.AsNode() is BaseTypeDeclarationSyntax); spans.AddIfNotNull( CSharpStructureHelpers.CreateBlockSpan( typeDeclaration, lastToken, compressEmptyLines: compressEmptyLines, autoCollapse: false, type: BlockTypes.Type, isCollapsible: true ) ); } // add any leading comments before the end of the type block if (!typeDeclaration.CloseBraceToken.IsMissing) { var leadingTrivia = typeDeclaration.CloseBraceToken.LeadingTrivia; CSharpStructureHelpers.CollectCommentBlockSpans(leadingTrivia, ref spans); } }
public sealed override void CollectBlockSpans( SyntaxNode node, ref TemporaryArray <BlockSpan> spans, BlockStructureOptionProvider optionProvider, CancellationToken cancellationToken) { if (node is TSyntaxNode tSyntax) { CollectBlockSpans(tSyntax, ref spans, optionProvider, cancellationToken); } }
public static void CollectBlockSpans( SyntaxNode syntaxRoot, BlockStructureOptionProvider optionProvider, ImmutableDictionary <Type, ImmutableArray <AbstractSyntaxStructureProvider> > nodeOutlinerMap, ImmutableDictionary <int, ImmutableArray <AbstractSyntaxStructureProvider> > triviaOutlinerMap, ref TemporaryArray <BlockSpan> spans, CancellationToken cancellationToken) { var collector = new BlockSpanCollector(optionProvider, nodeOutlinerMap, triviaOutlinerMap, cancellationToken); collector.Collect(syntaxRoot, ref spans); }
private void GetBlockSpans(SyntaxToken previousToken, SyntaxNode node, ref TemporaryArray <BlockSpan> spans) { if (_nodeProviderMap.TryGetValue(node.GetType(), out var providers)) { foreach (var provider in providers) { _cancellationToken.ThrowIfCancellationRequested(); provider.CollectBlockSpans(previousToken, node, ref spans, _optionProvider, _cancellationToken); } } }
protected override void CollectBlockSpans( SwitchStatementSyntax node, ref TemporaryArray <BlockSpan> spans, BlockStructureOptionProvider optionProvider, CancellationToken cancellationToken) { spans.Add(new BlockSpan( isCollapsible: true, textSpan: TextSpan.FromBounds((node.CloseParenToken != default) ? node.CloseParenToken.Span.End : node.Expression.Span.End, node.CloseBraceToken.Span.End), hintSpan: node.Span, type: BlockTypes.Conditional)); }