private string GetSourceLine(string filePath, int lineNumber)
        {
            using (var invisibleEditor = new InvisibleEditor(
                _serviceProvider, filePath, needsSave: false, needsUndoDisabled: false))
            {
                var vsTextLines = invisibleEditor.VsTextLines;
                if (vsTextLines != null &&
                    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;
            }
        }
Example #2
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;
            }
        }