提交 14cd1529 编写于 作者: B Benjamin Pasero

Offer to open workspace in root even when telemetry has been disabled (fix #108669)

上级 41f396d7
...@@ -210,6 +210,10 @@ ...@@ -210,6 +210,10 @@
"name": "vs/workbench/contrib/webviewPanel", "name": "vs/workbench/contrib/webviewPanel",
"project": "vscode-workbench" "project": "vscode-workbench"
}, },
{
"name": "vs/workbench/contrib/workspaces",
"project": "vscode-workbench"
},
{ {
"name": "vs/workbench/contrib/customEditor", "name": "vs/workbench/contrib/customEditor",
"project": "vscode-workbench" "project": "vscode-workbench"
......
...@@ -7,16 +7,9 @@ import * as crypto from 'crypto'; ...@@ -7,16 +7,9 @@ import * as crypto from 'crypto';
import { IFileService, IResolveFileResult, IFileStat } from 'vs/platform/files/common/files'; import { IFileService, IResolveFileResult, IFileStat } from 'vs/platform/files/common/files';
import { IWorkspaceContextService, WorkbenchState, IWorkspace } from 'vs/platform/workspace/common/workspace'; import { IWorkspaceContextService, WorkbenchState, IWorkspace } from 'vs/platform/workspace/common/workspace';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { IHostService } from 'vs/workbench/services/host/browser/host';
import { INotificationService, NeverShowAgainScope, INeverShowAgainOptions } from 'vs/platform/notification/common/notification';
import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
import { ITextFileService, ITextFileContent } from 'vs/workbench/services/textfile/common/textfiles'; import { ITextFileService, ITextFileContent } from 'vs/workbench/services/textfile/common/textfiles';
import { URI } from 'vs/base/common/uri'; import { URI } from 'vs/base/common/uri';
import { Schemas } from 'vs/base/common/network'; import { Schemas } from 'vs/base/common/network';
import { hasWorkspaceFileExtension } from 'vs/platform/workspaces/common/workspaces';
import { localize } from 'vs/nls';
import Severity from 'vs/base/common/severity';
import { joinPath } from 'vs/base/common/resources';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { IWorkspaceTagsService, Tags } from 'vs/workbench/contrib/tags/common/workspaceTags'; import { IWorkspaceTagsService, Tags } from 'vs/workbench/contrib/tags/common/workspaceTags';
import { getHashedRemotesFromConfig } from 'vs/workbench/contrib/tags/electron-browser/workspaceTags'; import { getHashedRemotesFromConfig } from 'vs/workbench/contrib/tags/electron-browser/workspaceTags';
...@@ -133,15 +126,12 @@ export class WorkspaceTagsService implements IWorkspaceTagsService { ...@@ -133,15 +126,12 @@ export class WorkspaceTagsService implements IWorkspaceTagsService {
@IWorkspaceContextService private readonly contextService: IWorkspaceContextService, @IWorkspaceContextService private readonly contextService: IWorkspaceContextService,
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService, @IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
@IProductService private readonly productService: IProductService, @IProductService private readonly productService: IProductService,
@IHostService private readonly hostService: IHostService,
@INotificationService private readonly notificationService: INotificationService,
@IQuickInputService private readonly quickInputService: IQuickInputService,
@ITextFileService private readonly textFileService: ITextFileService @ITextFileService private readonly textFileService: ITextFileService
) { } ) { }
async getTags(): Promise<Tags> { async getTags(): Promise<Tags> {
if (!this._tags) { if (!this._tags) {
this._tags = await this.resolveWorkspaceTags(rootFiles => this.handleWorkspaceFiles(rootFiles)); this._tags = await this.resolveWorkspaceTags();
} }
return this._tags; return this._tags;
...@@ -301,7 +291,7 @@ export class WorkspaceTagsService implements IWorkspaceTagsService { ...@@ -301,7 +291,7 @@ export class WorkspaceTagsService implements IWorkspaceTagsService {
"workspace.py.playwright" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true } "workspace.py.playwright" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
} }
*/ */
private resolveWorkspaceTags(participant?: (rootFiles: string[]) => void): Promise<Tags> { private resolveWorkspaceTags(): Promise<Tags> {
const tags: Tags = Object.create(null); const tags: Tags = Object.create(null);
const state = this.contextService.getWorkbenchState(); const state = this.contextService.getWorkbenchState();
...@@ -318,7 +308,7 @@ export class WorkspaceTagsService implements IWorkspaceTagsService { ...@@ -318,7 +308,7 @@ export class WorkspaceTagsService implements IWorkspaceTagsService {
tags['workspace.empty'] = isEmpty; tags['workspace.empty'] = isEmpty;
const folders = !isEmpty ? workspace.folders.map(folder => folder.uri) : this.productService.quality !== 'stable' && this.findFolders(); const folders = !isEmpty ? workspace.folders.map(folder => folder.uri) : this.productService.quality !== 'stable' && this.findFolders();
if (!folders || !folders.length || !this.fileService) { if (!folders || !folders.length) {
return Promise.resolve(tags); return Promise.resolve(tags);
} }
...@@ -326,10 +316,6 @@ export class WorkspaceTagsService implements IWorkspaceTagsService { ...@@ -326,10 +316,6 @@ export class WorkspaceTagsService implements IWorkspaceTagsService {
const names = (<IFileStat[]>[]).concat(...files.map(result => result.success ? (result.stat!.children || []) : [])).map(c => c.name); const names = (<IFileStat[]>[]).concat(...files.map(result => result.success ? (result.stat!.children || []) : [])).map(c => c.name);
const nameSet = names.reduce((s, n) => s.add(n.toLowerCase()), new Set()); const nameSet = names.reduce((s, n) => s.add(n.toLowerCase()), new Set());
if (participant) {
participant(names);
}
tags['workspace.grunt'] = nameSet.has('gruntfile.js'); tags['workspace.grunt'] = nameSet.has('gruntfile.js');
tags['workspace.gulp'] = nameSet.has('gulpfile.js'); tags['workspace.gulp'] = nameSet.has('gulpfile.js');
tags['workspace.jake'] = nameSet.has('jakefile.js'); tags['workspace.jake'] = nameSet.has('jakefile.js');
...@@ -485,49 +471,6 @@ export class WorkspaceTagsService implements IWorkspaceTagsService { ...@@ -485,49 +471,6 @@ export class WorkspaceTagsService implements IWorkspaceTagsService {
}); });
} }
private handleWorkspaceFiles(rootFiles: string[]): void {
const state = this.contextService.getWorkbenchState();
const workspace = this.contextService.getWorkspace();
// Handle top-level workspace files for local single folder workspace
if (state === WorkbenchState.FOLDER) {
const workspaceFiles = rootFiles.filter(hasWorkspaceFileExtension);
if (workspaceFiles.length > 0) {
this.doHandleWorkspaceFiles(workspace.folders[0].uri, workspaceFiles);
}
}
}
private doHandleWorkspaceFiles(folder: URI, workspaces: string[]): void {
const neverShowAgain: INeverShowAgainOptions = { id: 'workspaces.dontPromptToOpen', scope: NeverShowAgainScope.WORKSPACE, isSecondary: true };
// Prompt to open one workspace
if (workspaces.length === 1) {
const workspaceFile = workspaces[0];
this.notificationService.prompt(Severity.Info, localize('workspaceFound', "This folder contains a workspace file '{0}'. Do you want to open it? [Learn more]({1}) about workspace files.", workspaceFile, 'https://go.microsoft.com/fwlink/?linkid=2025315'), [{
label: localize('openWorkspace', "Open Workspace"),
run: () => this.hostService.openWindow([{ workspaceUri: joinPath(folder, workspaceFile) }])
}], { neverShowAgain });
}
// Prompt to select a workspace from many
else if (workspaces.length > 1) {
this.notificationService.prompt(Severity.Info, localize('workspacesFound', "This folder contains multiple workspace files. Do you want to open one? [Learn more]({0}) about workspace files.", 'https://go.microsoft.com/fwlink/?linkid=2025315'), [{
label: localize('selectWorkspace', "Select Workspace"),
run: () => {
this.quickInputService.pick(
workspaces.map(workspace => ({ label: workspace } as IQuickPickItem)),
{ placeHolder: localize('selectToOpen', "Select a workspace to open") }).then(pick => {
if (pick) {
this.hostService.openWindow([{ workspaceUri: joinPath(folder, pick.label) }]);
}
});
}
}], { neverShowAgain });
}
}
private findFolders(): URI[] | undefined { private findFolders(): URI[] | undefined {
const folder = this.findFolder(); const folder = this.findFolder();
return folder && [folder]; return folder && [folder];
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { localize } from 'vs/nls';
import { Registry } from 'vs/platform/registry/common/platform';
import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry, IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { Disposable } from 'vs/base/common/lifecycle';
import { IFileService } from 'vs/platform/files/common/files';
import { INeverShowAgainOptions, INotificationService, NeverShowAgainScope, Severity } from 'vs/platform/notification/common/notification';
import { URI } from 'vs/base/common/uri';
import { joinPath } from 'vs/base/common/resources';
import { IHostService } from 'vs/workbench/services/host/browser/host';
import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
import { hasWorkspaceFileExtension } from 'vs/platform/workspaces/common/workspaces';
/**
* A workbench contribution that will look for `.code-workspace` files in the root of the
* workspace folder and open a notification to suggest to open one of the workspaces.
*/
export class WorkspacesFinderContribution extends Disposable implements IWorkbenchContribution {
constructor(
@IWorkspaceContextService private readonly contextService: IWorkspaceContextService,
@INotificationService private readonly notificationService: INotificationService,
@IFileService private readonly fileService: IFileService,
@IQuickInputService private readonly quickInputService: IQuickInputService,
@IHostService private readonly hostService: IHostService
) {
super();
this.findWorkspaces();
}
private async findWorkspaces(): Promise<void> {
const folder = this.contextService.getWorkspace().folders[0];
if (!folder || this.contextService.getWorkbenchState() !== WorkbenchState.FOLDER) {
return; // require a single root folder
}
const rootFileNames = (await this.fileService.resolve(folder.uri)).children?.map(child => child.name);
if (Array.isArray(rootFileNames)) {
const workspaceFiles = rootFileNames.filter(hasWorkspaceFileExtension);
if (workspaceFiles.length > 0) {
this.doHandleWorkspaceFiles(folder.uri, workspaceFiles);
}
}
}
private doHandleWorkspaceFiles(folder: URI, workspaces: string[]): void {
const neverShowAgain: INeverShowAgainOptions = { id: 'workspaces.dontPromptToOpen', scope: NeverShowAgainScope.WORKSPACE, isSecondary: true };
// Prompt to open one workspace
if (workspaces.length === 1) {
const workspaceFile = workspaces[0];
this.notificationService.prompt(Severity.Info, localize('workspaceFound', "This folder contains a workspace file '{0}'. Do you want to open it? [Learn more]({1}) about workspace files.", workspaceFile, 'https://go.microsoft.com/fwlink/?linkid=2025315'), [{
label: localize('openWorkspace', "Open Workspace"),
run: () => this.hostService.openWindow([{ workspaceUri: joinPath(folder, workspaceFile) }])
}], { neverShowAgain });
}
// Prompt to select a workspace from many
else if (workspaces.length > 1) {
this.notificationService.prompt(Severity.Info, localize('workspacesFound', "This folder contains multiple workspace files. Do you want to open one? [Learn more]({0}) about workspace files.", 'https://go.microsoft.com/fwlink/?linkid=2025315'), [{
label: localize('selectWorkspace', "Select Workspace"),
run: () => {
this.quickInputService.pick(
workspaces.map(workspace => ({ label: workspace } as IQuickPickItem)),
{ placeHolder: localize('selectToOpen', "Select a workspace to open") }).then(pick => {
if (pick) {
this.hostService.openWindow([{ workspaceUri: joinPath(folder, pick.label) }]);
}
});
}
}], { neverShowAgain });
}
}
}
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(WorkspacesFinderContribution, LifecyclePhase.Eventually);
...@@ -295,4 +295,7 @@ import 'vs/workbench/contrib/welcome/common/viewsWelcome.contribution'; ...@@ -295,4 +295,7 @@ import 'vs/workbench/contrib/welcome/common/viewsWelcome.contribution';
// Timeline // Timeline
import 'vs/workbench/contrib/timeline/browser/timeline.contribution'; import 'vs/workbench/contrib/timeline/browser/timeline.contribution';
// Workspaces
import 'vs/workbench/contrib/workspaces/browser/workspaces.contribution';
//#endregion //#endregion
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册