public void ContentTypeIsDeducedFromFileExtension()
        {
            const string fileExtension = ".ext";

            var file = MockFor <IFile>(MockBehavior.Loose);

            file.SetupGet(_ => _.Extension).Returns(fileExtension);
            file.Setup(_ => _.ReadAllText()).Returns("text");

            var contentType = MockFor <IContentType>();

            var contentTypeRegistry = MockFor <IContentTypeRegistry>();

            contentTypeRegistry
            .Setup(_ => _.ForFileExtension(fileExtension))
            .Returns(contentType.Object);

            var factory = new TextDocumentFactory {
                ContentTypeRegistry = contentTypeRegistry.Object
            };
            var document = factory.ForFile(file.Object);

            Assert.AreSame(contentType.Object, document.Buffer.ContentType);

            VerifyAllMocks();
        }
        public ITextViewDocument DocumentForFile(IFile file)
        {
            var document   = TextDocumentFactory.ForFile(file);
            var classifier = ClassifierFor(document.Buffer);
            var caret      = CaretFactory.CaretForBuffer(document.Buffer);

            return(new TextViewDocument(document, caret, classifier, ClassificationStyler));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// On layout change add the adornment to any reformatted lines
        /// </summary>
        private void LayoutChangedHandler(object sender, TextViewLayoutChangedEventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (!Enabled)
            {
                return;
            }

            _errorTags.Clear();
            TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(new SnapshotSpan(_view.TextSnapshot, new Span(0, _view.TextSnapshot.Length))));
            OnTagsChanged(new SnapshotSpan(_view.TextSnapshot, new Span(0, _view.TextSnapshot.Length)));

            foreach (var line in _view.TextViewLines) // TODO [?]: implement more sensible handling of removing error tags, then use e.NewOrReformattedLines
            {
                var lineNumber = line.Snapshot.GetLineFromPosition(line.Start.Position).LineNumber;
                //TODO [?]: Limit rate of calls to the below when user is editing a line
                try
                {
                    ITextDocument textDoc = null;
                    var           success = TextDocumentFactory?.TryGetTextDocument(_view.TextBuffer, out textDoc);
                    CreateVisuals(line, lineNumber, success.HasValue && success.Value && textDoc != null ? textDoc.FilePath : null);
                }
                catch (InvalidOperationException ex)
                {
                    ExceptionHandler.Notify(ex, true);
                }
            }

            // Sometimes, on loading a file in an editor view, the line transform gets triggered before the image adornments
            // have been added, so the lines don't resize to the image height. So here's a workaround:
            // Changing the zoom level triggers the required update.
            // Need to do it twice - once to trigger the event, and again to change it back to the user's expected level.
            if (!_initialised1)
            {
                _view.ZoomLevel++;
                _initialised1 = true;
            }
            if (!_initialised2)
            {
                _view.ZoomLevel--;
                _initialised2 = true;
            }
        }
Ejemplo n.º 4
0
 private void RemoveDocumentFactories()
 {
     _documentService.Factories.Remove(_textDocumentFactory);
     _textDocumentFactory = null;
 }
Ejemplo n.º 5
0
 private void AddDocumentFactories()
 {
     _textDocumentFactory = new TextDocumentFactory(Editor);
     _documentService.Factories.Add(_textDocumentFactory);
 }