Exemplo n.º 1
0
        internal Session(
            string name,
            IReadOnlyCollection <AnnotatedCodeBlock> codeBlocks,
            MarkdownFile markdownFile)
        {
            Name         = name;
            CodeBlocks   = codeBlocks;
            MarkdownFile = markdownFile;

            var projectOrPackageNames = codeBlocks
                                        .Select(block => block.ProjectOrPackageName())
                                        .Distinct()
                                        .ToArray();

            if (projectOrPackageNames.Length == 1)
            {
                ProjectOrPackageName = projectOrPackageNames[0];
            }
            else
            {
                ProjectOrPackageName = projectOrPackageNames.FirstOrDefault();
            }

            Language = CodeBlocks
                       .Select(b => b.Language())
                       .FirstOrDefault(n => !string.IsNullOrWhiteSpace(n));
        }
Exemplo n.º 2
0
        public bool TryGetMarkdownFile(RelativeFilePath path, out MarkdownFile markdownFile)
        {
            if (!DirectoryAccessor.FileExists(path) || path.Extension != ".md")
            {
                markdownFile = null;
                return(false);
            }

            markdownFile = new MarkdownFile(path, this);
            return(true);
        }
        public static Buffer GetBufferAsync(
            this AnnotatedCodeBlock block,
            IDirectoryAccessor directoryAccessor,
            MarkdownFile markdownFile)
        {
            if (block.Annotations is LocalCodeBlockAnnotations localOptions)
            {
                var absolutePath = directoryAccessor.GetFullyQualifiedPath(localOptions.SourceFile).FullName;
                var bufferId     = new BufferId(absolutePath, block.Annotations.Region);
                return(new Buffer(bufferId, block.SourceCode));
            }

            return(null);
        }
Exemplo n.º 4
0
        public async Task <Workspace> GetWorkspaceAsync()
        {
            var(buffersToInclude, filesToInclude) = await MarkdownFile.GetIncludes(MarkdownFile.Project.DirectoryAccessor);

            var markdownFileDir = MarkdownFile.Project.DirectoryAccessor.GetDirectoryAccessorForRelativePath(MarkdownFile.Path.Directory);

            var buffers = CodeBlocks
                          .Where(b => b.Annotations is CodeBlockAnnotations a && a.Editable)
                          .Select(block => block.GetBufferAsync(markdownFileDir))
                          .ToList();

            var files = new List <File>();

            if (filesToInclude.TryGetValue("global", out var globalIncludes))
            {
                files.AddRange(globalIncludes);
            }

            if (!string.IsNullOrWhiteSpace(Name) && filesToInclude.TryGetValue(Name, out var sessionIncludes))
            {
                files.AddRange(sessionIncludes);
            }

            if (buffersToInclude.TryGetValue("global", out var globalSessionBuffersToInclude))
            {
                buffers.AddRange(globalSessionBuffersToInclude);
            }

            if (!string.IsNullOrWhiteSpace(Name) && buffersToInclude.TryGetValue(Name, out var localSessionBuffersToInclude))
            {
                buffers.AddRange(localSessionBuffersToInclude);
            }

            var workspace = new Workspace(
                workspaceType: ProjectOrPackageName,
                language: Language,
                files: files.ToArray(),
                buffers: buffers.ToArray());

            workspace = await workspace
                        .MergeAsync()
                        .InlineBuffersAsync();

            return(workspace);
        }