提交 5b34b4c6 编写于 作者: M Martin Aeschlimann

add hasWorkspaceFileExtension

上级 f078b096
......@@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { basename, normalize, join, dirname, extname } from 'path';
import { basename, normalize, join, dirname } from 'path';
import * as fs from 'fs';
import { localize } from 'vs/nls';
import * as arrays from 'vs/base/common/arrays';
......@@ -26,7 +26,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IWindowsMainService, IOpenConfiguration, IWindowsCountChangedEvent, ICodeWindow, IWindowState as ISingleWindowState, WindowMode } from 'vs/platform/windows/electron-main/windows';
import { IHistoryMainService } from 'vs/platform/history/common/history';
import { IProcessEnvironment, isLinux, isMacintosh, isWindows } from 'vs/base/common/platform';
import { IWorkspacesMainService, IWorkspaceIdentifier, WORKSPACE_FILTER, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier, WORKSPACE_EXTENSION } from 'vs/platform/workspaces/common/workspaces';
import { IWorkspacesMainService, IWorkspaceIdentifier, WORKSPACE_FILTER, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier, hasWorkspaceFileExtension } from 'vs/platform/workspaces/common/workspaces';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { mnemonicButtonLabel } from 'vs/base/common/labels';
import { Schemas } from 'vs/base/common/network';
......@@ -762,6 +762,8 @@ export class WindowsManager implements IWindowsMainService {
}
private getPathsToOpen(openConfig: IOpenConfiguration): IPathToOpen[] {
debugger;
let windowsToOpen: IPathToOpen[];
let isCommandLineOrAPICall = false;
......@@ -980,6 +982,7 @@ export class WindowsManager implements IWindowsMainService {
// remove trailing slash
const uriPath = uri.path;
if (endsWith(uriPath, '/')) {
if (uriPath.length > 2) {
// only remove if the path has some content
......@@ -991,7 +994,7 @@ export class WindowsManager implements IWindowsMainService {
}
// if there's no type hint
if (!typeHint && (extname(uri.path) === WORKSPACE_EXTENSION || options.gotoLineMode)) {
if (!typeHint && (hasWorkspaceFileExtension(uri.path) || options.gotoLineMode)) {
typeHint = 'file';
}
......@@ -1005,7 +1008,7 @@ export class WindowsManager implements IWindowsMainService {
remoteAuthority
};
}
if (extname(uri.path) === WORKSPACE_EXTENSION && !options.forceOpenWorkspaceAsFile) {
if (hasWorkspaceFileExtension(uri.path) && !options.forceOpenWorkspaceAsFile) {
return {
workspace: this.workspacesMainService.getWorkspaceIdentifier(uri),
remoteAuthority
......
......@@ -8,6 +8,7 @@ import { localize } from 'vs/nls';
import { Event } from 'vs/base/common/event';
import { IWorkspaceFolder, IWorkspace } from 'vs/platform/workspace/common/workspace';
import { URI, UriComponents } from 'vs/base/common/uri';
import { extname } from 'vs/base/common/paths';
export const IWorkspacesMainService = createDecorator<IWorkspacesMainService>('workspacesMainService');
export const IWorkspacesService = createDecorator<IWorkspacesService>('workspacesService');
......@@ -138,3 +139,9 @@ export type IWorkspaceInitializationPayload = IMultiFolderWorkspaceInitializatio
export function isSingleFolderWorkspaceInitializationPayload(obj: any): obj is ISingleFolderWorkspaceInitializationPayload {
return isSingleFolderWorkspaceIdentifier((obj.folder as ISingleFolderWorkspaceIdentifier));
}
const WORKSPACE_SUFFIX = '.' + WORKSPACE_EXTENSION;
export function hasWorkspaceFileExtension(path: string) {
return extname(path) === WORKSPACE_SUFFIX;
}
......@@ -3,10 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IWorkspacesMainService, IWorkspaceIdentifier, WORKSPACE_EXTENSION, UNTITLED_WORKSPACE_NAME, IResolvedWorkspace, IStoredWorkspaceFolder, isStoredWorkspaceFolder, IWorkspaceFolderCreationData } from 'vs/platform/workspaces/common/workspaces';
import { IWorkspacesMainService, IWorkspaceIdentifier, hasWorkspaceFileExtension, UNTITLED_WORKSPACE_NAME, IResolvedWorkspace, IStoredWorkspaceFolder, isStoredWorkspaceFolder, IWorkspaceFolderCreationData } from 'vs/platform/workspaces/common/workspaces';
import { isParent } from 'vs/platform/files/common/files';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { join, dirname, extname } from 'path';
import { join, dirname } from 'path';
import { mkdirp, writeFile, readFile } from 'vs/base/node/pfs';
import { readFileSync, existsSync, mkdirSync, writeFileSync } from 'fs';
import { isLinux } from 'vs/base/common/platform';
......@@ -61,7 +61,7 @@ export class WorkspacesMainService extends Disposable implements IWorkspacesMain
}
private isWorkspacePath(path: string): boolean {
return this.isInsideWorkspacesHome(path) || extname(path) === `.${WORKSPACE_EXTENSION}`;
return this.isInsideWorkspacesHome(path) || hasWorkspaceFileExtension(path);
}
private doResolveWorkspace(path: URI, contents: string): IResolvedWorkspace | null {
......
......@@ -3,8 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { WORKSPACE_EXTENSION, IWorkspacesService } from 'vs/platform/workspaces/common/workspaces';
import { extname, basename, normalize } from 'vs/base/common/paths';
import { hasWorkspaceFileExtension, IWorkspacesService } from 'vs/platform/workspaces/common/workspaces';
import { basename, normalize } from 'vs/base/common/paths';
import { IFileService } from 'vs/platform/files/common/files';
import { IWindowsService, IWindowService, IURIToOpen } from 'vs/platform/windows/common/windows';
import { URI } from 'vs/base/common/uri';
......@@ -263,7 +263,7 @@ export class ResourcesDropHandler {
return Promise.all(fileOnDiskResources.map(fileOnDiskResource => {
// Check for Workspace
if (extname(fileOnDiskResource.fsPath) === `.${WORKSPACE_EXTENSION}`) {
if (hasWorkspaceFileExtension(fileOnDiskResource.fsPath)) {
workspaceResources.workspaces.push({ uri: fileOnDiskResource, typeHint: 'file' });
return undefined;
......
......@@ -15,8 +15,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { IWindowService } from 'vs/platform/windows/common/windows';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { Schemas } from 'vs/base/common/network';
import { WORKSPACE_EXTENSION } from 'vs/platform/workspaces/common/workspaces';
import { extname } from 'vs/base/common/paths';
import { hasWorkspaceFileExtension } from 'vs/platform/workspaces/common/workspaces';
import { Disposable, dispose } from 'vs/base/common/lifecycle';
import { localize } from 'vs/nls';
import { IEditorContribution } from 'vs/editor/common/editorCommon';
......@@ -139,7 +138,7 @@ export class OpenWorkspaceButtonContribution extends Disposable implements IEdit
return false; // we need a model
}
if (model.uri.scheme !== Schemas.file || extname(model.uri.fsPath) !== `.${WORKSPACE_EXTENSION}`) {
if (model.uri.scheme !== Schemas.file || hasWorkspaceFileExtension(model.uri.fsPath)) {
return false; // we need a local workspace file
}
......
......@@ -16,11 +16,10 @@ import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { endsWith } from 'vs/base/common/strings';
import { Schemas } from 'vs/base/common/network';
import { INotificationService, Severity, IPromptChoice } from 'vs/platform/notification/common/notification';
import { WORKSPACE_EXTENSION } from 'vs/platform/workspaces/common/workspaces';
import { hasWorkspaceFileExtension } from 'vs/platform/workspaces/common/workspaces';
import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { joinPath } from 'vs/base/common/resources';
import { extname } from 'vs/base/common/paths';
import { collectWorkspaceStats, WorkspaceStats as WorkspaceStatsType } from 'vs/base/node/stats';
const SshProtocolMatcher = /^([^@:]+@)?([^:]+):/;
......@@ -534,7 +533,7 @@ export class WorkspaceStats implements IWorkbenchContribution {
// Handle top-level workspace files for local single folder workspace
if (state === WorkbenchState.FOLDER && workspace.folders[0].uri.scheme === Schemas.file) {
const workspaceFiles = rootFiles.filter(name => extname(name) === `.${WORKSPACE_EXTENSION}`);
const workspaceFiles = rootFiles.filter(hasWorkspaceFileExtension);
if (workspaceFiles.length > 0) {
this.doHandleWorkspaceFiles(workspace.folders[0].uri, workspaceFiles);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册