示例#1
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            TextView = AdapterService.GetWpfTextView(textViewAdapter);
            if (TextView == null)
            {
                return;
            }

            TextBuffer = TextView.TextBuffer as ITextBuffer2;
            if (TextBuffer == null)
            {
                return;
            }

            if (TextView.TextBuffer.Properties.ContainsProperty(typeof(ITextDocument)))
            {
                FileName = (TextView.TextBuffer.Properties[typeof(ITextDocument)] as ITextDocument).FilePath;
                if (System.IO.Path.GetExtension(FileName).ToLower() == EditorFactory.Extension.ToLower() &&
                    textViewAdapter.GetBuffer(out IVsTextLines textLines) == VSConstants.S_OK)
                {
                    Model            = ViewModelCoordinator.GetViewModel(FileName, textLines);
                    TextView.Closed += TextViewClosedHandler;
                    TextBuffer.ChangedOnBackground += TextBufferChangedHandler;
                    IsRegisteredForChangeTracking   = true;
                }
            }
        }
示例#2
0
        public async Task InitializeAsync()
        {
            _tempFilePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".py");
            File.WriteAllText(_tempFilePath, string.Empty);

            DocumentUri = new Uri(_tempFilePath);

            _window.SubmissionBufferAdded += OnSubmissionBufferAdded;
            _disposableBag.Add(() => {
                _window.SubmissionBufferAdded -= OnSubmissionBufferAdded;
            });

            _currentInputBuffer     = null;
            _previousCellsLineCount = 0;

            var textDocItem = new LSP.TextDocumentItem {
                Uri     = new Uri(_tempFilePath),
                Text    = string.Empty,
                Version = _version,
            };

            await _client.InvokeTextDocumentDidOpenAsync(new LSP.DidOpenTextDocumentParams {
                TextDocument = textDocItem
            });

            if (_window.CurrentLanguageBuffer is ITextBuffer2 buffer)
            {
                SetCurrentBuffer(buffer);
            }
        }
示例#3
0
 protected override void Dispose(bool disposing)
 {
     if (disposing && Buffer != null)
     {
         Buffer.ChangedOnBackground -= BufferChangedOnBackground;
         Buffer.ContentTypeChanged  -= BufferContentTypeChanged;
         Buffer.Properties.RemoveProperty(GetType());
         Buffer = null;
     }
 }
        public static TParser GetParser <TParser> (ITextBuffer2 buffer) where TParser : BackgroundParser <T>, new()
        {
            var parser = buffer.Properties.GetOrCreateSingletonProperty(nameof(TParser), () => new TParser());

            //avoid capturing by calling this afterwards
            if (parser.Buffer == null)
            {
                parser.Initialize(buffer);
            }
            return(parser);
        }
示例#5
0
        void Initialize(ITextBuffer2 buffer)
        {
            Buffer = buffer;

            // it's not super-important to unsubscribe this, as it has the same lifetime as the buffer.
            buffer.ChangedOnBackground += BufferChangedOnBackground;

            // if the content type changes, discard the parser. it will be recreated if needed anyway.
            buffer.ContentTypeChanged += BufferContentTypeChanged;

            Initialize();
        }
示例#6
0
        private void SetCurrentBuffer(ITextBuffer2 buffer)
        {
            if (_currentInputBuffer != null)
            {
                _currentInputBuffer.ChangedHighPriority -= OnReplInputBufferBackgroundChange;
                _previousCellsLineCount += _currentInputBuffer.CurrentSnapshot.LineCount - 1;
            }

            _currentInputBuffer = buffer;

            buffer.ChangedHighPriority += OnReplInputBufferBackgroundChange;
        }
        public void Dispose()
        {
            if (disposed)
            {
                return;
            }
            disposed = true;

            Buffer.ChangedOnBackground -= BufferChangedOnBackground;
            Buffer.ContentTypeChanged  -= BufferContentTypeChanged;
            Buffer.Properties.RemoveProperty(GetType().Name);
            Buffer = null;
        }
        internal OutliningManager(ITextBuffer editBuffer, ITagAggregator <IOutliningRegionTag> tagAggregator, IEditorOptions options)
        {
            this.editBuffer    = (ITextBuffer2)editBuffer;
            this.tagAggregator = tagAggregator as IAccurateTagAggregator <IOutliningRegionTag>;

            bool keepTrackingCurrent = false;

            if (options != null && options.IsOptionDefined("Stress Test Mode", false))
            {
                keepTrackingCurrent = options.GetOptionValue <bool>("Stress Test Mode");
            }
            collapsedRegionTree = new TrackingSpanTree <Collapsed>(editBuffer, keepTrackingCurrent);

            tagAggregator.BatchedTagsChanged += OutliningRegionTagsChanged;
            this.editBuffer.Changed          += SourceTextChanged;
        }
        void BindActiveDoc(object sender, EventArgs e)
        {
            var doc = IdeApp.Workbench.ActiveDocument;

            if (boundDoc == doc)
            {
                return;
            }

            if (buffer != null)
            {
                buffer.Changed -= ScheduleUpdate;
            }

            boundDoc = doc;
            buffer   = doc.GetContent <ITextBuffer2>();

            if (buffer != null)
            {
                buffer.Changed += ScheduleUpdate;
            }
        }
示例#10
0
 public ForwardParserCache(T engine, ITextBuffer2 buffer)
 {
     this.Parser     = engine;
     this.buffer     = buffer;
     buffer.Changed += BufferChanged;
 }