Example #1
0
        public static string Preview(this AstNode node, CSharpFile file, int maxWidth)
        {
            var startLocation = node.StartLocation;
            var startOffset = file.Document.GetOffset(startLocation.Line, startLocation.Column);
            

            var line = file.Document.GetLineByNumber(startLocation.Line);

            var lineText = file.Document.GetText(line.Offset, line.Length);
            
            if (line.Length < maxWidth)
            {
                // Don't truncate
                return lineText;
            }

            var endLocation = node.EndLocation;
            var endOffset = file.Document.GetOffset(endLocation.Line, endLocation.Column);

            const string ellipsis = "...";

            var charactersEitherSide = (maxWidth - (ellipsis.Length * 2));

            // Place the node text as close as possible to the centre of the returned text
            var start = Math.Max(line.Offset, startOffset - charactersEitherSide); 
            var end = Math.Min(line.EndOffset, endOffset + charactersEitherSide); 

            return ellipsis + file.Document.GetText(start, end - start).Trim() + ellipsis;
        }
Example #2
0
        public void AddFile(string fileName)
        {
            var csharpFile = new CSharpFile(this, fileName);

            Files.Add(csharpFile);
            ProjectContent.AddOrUpdateFiles(new[] { csharpFile.ParsedFile });
        }
Example #3
0
        public OrphanProject(ISolution solution)
        {
            Title = "Orphan Project";
            _file = new CSharpFile(this, "dummy_file", "");
            Files = new List<CSharpFile>();
            Files.Add(_file);

            string mscorlib = CSharpProject.FindAssembly(CSharpProject.AssemblySearchPaths, "mscorlib");
            ProjectContent = new CSharpProjectContent()
                .SetAssemblyName("OrphanProject")
                .AddAssemblyReferences(CSharpProject.LoadAssembly(mscorlib));
        }
Example #4
0
        private CSharpFile GetFile(string fileName, string source)
        {
            var file = Files.FirstOrDefault(f => f.FileName.Equals(fileName, StringComparison.InvariantCultureIgnoreCase));
            if (file == null)
            {
                file = new CSharpFile(this, fileName, source);
                Files.Add (file);

                this.ProjectContent = this.ProjectContent
                    .AddOrUpdateFiles(file.ParsedFile);
            }
            return file;
        }
Example #5
0
        private CSharpFile GetFile(string fileName, string source)
        {
            var file = Files.FirstOrDefault(f => f.FileName.Equals(fileName, StringComparison.InvariantCultureIgnoreCase));

            if (file == null)
            {
                file = new CSharpFile(this, fileName, source);
                Files.Add(file);

                this.ProjectContent
                .AddOrUpdateFiles(file.ParsedFile);
            }
            return(file);
        }
Example #6
0
        public OrphanProject(ISolution solution)
        {
            Title = "Orphan Project";
            _file = new CSharpFile(this, "dummy_file", "");
            Files = new List <CSharpFile>();
            Files.Add(_file);

            ProjectId = Guid.NewGuid();

            string mscorlib = CSharpProject.FindAssembly(CSharpProject.AssemblySearchPaths, "mscorlib");

            ProjectContent = new CSharpProjectContent()
                             .SetAssemblyName("OrphanProject")
                             .AddAssemblyReferences(CSharpProject.LoadAssembly(mscorlib));
        }
Example #7
0
        public static string Preview(this AstNode node, CSharpFile file)
        {
            var location = node.StartLocation;
            var offset = file.Document.GetOffset(location.Line, location.Column);
            var line = file.Document.GetLineByNumber(location.Line);
            if (line.Length < 50)
            {
                return file.Document.GetText(line.Offset, line.Length);
            }

            var start = Math.Max(line.Offset, offset - 60);
            var end = Math.Min(line.EndOffset, offset + 60);

            return "..." + file.Document.GetText(start, end - start).Trim() + "...";
        }
Example #8
0
        /// <summary>
        ///   Initialize a QuickFix pointing to the first line of the
        ///   given region in the given file.
        /// </summary>
        public static QuickFix ForFirstLineInRegion(DomRegion region, CSharpFile file)
        {
            return new QuickFix
                { FileName = region.FileName
                , Line     = region.BeginLine
                , Column   = region.BeginColumn

                // Note that we could display an arbitrary amount of
                // context to the user: ranging from one line to tens,
                // hundreds..
                , Text = file.Document.GetText
                    ( offset: file.Document.GetOffset(region.Begin)
                    , length: file.Document.GetLineByNumber
                                (region.BeginLine).Length)};
        }
Example #9
0
        /// <summary>
        ///   Initialize a QuickFix pointing to the first line of the
        ///   given region in the given file.
        /// </summary>
        public static QuickFix ForFirstLineInRegion
            (DomRegion region, CSharpFile file) {

            return QuickFix.ForFirstLineInRegion
                (region, file.Document);
        }
Example #10
0
 public void AddFile(string fileName)
 {
     var csharpFile = new CSharpFile (this, fileName);
     Files.Add (csharpFile);
     ProjectContent.AddOrUpdateFiles (new[] { csharpFile.ParsedFile });
 }