Esempio n. 1
0
        public void SimpleDocument()
        {
            string    text     = "Hello\nWorld!\r\n";
            IDocument document = DocumentUtilitites.LoadReadOnlyDocumentFromBuffer(new StringTextBuffer(text));

            Assert.AreEqual(text, document.Text);
            Assert.AreEqual(3, document.TotalNumberOfLines);

            Assert.AreEqual(0, document.GetLine(1).Offset);
            Assert.AreEqual(5, document.GetLine(1).EndOffset);
            Assert.AreEqual(5, document.GetLine(1).Length);
            Assert.AreEqual(6, document.GetLine(1).TotalLength);
            Assert.AreEqual(1, document.GetLine(1).DelimiterLength);
            Assert.AreEqual(1, document.GetLine(1).LineNumber);

            Assert.AreEqual(6, document.GetLine(2).Offset);
            Assert.AreEqual(12, document.GetLine(2).EndOffset);
            Assert.AreEqual(6, document.GetLine(2).Length);
            Assert.AreEqual(8, document.GetLine(2).TotalLength);
            Assert.AreEqual(2, document.GetLine(2).DelimiterLength);
            Assert.AreEqual(2, document.GetLine(2).LineNumber);

            Assert.AreEqual(14, document.GetLine(3).Offset);
            Assert.AreEqual(14, document.GetLine(3).EndOffset);
            Assert.AreEqual(0, document.GetLine(3).Length);
            Assert.AreEqual(0, document.GetLine(3).TotalLength);
            Assert.AreEqual(0, document.GetLine(3).DelimiterLength);
            Assert.AreEqual(3, document.GetLine(3).LineNumber);
        }
        public void Initialize(IDocument document)
        {
            if (changeList != null && changeList.Any())
            {
                return;
            }

            this.document     = document;
            this.textDocument = (TextDocument)document.GetService(typeof(TextDocument));
            this.changeList   = new CompressingTreeList <LineChangeInfo>((x, y) => x.Equals(y));

            Stream baseFileStream = GetBaseVersion();

            // TODO : update baseDocument on VCS actions
            if (baseFileStream != null)
            {
                // ReadAll() is taking care of closing the stream
                baseDocument = DocumentUtilitites.LoadReadOnlyDocumentFromBuffer(new StringTextBuffer(ReadAll(baseFileStream)));
            }
            else
            {
                if (baseDocument == null)
                {
                    // if the file is not under subversion, the document is the opened document
                    var doc = new TextDocument(textDocument.Text);
                    baseDocument = new AvalonEditDocumentAdapter(doc, null);
                }
            }

            SetupInitialFileState(false);

            this.textDocument.LineTrackers.Add(this);
            this.textDocument.UndoStack.PropertyChanged += UndoStackPropertyChanged;
        }
