20c7d30f61822fd2677513ce25acc4de98118f35d959fbb13d6b4723ff6b3c2ae0c0b0964e4e3702b98cdcb82687217383c7d58de94743840199fe787d627a 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. import { localize } from '../../../nls.js';
  6. import { TernarySearchTree } from '../../../base/common/map.js';
  7. import { URI } from '../../../base/common/uri.js';
  8. import { createDecorator } from '../../instantiation/common/instantiation.js';
  9. export const IWorkspaceContextService = createDecorator('contextService');
  10. export function isSingleFolderWorkspaceIdentifier(obj) {
  11. const singleFolderIdentifier = obj;
  12. return typeof (singleFolderIdentifier === null || singleFolderIdentifier === void 0 ? void 0 : singleFolderIdentifier.id) === 'string' && URI.isUri(singleFolderIdentifier.uri);
  13. }
  14. export function toWorkspaceIdentifier(workspace) {
  15. // Multi root
  16. if (workspace.configuration) {
  17. return {
  18. id: workspace.id,
  19. configPath: workspace.configuration
  20. };
  21. }
  22. // Single folder
  23. if (workspace.folders.length === 1) {
  24. return {
  25. id: workspace.id,
  26. uri: workspace.folders[0].uri
  27. };
  28. }
  29. // Empty workspace
  30. return undefined;
  31. }
  32. export class Workspace {
  33. constructor(_id, folders, _transient, _configuration, _ignorePathCasing) {
  34. this._id = _id;
  35. this._transient = _transient;
  36. this._configuration = _configuration;
  37. this._ignorePathCasing = _ignorePathCasing;
  38. this._foldersMap = TernarySearchTree.forUris(this._ignorePathCasing, () => true);
  39. this.folders = folders;
  40. }
  41. get folders() {
  42. return this._folders;
  43. }
  44. set folders(folders) {
  45. this._folders = folders;
  46. this.updateFoldersMap();
  47. }
  48. get id() {
  49. return this._id;
  50. }
  51. get transient() {
  52. return this._transient;
  53. }
  54. get configuration() {
  55. return this._configuration;
  56. }
  57. set configuration(configuration) {
  58. this._configuration = configuration;
  59. }
  60. getFolder(resource) {
  61. if (!resource) {
  62. return null;
  63. }
  64. return this._foldersMap.findSubstr(resource) || null;
  65. }
  66. updateFoldersMap() {
  67. this._foldersMap = TernarySearchTree.forUris(this._ignorePathCasing, () => true);
  68. for (const folder of this.folders) {
  69. this._foldersMap.set(folder.uri, folder);
  70. }
  71. }
  72. toJSON() {
  73. return { id: this.id, folders: this.folders, transient: this.transient, configuration: this.configuration };
  74. }
  75. }
  76. export class WorkspaceFolder {
  77. constructor(data,
  78. /**
  79. * Provides access to the original metadata for this workspace
  80. * folder. This can be different from the metadata provided in
  81. * this class:
  82. * - raw paths can be relative
  83. * - raw paths are not normalized
  84. */
  85. raw) {
  86. this.raw = raw;
  87. this.uri = data.uri;
  88. this.index = data.index;
  89. this.name = data.name;
  90. }
  91. toJSON() {
  92. return { uri: this.uri, name: this.name, index: this.index };
  93. }
  94. }
  95. export const WORKSPACE_EXTENSION = 'code-workspace';
  96. export const WORKSPACE_FILTER = [{ name: localize('codeWorkspace', "Code Workspace"), extensions: [WORKSPACE_EXTENSION] }];