protected AbstractConvertAnonymousTypeToTupleDiagnosticAnalyzer(ISyntaxKindsService syntaxKinds) : base(IDEDiagnosticIds.ConvertAnonymousTypeToTupleDiagnosticId, option: null, new LocalizableResourceString(nameof(FeaturesResources.Convert_to_tuple), FeaturesResources.ResourceManager, typeof(FeaturesResources)), new LocalizableResourceString(nameof(FeaturesResources.Convert_to_tuple), FeaturesResources.ResourceManager, typeof(FeaturesResources))) { _syntaxKinds = syntaxKinds; }
private static bool IsEndOfLine(ISyntaxKindsService syntaxKinds, SyntaxTriviaList triviaList, int index) { if (index >= triviaList.Count) { return(false); } var trivia = triviaList[index]; return(trivia.RawKind == syntaxKinds.EndOfLineTrivia); }
protected sealed override int GetLogicalExpressionKind(ISyntaxKindsService syntaxKinds) => syntaxKinds.LogicalAndExpression;
protected abstract int GetLogicalExpressionKind(ISyntaxKindsService syntaxKinds);
private static SyntaxTriviaList UpdateLeadingTrivia(ISyntaxKindsService syntaxKinds, SyntaxTriviaList triviaList) { using var _ = ArrayBuilder <SyntaxTrivia> .GetInstance(out var builder); var currentStart = 0; while (currentStart < triviaList.Count) { var trivia = triviaList[currentStart]; builder.Add(trivia); // If it's not an end of line, just keep going. if (trivia.RawKind != syntaxKinds.EndOfLineTrivia) { currentStart++; continue; } // We have a newlines. Walk forward to get to the last newline in this sequence. var currentEnd = currentStart + 1; while (currentEnd < triviaList.Count && IsEndOfLine(syntaxKinds, triviaList, currentEnd)) { currentEnd++; } var newLineCount = currentEnd - currentStart; if (newLineCount == 1) { // only a single newline. keep as is. currentStart = currentEnd; continue; } // we have two or more newlines. We have three cases to handle: // // 1. We're at the start of the token's trivia. Collapse this down to 1 blank line. // 2. We follow structured trivia (i.e. pp-directive or doc comment). These already end with a newline, // so we only need to add one newline to get a blank line. // 3. We follow something else. We only want to collapse if we have 3 or more newlines. if (currentStart == 0) { // case 1. // skip the second newline onwards. currentStart = currentEnd; continue; } if (triviaList[currentStart - 1].HasStructure) { // case 2. // skip the second newline onwards currentStart = currentEnd; continue; } if (newLineCount >= 3) { // case 3. We want to keep the first two newlines to end up with one blank line, // and then skip the rest. builder.Add(triviaList[currentStart + 1]); currentStart = currentEnd; continue; } // for anything else just add the trivia and move forward like normal. currentStart++; } return(new SyntaxTriviaList(builder.ToImmutable())); }
private int InvertedKind(ISyntaxKindsService syntaxKinds, int binaryExprKind) => binaryExprKind == syntaxKinds.LogicalAndExpression ? syntaxKinds.LogicalOrExpression : syntaxKinds.LogicalAndExpression;
private string GetTitle(ISyntaxKindsService syntaxKinds, int binaryExprKind) => string.Format(FeaturesResources.Replace_0_with_1, GetOperatorText(syntaxKinds.Convert <TSyntaxKind>(binaryExprKind)), GetOperatorText(syntaxKinds.Convert <TSyntaxKind>(InvertedKind(syntaxKinds, binaryExprKind))));
protected AbstractResolveConflictMarkerCodeFixProvider( ISyntaxKindsService syntaxKinds, string diagnosticId) { FixableDiagnosticIds = ImmutableArray.Create(diagnosticId); _syntaxKinds = syntaxKinds; }
private CompletionItem GetCompletionItem(SyntaxToken token, SyntaxGenerator generator, ISyntaxKindsService syntaxKinds, ISyntaxFactsService syntaxFacts) { var shouldMakeContainerAsync = ShouldMakeContainerAsync(token, generator); var text = syntaxFacts.GetText(syntaxKinds.AwaitKeyword); return(CommonCompletionItem.Create( displayText: text, displayTextSuffix: "", rules: CompletionItemRules.Default, Glyph.Keyword, description: RecommendedKeyword.CreateDisplayParts(text, FeaturesResources.Asynchronously_waits_for_the_task_to_finish), inlineDescription: shouldMakeContainerAsync ? FeaturesResources.Make_containing_scope_async : null, isComplexTextEdit: shouldMakeContainerAsync)); }