Esempio n. 3
0
        public void EmptyReadOnlyDocument()
        {
            IDocument document = DocumentUtilitites.LoadReadOnlyDocumentFromBuffer(new StringTextBuffer(string.Empty));

            Assert.AreEqual(string.Empty, document.Text);
            Assert.AreEqual(0, document.TextLength);
            Assert.AreEqual(1, document.TotalNumberOfLines);
            Assert.AreEqual(0, document.PositionToOffset(1, 1));
            Assert.AreEqual(new Location(1, 1), document.OffsetToPosition(0));

            Assert.AreEqual(0, document.GetLine(1).Offset);
            Assert.AreEqual(0, document.GetLine(1).EndOffset);
            Assert.AreEqual(0, document.GetLine(1).Length);
            Assert.AreEqual(0, document.GetLine(1).TotalLength);
            Assert.AreEqual(0, document.GetLine(1).DelimiterLength);
            Assert.AreEqual(1, document.GetLine(1).LineNumber);
        }
        void InitializeBaseDocument()
        {
            Stream baseFileStream = GetBaseVersion();

            if (baseFileStream != null)
            {
                // ReadAll() is taking care of closing the stream
                baseDocument = DocumentUtilitites.LoadReadOnlyDocumentFromBuffer(new StringTextBuffer(ReadAll(baseFileStream)));
            }
            else
            {
                // if the file is not under subversion, the document is the opened document
                if (baseDocument == null)
                {
                    baseDocument = DocumentUtilitites.LoadReadOnlyDocumentFromBuffer(document.CreateSnapshot());
                }
            }
        }
        public ICompilationUnit Parse(
            IProjectContent projectContent,
            string fileName,
            ITextBuffer fileContent,
            IEnumerable <TypeScriptFile> files)
        {
            try {
                using (TypeScriptContext context = contextFactory.CreateContext()) {
                    var file = new FileName(fileName);
                    context.AddFile(file, fileContent.Text);
                    context.RunInitialisationScript();

                    NavigationBarItem[] navigation = context.GetNavigationInfo(file);
                    var unit = new TypeScriptCompilationUnit(projectContent)
                    {
                        FileName = fileName
                    };
                    unit.AddNavigation(navigation, fileContent);

                    var typeScriptProjectContent = projectContent as TypeScriptProjectContent;
                    if (typeScriptProjectContent != null)
                    {
                        context.AddFiles(files);
                        IDocument    document    = DocumentUtilitites.LoadReadOnlyDocumentFromBuffer(fileContent);
                        Diagnostic[] diagnostics = context.GetDiagnostics(file, typeScriptProjectContent.Options);
                        TypeScriptService.TaskService.Update(diagnostics, file, document);
                    }

                    return(unit);
                }
            } catch (Exception ex) {
                Console.WriteLine(ex.ToString());
                LoggingService.Debug(ex.ToString());
            }
            return(new DefaultCompilationUnit(projectContent));
        }
Esempio n. 6
0
            public SearchResultMatch FindNext()
            {
                // Setup search inside current or first file.
                SearchableFileContentFinder finder = new SearchableFileContentFinder();
                int index        = GetCurrentFileIndex();
                int i            = 0;
                int searchOffset = 0;

                SearchResultMatch result = null;

                if (index > -1)
                {
                    ITextEditor editor = GetActiveTextEditor();
                    if (editor.SelectionLength > 0)
                    {
                        searchOffset = editor.SelectionStart + editor.SelectionLength;
                    }
                    else
                    {
                        searchOffset = editor.Caret.Offset + 1;
                    }
                    var document = editor.Document;

                    int length;
                    // if (target == SearchTarget.CurrentSelection) selection will not be null
                    // hence use the selection as search region.
                    if (location.Selection != null)
                    {
                        searchOffset = Math.Max(location.Selection.Offset, searchOffset);
                        length       = location.Selection.EndOffset - searchOffset;
                    }
                    else
                    {
                        length = document.TextLength - searchOffset;
                    }

                    // try to find a result
                    if (length > 0 && (searchOffset + length) <= document.TextLength)
                    {
                        result = Find(editor.FileName, document, searchOffset, length);
                    }
                }

                // try the other files until we find something, or have processed all of them
                while (result == null && i < files.Length)
                {
                    index = (index + 1) % files.Length;

                    FileName    file   = files[index];
                    ITextBuffer buffer = finder.Create(file);

                    if (buffer == null)
                    {
                        continue;
                    }
                    int length;
                    if (location.Selection != null)
                    {
                        searchOffset = location.Selection.Offset;
                        length       = location.Selection.Length;
                    }
                    else
                    {
                        searchOffset = 0;
                        length       = buffer.TextLength;
                    }

                    // try to find a result
                    result = Find(file, DocumentUtilitites.LoadReadOnlyDocumentFromBuffer(buffer), searchOffset, length);

                    i++;
                }

                return(result);
            }
Esempio n. 7
0
        public void AddNavigation(NavigationBarItem[] navigation, ITextBuffer textBuffer)
        {
            IDocument document = DocumentUtilitites.LoadReadOnlyDocumentFromBuffer(textBuffer);

            AddNavigationInfo(navigation, document);
        }