/// <inheritdoc />
        protected override void ApplyDocumentTextChanged(DocumentId documentId, SourceText text)
        {
            var document = CurrentSolution.GetDocument(documentId);

            if (document != null)
            {
                if (_openedDocs.Values.Contains(documentId) || IsDocumentOpen(documentId))
                {
                    var textBuffer = _threadingContext.JoinableTaskFactory.Run(async() =>
                    {
                        var sourceText    = await document.GetTextAsync().ConfigureAwait(false);
                        var textContainer = sourceText.Container;
                        return(textContainer.TryGetTextBuffer());
                    });

                    UpdateText(textBuffer, text);
                }
                else
                {
                    // The edits would get sent by the co-authoring service to the owner.
                    // The invisible editor saves the file on being disposed, which should get reflected  on the owner's side.
                    using (var invisibleEditor = new InvisibleEditor(_serviceProvider, document.FilePath, hierarchyOpt: null,
                                                                     needsSave: true, needsUndoDisabled: false))
                    {
                        UpdateText(invisibleEditor.TextBuffer, text);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public EnvDTE.TextPoint CreateTextPoint(FileCodeModel fileCodeModel, VirtualTreePoint point)
        {
            if (!fileCodeModel.TryGetDocument(out var document))
            {
                return(null);
            }

            var hierarchyOpt = fileCodeModel.Workspace.GetHierarchy(document.Project.Id);

            using var invisibleEditor = new InvisibleEditor(
                      fileCodeModel.ServiceProvider,
                      document.FilePath,
                      hierarchyOpt,
                      needsSave: false,
                      needsUndoDisabled: false
                      );
            var vsTextLines = invisibleEditor.VsTextLines;

            var line   = point.GetContainingLine();
            var column = point.Position - line.Start + point.VirtualSpaces;

            Marshal.ThrowExceptionForHR(
                vsTextLines.CreateTextPoint(line.LineNumber, column, out var textPoint)
                );
            return((EnvDTE.TextPoint)textPoint);
        }
Ejemplo n.º 3
0
        private string GetSourceLine_MustCallOnUIThread(string filePath, int lineNumber)
        {
            using var invisibleEditor = new InvisibleEditor(
                      _serviceProvider, filePath, hierarchy: null, needsSave: false, needsUndoDisabled: false);
            var vsTextLines = invisibleEditor.VsTextLines;

            if (vsTextLines.GetLengthOfLine(lineNumber, out var lineLength) == VSConstants.S_OK &&
                vsTextLines.GetLineText(lineNumber, 0, lineNumber, lineLength, out var lineText) == VSConstants.S_OK)
            {
                return(lineText);
            }

            return(ServicesVSResources.Preview_unavailable);
        }
        private static string GetSourceLine(string filePath, int lineNumber, IServiceProvider serviceProvider)
        {
            using (var invisibleEditor = new InvisibleEditor(serviceProvider, filePath, needsSave: false, needsUndoDisabled: false))
            {
                var    vsTextLines = invisibleEditor.VsTextLines;
                int    lineLength;
                string lineText;

                if (vsTextLines != null &&
                    vsTextLines.GetLengthOfLine(lineNumber, out lineLength) == VSConstants.S_OK &&
                    vsTextLines.GetLineText(lineNumber, 0, lineNumber, lineLength, out lineText) == VSConstants.S_OK)
                {
                    return(lineText);
                }

                return(ServicesVSResources.PreviewUnavailable);
            }
        }
Ejemplo n.º 5
0
        public EnvDTE.TextPoint CreateTextPoint(FileCodeModel fileCodeModel, VirtualTreePoint point)
        {
            var workspace    = fileCodeModel.Workspace as VisualStudioWorkspaceImpl;
            var hostDocument = workspace.GetHostDocument(fileCodeModel.GetDocumentId());

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

            using (var invisibleEditor = new InvisibleEditor(fileCodeModel.ServiceProvider, hostDocument.FilePath, needsSave: false, needsUndoDisabled: false))
            {
                var vsTextLines = invisibleEditor.VsTextLines;

                var line   = point.GetContainingLine();
                var column = point.Position - line.Start + point.VirtualSpaces;
                Marshal.ThrowExceptionForHR(vsTextLines.CreateTextPoint(line.LineNumber, column, out var textPoint));
                return((EnvDTE.TextPoint)textPoint);
            }
        }