function addProject(item, languageClient, extensionContext) {
    const userOverridePath = path.join(extensionContext.storagePath, "addProjectConfigurations.json");
    const addProjectConfigurationFile = fs.existsSync(userOverridePath) ? userOverridePath : extensionContext.asAbsolutePath("ProjectManagement\\addProjectConfigurations.json");
    let addProjectConfigurations;
    try {
        addProjectConfigurations = require(addProjectConfigurationFile);
    }
    catch (_a) {
        vscode_1.window.showErrorMessage(`The add project configuration file '${addProjectConfigurationFile}' cannot be parsed.`);
    }
    const quickPickItems = addProjectConfigurations.configurations.map(configuration => {
        return {
            description: configuration.description,
            label: configuration.quickPickLabel,
            snippet: configuration.snippet
        };
    });
    // As the user which project type.
    vscode_1.window.showQuickPick(quickPickItems, { placeHolder: "Choose project type to create" }).then((pickedItem) => {
        if (!pickedItem) {
            return;
        }
        const quickPickItem = pickedItem;
        const projectBaseUri = path.dirname(item.descriptor().configFilename).toLowerCase();
        const openDialogUri = vscode_1.Uri.parse("file:///" + projectBaseUri);
        // Let the user pick a destination folder based on the module configuration directory.
        vscode_1.window.showOpenDialog({
            canSelectFiles: false,
            canSelectFolders: true,
            canSelectMany: false,
            defaultUri: openDialogUri,
            openLabel: "Select folder"
        }).then((folders) => {
            // This will return undefined on cancel and we only support one file.
            if (folders && folders.length === 1) {
                let newProjectFilePath = path.join(folders[0].fsPath, "sources.bp").toLowerCase();
                if (!newProjectFilePath.startsWith(projectBaseUri)) {
                    vscode_1.window.showWarningMessage("Project must be under module configuration path: " + projectBaseUri);
                    return;
                }
                // Don't overwrite a file if it already exists.
                if (fs.existsSync(newProjectFilePath)) {
                    vscode_1.window.showWarningMessage("Project file already exists at: " + newProjectFilePath);
                    return;
                }
                // Create a new file with the untitled "schema". This
                // causes VSCode to create the file in the editor but
                // does not commit it do disk.
                let newUri = vscode_1.Uri.parse("untitled:" + newProjectFilePath);
                vscode_1.workspace.openTextDocument(newUri).then((textDoc) => {
                    vscode_1.window.showTextDocument(textDoc).then((editor) => {
                        const totalSnippet = quickPickItem.snippet.join("\r\n");
                        editor.insertSnippet(new vscode_1.SnippetString(totalSnippet)).then(() => {
                            // This can probably be done in the Language Server itself.
                            findClosestProjectListFile(newProjectFilePath).then((buildListPath) => {
                                languageClient.sendRequest(AddProjectRequest, {
                                    moduleFilename: item.descriptor().configFilename,
                                    projectFilename: newProjectFilePath
                                });
                            });
                        });
                    });
                });
            }
        });
    });
}
/**
 * Called by the DScript.addProject command which is invoked
 * from the context menu in the project browser.
 * @param item The tree item that represents the module.
 */
