labels.js 1.3 KB

123456789101112131415161718192021222324252627282930
  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 { hasDriveLetter, isRootOrDriveLetter } from './extpath.js';
  6. import { Schemas } from './network.js';
  7. import { isWindows } from './platform.js';
  8. import { basename } from './resources.js';
  9. import { URI } from './uri.js';
  10. export function getBaseLabel(resource) {
  11. if (!resource) {
  12. return undefined;
  13. }
  14. if (typeof resource === 'string') {
  15. resource = URI.file(resource);
  16. }
  17. const base = basename(resource) || (resource.scheme === Schemas.file ? resource.fsPath : resource.path) /* can be empty string if '/' is passed in */;
  18. // convert c: => C:
  19. if (isWindows && isRootOrDriveLetter(base)) {
  20. return normalizeDriveLetter(base);
  21. }
  22. return base;
  23. }
  24. export function normalizeDriveLetter(path, continueAsWindows) {
  25. if (hasDriveLetter(path, continueAsWindows)) {
  26. return path.charAt(0).toUpperCase() + path.slice(1);
  27. }
  28. return path;
  29. }
  30. let normalizedUserHomeCached = Object.create(null);