Exemple #1
0
        private static void SerializeRangeProperty(Range.range range, IFastJsonWriter writer, IFSharpSession session)
        {
            writer.WritePropertyName("range");
            var startOffset = session.ConvertToOffset(range.StartLine, range.StartColumn);
            var endOffset   = session.ConvertToOffset(range.EndLine, range.EndColumn);

            writer.WriteValueFromParts(startOffset, '-', endOffset);
        }
        protected override string GetFormatted(bool isSignatureFile, string source, Fantomas.FormatConfig.FormatConfig config)
        {
            Range.pos   startPos = TextUtils.GetFSharpPos(TextView.Selection.Start);
            Range.pos   endPos   = TextUtils.GetFSharpPos(TextView.Selection.End);
            Range.range range    = Range.mkRange("fsfile", startPos, endPos);

            return(Fantomas.CodeFormatter.formatSelectionFromString(isSignatureFile, range, source, config));
        }
        public static ITrackingSpan RangeToTrackingSpan(Range.range fsrange, ITextSnapshot textSnapshot)
        {
            var from = fsrange.StartLine - 1;
            ITextSnapshotLine anchor = textSnapshot.GetLineFromLineNumber(from);
            var start = anchor.Start.Position + fsrange.StartColumn;
            var to    = fsrange.EndLine - 1;
            var end   = textSnapshot.GetLineFromLineNumber(to).Start.Position + fsrange.EndColumn;

            return(textSnapshot.CreateTrackingSpan(start, end - start, SpanTrackingMode.EdgeExclusive));
        }
        public static SnapshotSpan RangeToSpan(Range.range fsrange, ITextSnapshot textSnapshot)
        {
            var from = fsrange.StartLine - 1;
            ITextSnapshotLine anchor = textSnapshot.GetLineFromLineNumber(from);
            var start = anchor.Start.Position + fsrange.StartColumn;
            var to    = fsrange.EndLine - 1;
            var end   = textSnapshot.GetLineFromLineNumber(to).Start.Position + fsrange.EndColumn;

            return(new SnapshotSpan(textSnapshot, new Span(start, end - start)));
        }
        protected override string GetFormatted(bool isSignatureFile, string source, Fantomas.FormatConfig.FormatConfig config)
        {
            // This still seems to give "The indent level cannot be negative"
            // in a lot of cases that feel like they should work, e.g. 'let' forms

            Range.pos   startPos = TextUtils.GetFSharpPos(TextView.Selection.Start);
            Range.pos   endPos   = TextUtils.GetFSharpPos(TextView.Selection.End);
            Range.range range    = Range.mkRange("fsfile", startPos, endPos);

            return(Fantomas.CodeFormatter.formatSelectionFromString(isSignatureFile, range, source, config));
        }
        private static T FindNode <T>(Range.range range, [CanBeNull] ITreeNode node) where T : class, ITreeNode
        {
            var fsFile   = node?.GetContainingFile() as IFSharpFile;
            var document = fsFile?.GetSourceFile()?.Document;

            if (document == null)
            {
                return(null);
            }

            var idToken = fsFile.FindTokenAt(document.GetTreeEndOffset(range) - 1);

            return(idToken?.GetContainingNode <T>(true));
        }
        protected override string GetFormatted(bool isSignatureFile, string source, Fantomas.FormatConfig.FormatConfig config)
        {
            if (isFormattingCursor)
            {
                var       caretPos = new VirtualSnapshotPoint(TextView.TextBuffer.CurrentSnapshot, TextView.Caret.Position.BufferPosition);
                Range.pos pos      = TextUtils.GetFSharpPos(caretPos);
                return(Fantomas.CodeFormatter.formatAroundCursor(isSignatureFile, pos, source, config));
            }

            Range.pos   startPos = TextUtils.GetFSharpPos(TextView.Selection.Start);
            Range.pos   endPos   = TextUtils.GetFSharpPos(TextView.Selection.End);
            Range.range range    = Range.mkRange("fsfile", startPos, endPos);

            return(Fantomas.CodeFormatter.formatSelectionFromString(isSignatureFile, range, source, config));
        }
 public static int GetStartOffset(this IDocument document, Range.range range) =>
 document.GetOffset(range.Start);
 public static int GetEndOffset(this IDocument document, Range.range range) =>
 document.GetOffset(range.End);
 public static bool Contains(this Range.range range, DocumentCoords coords) =>
 range.StartLine - 1 >= (int)coords.Line && range.EndLine - 1 <= (int)coords.Line &&
 range.StartColumn >= (int)coords.Column && range.EndColumn <= (int)coords.Column;
 public static Column GetEndColumn(this Range.range range)
 {
     return((Column)range.EndColumn);
 }
 public static Column GetStartColumn(this Range.range range)
 {
     return((Column)range.StartColumn);
 }
 public static Line GetEndLine(this Range.range range)
 {
     // FCS lines are 1-based
     return((Line)(range.EndLine - 1));
 }
 public static TreeOffset GetTreeEndOffset([NotNull] this IDocument document, Range.range range)
 {
     return(GetTreeOffset(document, range.GetEndLine(), range.GetEndColumn()));
 }
 void OnNavigateToLine(object sender, Range.range r)
 {
     Snuup.Package.Instance.NavigateTo(this.astmgr.Filename, r.StartLine - 1, r.StartColumn, r.EndLine - 1, r.EndColumn);
     Snuup.Package.Instance.ShowFileStructureToolWindow();
 }