Called by the DScript.addProject command which is invoked
from the context menu in the project browser.
@param item The tree item that represents the module.
Called by the DScript . addProject command which is invoked from the context menu in the project browser . @param item The tree item that represents the module .
function addProject(item, languageClient, extensionContext) {
    const userOverridePath = path.join(extensionContext.storagePath, "addProjectConfigurations.json");
    const addProjectConfigurationFile = fs.existsSync(userOverridePath) ? userOverridePath : extensionContext.asAbsolutePath("ProjectManagement\\addProjectConfigurations.json");
    let addProjectConfigurations;
    try {
        addProjectConfigurations = require(addProjectConfigurationFile);
    }
    catch (_a) {
        vscode_1.window.showErrorMessage(`The add project configuration file '${addProjectConfigurationFile}' cannot be parsed.`);
    }
    const quickPickItems = addProjectConfigurations.configurations.map(configuration => {
        return {
            description: configuration.description,
            label: configuration.quickPickLabel,
            snippet: configuration.snippet
        };
    });
    vscode_1.window.showQuickPick(quickPickItems, { placeHolder: "Choose project type to create" }).then((pickedItem) => {
        if (!pickedItem) {
            return;
        }
        const quickPickItem = pickedItem;
        const projectBaseUri = path.dirname(item.descriptor().configFilename).toLowerCase();
        const openDialogUri = vscode_1.Uri.parse("file:///" + projectBaseUri);
        vscode_1.window.showOpenDialog({
            canSelectFiles: false,
            canSelectFolders: true,
            canSelectMany: false,
            defaultUri: openDialogUri,
            openLabel: "Select folder"
        }).then((folders) => {
            if (folders && folders.length === 1) {
                let newProjectFilePath = path.join(folders[0].fsPath, "sources.bp").toLowerCase();
                if (!newProjectFilePath.startsWith(projectBaseUri)) {
                    vscode_1.window.showWarningMessage("Project must be under module configuration path: " + projectBaseUri);
                    return;
                }
                if (fs.existsSync(newProjectFilePath)) {
                    vscode_1.window.showWarningMessage("Project file already exists at: " + newProjectFilePath);
                    return;
                }
                let newUri = vscode_1.Uri.parse("untitled:" + newProjectFilePath);
                vscode_1.workspace.openTextDocument(newUri).then((textDoc) => {
                    vscode_1.window.showTextDocument(textDoc).then((editor) => {
                        const totalSnippet = quickPickItem.snippet.join("\r\n");
                        editor.insertSnippet(new vscode_1.SnippetString(totalSnippet)).then(() => {
                            findClosestProjectListFile(newProjectFilePath).then((buildListPath) => {
                                languageClient.sendRequest(AddProjectRequest, {
                                    moduleFilename: item.descriptor().configFilename,
                                    projectFilename: newProjectFilePath
                                });
                            });
                        });
                    });
                });
            }
        });
    });
}
function addProject ( item , languageClient , extensionContext ) { const userOverridePath = path . join ( extensionContext . storagePath , "addProjectConfigurations.json" ) ; const addProjectConfigurationFile = fs . existsSync ( userOverridePath ) ? userOverridePath : extensionContext . asAbsolutePath ( "ProjectManagement\\addProjectConfigurations.json" ) ; let addProjectConfigurations ; try { addProjectConfigurations = require ( addProjectConfigurationFile ) ; } catch ( _a ) { vscode_1 . window . showErrorMessage ( ` ${ addProjectConfigurationFile } ` ) ; } const quickPickItems = addProjectConfigurations . configurations . map ( configuration => { return { description : configuration . description , label : configuration . quickPickLabel , snippet : configuration . snippet } ; } ) ; vscode_1 . window . showQuickPick ( quickPickItems , { placeHolder : "Choose project type to create" } ) . then ( ( pickedItem ) => { if ( ! pickedItem ) { return ; } const quickPickItem = pickedItem ; const projectBaseUri = path . dirname ( item . descriptor ( ) . configFilename ) . toLowerCase ( ) ; const openDialogUri = vscode_1 . Uri . parse ( "file:///" + projectBaseUri ) ; vscode_1 . window . showOpenDialog ( { canSelectFiles : false , canSelectFolders : true , canSelectMany : false , defaultUri : openDialogUri , openLabel : "Select folder" } ) . then ( ( folders ) => { if ( folders && folders . length === 1 ) { let newProjectFilePath = path . join ( folders [ 0 ] . fsPath , "sources.bp" ) . toLowerCase ( ) ; if ( ! newProjectFilePath . startsWith ( projectBaseUri ) ) { vscode_1 . window . showWarningMessage ( "Project must be under module configuration path: " + projectBaseUri ) ; return ; } if ( fs . existsSync ( newProjectFilePath ) ) { vscode_1 . window . showWarningMessage ( "Project file already exists at: " + newProjectFilePath ) ; return ; } let newUri = vscode_1 . Uri . parse ( "untitled:" + newProjectFilePath ) ; vscode_1 . workspace . openTextDocument ( newUri ) . then ( ( textDoc ) => { vscode_1 . window . showTextDocument ( textDoc ) . then ( ( editor ) => { const totalSnippet = quickPickItem . snippet . join ( "\r\n" ) ; editor . insertSnippet ( new vscode_1 . SnippetString ( totalSnippet ) ) . then ( ( ) => { findClosestProjectListFile ( newProjectFilePath ) . then ( ( buildListPath ) => { languageClient . sendRequest ( AddProjectRequest , { moduleFilename : item . descriptor ( ) . configFilename , projectFilename : newProjectFilePath } ) ; } ) ; } ) ; } ) ; } ) ; } } ) ; } ) ; }
Called by the DScript.addProject command which is invoked
 from the context menu in the project browser.
Called by the DScript . addProject command which is invoked from the context menu in the project browser .
// As the user which project type.
 // Let the user pick a destination folder based on the module configuration directory.
 // This will return undefined on cancel and we only support one file.
 // Don't overwrite a file if it already exists.
 // Create a new file with the untitled "schema". This
 // causes VSCode to create the file in the editor but
 // does not commit it do disk.
 // This can probably be done in the Language Server itself.
