/// <summary> /// Returns the text changes necessary to format the document after the user enters a /// character. The position provided is the position of the caret in the document after /// the character been inserted into the document. /// </summary> public static async Task <ImmutableArray <TextChange> > GetFormattingChangesAsync( Document document, char typedChar, int position, RazorIndentationOptions indentationOptions, RazorAutoFormattingOptions autoFormattingOptions, FormattingOptions.IndentStyle indentStyle, CancellationToken cancellationToken) { Contract.ThrowIfFalse(document.Project.Language is LanguageNames.CSharp); var formattingService = document.GetRequiredLanguageService <ISyntaxFormattingService>(); var documentSyntax = await ParsedDocument.CreateAsync(document, cancellationToken).ConfigureAwait(false); if (!formattingService.ShouldFormatOnTypedCharacter(documentSyntax, typedChar, position, cancellationToken)) { return(ImmutableArray <TextChange> .Empty); } var formattingOptions = GetFormattingOptions(indentationOptions); var roslynIndentationOptions = new IndentationOptions(formattingOptions) { AutoFormattingOptions = autoFormattingOptions.UnderlyingObject, IndentStyle = (FormattingOptions2.IndentStyle)indentStyle }; return(formattingService.GetFormattingChangesOnTypedCharacter(documentSyntax, position, roslynIndentationOptions, cancellationToken)); }
private Indenter GetIndenter( Document document, int lineNumber, FormattingOptions.IndentStyle indentStyle, CancellationToken cancellationToken ) { var documentOptions = document .GetOptionsAsync(cancellationToken) .WaitAndGetResult_CanCallOnBackground(cancellationToken); var syntacticDoc = SyntacticDocument .CreateAsync(document, cancellationToken) .WaitAndGetResult_CanCallOnBackground(cancellationToken); var sourceText = syntacticDoc.Root.SyntaxTree.GetText(cancellationToken); var lineToBeIndented = sourceText.Lines[lineNumber]; var formattingRules = GetFormattingRules(document, lineToBeIndented.Start, indentStyle); return(new Indenter( this, syntacticDoc, formattingRules, documentOptions, lineToBeIndented, cancellationToken )); }
public IndentationResult GetIndentation( Document document, int lineNumber, FormattingOptions.IndentStyle indentStyle, CancellationToken cancellationToken ) { var indenter = GetIndenter(document, lineNumber, indentStyle, cancellationToken); if (indentStyle == FormattingOptions.IndentStyle.None) { // If there is no indent style, then do nothing. return(new IndentationResult(basePosition: 0, offset: 0)); } if ( indentStyle == FormattingOptions.IndentStyle.Smart && indenter.TryGetSmartTokenIndentation(out var indentationResult) ) { return(indentationResult); } // If the indenter can't produce a valid result, just default to 0 as our indentation. return(indenter.GetDesiredIndentation(indentStyle) ?? default); }
public IndentationResult?GetDesiredIndentation( FormattingOptions.IndentStyle indentStyle ) { // If the caller wants no indent, then we'll return an effective '0' indent. if (indentStyle == FormattingOptions.IndentStyle.None) { return(null); } // If the user has explicitly set 'block' indentation, or they're in an inactive preprocessor region, // then just do simple block indentation. if ( indentStyle == FormattingOptions.IndentStyle.Block || _syntaxFacts.IsInInactiveRegion( Document.SyntaxTree, LineToBeIndented.Start, this.CancellationToken ) ) { return(GetDesiredBlockIndentation()); } Debug.Assert(indentStyle == FormattingOptions.IndentStyle.Smart); return(GetDesiredSmartIndentation()); }
public SimpleStringSplitter( Document document, int position, SyntaxNode root, SourceText sourceText, SyntaxToken token, bool useTabs, int tabSize, FormattingOptions.IndentStyle indentStyle, CancellationToken cancellationToken) : base(document, position, root, sourceText, useTabs, tabSize, indentStyle, cancellationToken) { _token = token; }
private IEnumerable <AbstractFormattingRule> GetFormattingRules( Document document, int position, FormattingOptions.IndentStyle indentStyle ) { var workspace = document.Project.Solution.Workspace; var formattingRuleFactory = workspace.Services.GetRequiredService <IHostDependentFormattingRuleFactoryService>(); var baseIndentationRule = formattingRuleFactory.CreateRule(document, position); var formattingRules = new[] { baseIndentationRule, this.GetSpecializedIndentationFormattingRule(indentStyle) }.Concat(Formatter.GetDefaultFormattingRules(document)); return(formattingRules); }
protected override AbstractFormattingRule GetSpecializedIndentationFormattingRule(FormattingOptions.IndentStyle indentStyle) { return(s_instance); }
private BraceCompletionFormattingRule(FormattingOptions.IndentStyle indentStyle) { _indentStyle = indentStyle; }
protected abstract AbstractFormattingRule GetSpecializedIndentationFormattingRule(FormattingOptions.IndentStyle indentStyle);
private BraceCompletionFormattingRule(FormattingOptions.IndentStyle indentStyle, CSharpSyntaxFormattingOptions options) { _indentStyle = indentStyle; _options = options; }
public BraceCompletionFormattingRule(FormattingOptions.IndentStyle indentStyle) : this(indentStyle, CSharpSyntaxFormattingOptions.Default) { }
public IndentationResult GetIndentation(Document document, int lineNumber, FormattingOptions.IndentStyle indentStyle, CancellationToken cancellationToken) { // all F# documents should have a file path if (document.FilePath == null) { return(default);
IndentationResult IIndentationService.GetBlankLineIndentation( Document document, int lineNumber, FormattingOptions.IndentStyle indentStyle, CancellationToken cancellationToken) { return(default);