Show notification if there are projects that haven't been added to the workspace (#14046)

* add check for if there are projects that haven't been added to the workspace

* add check when workspace folders change

* add comment

* update wording

* filter for multiple file extensions at the same time

* add test

* addressing comments
This commit is contained in:
Kim Santiago
2021-01-27 16:06:33 -08:00
committed by GitHub
parent fa150fbe67
commit 8651db1e7e
7 changed files with 221 additions and 3 deletions

View File

@@ -8,6 +8,7 @@ import * as vscode from 'vscode';
import * as dataworkspace from 'dataworkspace';
import * as path from 'path';
import * as constants from '../common/constants';
import * as glob from 'fast-glob';
import { IWorkspaceService } from '../common/interfaces';
import { ProjectProviderRegistry } from '../common/projectProviderRegistry';
import Logger from '../common/logger';
@@ -158,6 +159,65 @@ export class WorkspaceService implements IWorkspaceService {
return vscode.workspace.workspaceFile ? this.getWorkspaceConfigurationValue<string[]>(ProjectsConfigurationName).map(project => this.toUri(project)) : [];
}
/**
* Check for projects that are in the workspace folders but have not been added to the workspace through the dialog or by editing the .code-workspace file
*/
async checkForProjectsNotAddedToWorkspace(): Promise<void> {
const config = vscode.workspace.getConfiguration(constants.projectsConfigurationKey);
// only check if the user hasn't selected not to show this prompt again
if (!config[constants.showNotAddedProjectsMessageKey]) {
return;
}
// look for any projects that haven't been added to the workspace
const projectsInWorkspace = this.getProjectsInWorkspace();
const workspaceFolders = vscode.workspace.workspaceFolders;
if (!workspaceFolders) {
return;
}
for (const folder of workspaceFolders) {
const results = await this.getAllProjectsInWorkspaceFolder(folder);
let containsNotAddedProject = false;
for (const projFile of results) {
// if any of the found projects aren't already in the workspace's projects, we can stop checking and show the info message
if (!projectsInWorkspace.find(p => p.fsPath === projFile)) {
containsNotAddedProject = true;
break;
}
}
if (containsNotAddedProject) {
const result = await vscode.window.showInformationMessage(constants.WorkspaceContainsNotAddedProjects, constants.LaunchOpenExisitingDialog, constants.DoNotShowAgain);
if (result === constants.LaunchOpenExisitingDialog) {
// open settings
await vscode.commands.executeCommand('projects.openExisting');
} else if (result === constants.DoNotShowAgain) {
await config.update(constants.showNotAddedProjectsMessageKey, false, true);
}
return;
}
}
}
async getAllProjectsInWorkspaceFolder(folder: vscode.WorkspaceFolder): Promise<string[]> {
// get the unique supported project extensions
const supportedProjectExtensions = [...new Set((await this.getAllProjectTypes()).map(p => { return p.projectFileExtension; }))];
// path needs to use forward slashes for glob to work
const escapedPath = glob.escapePath(folder.uri.fsPath.replace(/\\/g, '/'));
// can filter for multiple file extensions using folder/**/*.{sqlproj,csproj} format, but this notation doesn't work if there's only one extension
// so the filter needs to be in the format folder/**/*.sqlproj if there's only one supported projectextension
const projFilter = supportedProjectExtensions.length > 1 ? path.posix.join(escapedPath, '**', `*.{${supportedProjectExtensions.toString()}}`) : path.posix.join(escapedPath, '**', `*.${supportedProjectExtensions[0]}`);
return await glob(projFilter);
}
async getProjectProvider(projectFile: vscode.Uri): Promise<dataworkspace.IProjectProvider | undefined> {
const projectType = path.extname(projectFile.path).replace(/\./g, '');
let provider = ProjectProviderRegistry.getProviderByProjectExtension(projectType);