'use strict' ; import * as fs from 'fs' ; import * as path from 'path' ; import { QuickPickItem , Uri , workspace } from 'vscode' ; /**
 * Configuration for how to transform rst files to html. Either use Sphinx
 * with a gven conf.py file, or use docutils without any configuration
 */ export class RstTransformerConfig implements QuickPickItem { public label : string ; public description : string = 'Use Sphinx with the selected conf.py path' ; public confPyDirectory : string ; public workspaceRoot : string ; } /**
 * Returns a list of conf.py files in the workspace
 */ export async function findConfPyFiles ( resource ) { if ( ! workspace . workspaceFolders ) { return [ ] ; } const items = await workspace . findFiles ( '{**/conf.py}' , '{}' , 100 ) ; return urisToPaths ( items , resource ) ; } function urisToPaths ( uris , resource ) { const paths = [ ] ; const workspaceFolder = workspace . getWorkspaceFolder ( resource ) ; uris . forEach ( ( uri ) => { const folder = workspace . getWorkspaceFolder ( uri ) ; if ( folder === workspaceFolder ) { paths . push ( uri . fsPath ) ; } } ) ; return paths ; } /**
 * Find conf.py files by looking at parent directories. Useful in case
 * a single rst file is opened without a workspace
 */ export function findConfPyFilesInParentDirs ( rstPath ) { const paths = [ ] ; let dirName = rstPath ; while ( true ) { const parentDir = path . normalize ( dirName + '/..' ) ; if ( parentDir === dirName ) { break ; } if ( ! fs . existsSync ( parentDir ) || ! fs . statSync ( parentDir ) . isDirectory ) { break ; } const confPath = path . join ( parentDir , 'conf.py' ) ; if ( fs . existsSync ( confPath ) && fs . statSync ( confPath ) . isFile ) { paths . push ( confPath ) ; } dirName = parentDir ; } return paths ; }