예제 #1
0
        public void AddAnchorIndentationOperation(AnchorIndentationOperation operation)
        {
            // don't add stuff if it is empty
            if (operation.TextSpan.IsEmpty ||
                _anchorMap.Contains(operation.TextSpan) ||
                _anchorBaseTokenMap.ContainsKey(operation.AnchorToken))
            {
                return;
            }

            // If the indentation changes on a line which other code is anchored to, adjust those other lines to reflect
            // the same change in indentation. Note that we anchor to the first token on a line to account for common
            // cases like the following code, where the `{` token is anchored to the `(` token of `()`:
            //
            //                ↓ this space can be removed, which moves `(` one character to the left
            // var x = Method( () =>
            // {
            // ↑ this `{` anchors to `var` instead of `(`, which prevents it from moving when `(` is moved
            // });
            //
            // The calculation of true anchor token (which is always the first token on a line) is delayed to account
            // for cases where the original anchor token is moved to a new line during a formatting operation.
            var anchorToken   = _tokenStream.FirstTokenOfBaseTokenLine(operation.AnchorToken);
            var originalSpace = _tokenStream.GetOriginalColumn(anchorToken);
            var data          = new AnchorData(operation, anchorToken, originalSpace);

            _anchorTree.AddIntervalInPlace(data);

            _anchorBaseTokenMap.Add(operation.AnchorToken, data);
            _anchorMap.Add(operation.TextSpan);
        }
예제 #2
0
        public void AddAnchorIndentationOperation(AnchorIndentationOperation operation)
        {
            // don't add stuff if it is empty
            if (operation.TextSpan.IsEmpty ||
                this.anchorMap.Contains(operation.TextSpan) ||
                this.anchorBaseTokenMap.ContainsKey(operation.AnchorToken))
            {
                return;
            }

            var originalSpace = this.tokenStream.GetOriginalColumn(operation.StartToken);
            var data          = new AnchorData(operation, originalSpace);

            this.anchorTree.AddIntervalInPlace(data);

            this.anchorBaseTokenMap.Add(operation.AnchorToken, data);
            this.anchorMap.Add(operation.TextSpan);
        }
예제 #3
0
 public AnchorData(AnchorIndentationOperation operation, int originalColumn)
 {
     _operation          = operation;
     this.OriginalColumn = originalColumn;
 }
 public AnchorData(AnchorIndentationOperation operation, SyntaxToken anchorToken, int originalColumn)
 {
     _operation          = operation;
     this.AnchorToken    = anchorToken;
     this.OriginalColumn = originalColumn;
 }