Ejemplo n.º 1
0
            private void SaveCopyData(ITextBuffer subjectBuffer)
            {
                var selection = view.Selection;
                var spans     = selection.GetSnapshotSpansOnBuffer(subjectBuffer);

                if (spans.Count() != 1)
                {
                    return;
                }

                var document = subjectBuffer.CurrentSnapshot.GetRelatedDocumentsWithChanges().FirstOrDefault();

                if (document == null)
                {
                    return;
                }

                if (document.SourceCodeKind != SourceCodeKind.Regular)
                {
                    return;
                }

                var span = spans.Select(s => new Microsoft.CodeAnalysis.Text.TextSpan(s.Start, s.Length)).First();

                if (span.IsEmpty)
                {
                    return;
                }

                var text = document.GetTextAsync().Result.ToString().Substring(span.Start, span.Length);

                var offsetMap = CopyData.CreateOffsetMap(document, span);

                this.copyDataService.SaveData(new CopyData(text, offsetMap));
            }
Ejemplo n.º 2
0
 public void SaveData(CopyData data)
 {
     lock (this.syncLock)
     {
         this.data = data;
     }
 }
Ejemplo n.º 3
0
        private static Document ForkNewDocument(CopyData copyData, Document document, TextSpan span)
        {
            // here we assume paste data is what is copied before.
            // we will check this assumption when things are actually pasted.
            var newText = document.GetTextAsync().Result.ToString().Remove(span.Start, span.Length).Insert(span.Start, copyData.Text);

            // fork solution
            return(document.WithText(SourceText.From(newText)));
        }
Ejemplo n.º 4
0
        public CopyDataService()
        {
            this.data = null;

#if false
            Workspace.PrimaryWorkspace.WorkspaceChanged += (sender, args) =>
            {
                SaveData(null);
            };
#endif
        }
Ejemplo n.º 5
0
        public bool CheckApplicable(ITextBuffer subjectBuffer, CopyData copyData)
        {
            if (copyData == null)
            {
                return(false);
            }

            var selection = view.Selection;
            var spans     = selection.GetSnapshotSpansOnBuffer(subjectBuffer);

            if (spans.Count() != 1)
            {
                return(false);
            }

            var document = subjectBuffer.CurrentSnapshot.GetRelatedDocumentsWithChanges().FirstOrDefault();

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

            if (document.SourceCodeKind != SourceCodeKind.Regular)
            {
                return(false);
            }

            var span    = spans.Select(s => new TextSpan(s.Start, s.Length)).First();
            var newSpan = new TextSpan(span.Start, copyData.Text.Length);

            var newDocument = ForkNewDocument(copyData, document, span);

            // analyze in new document
            var newOffsetMap = CopyData.CreateOffsetMap(newDocument, newSpan);

            foreach (var pair in copyData)
            {
                var offset = pair.Key;
                var token  = pair.Value.Item1;
                var symbol = pair.Value.Item2;

                // check whether existing symbol is same one
                if (IsSameSymbol(offset, token, symbol, newOffsetMap))
                {
                    continue;
                }

                // missing using,
            }

            return(false);
        }
Ejemplo n.º 6
0
 public void Apply(ITextBuffer buffer, CopyData copyData)
 {
     throw new NotImplementedException();
 }