MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / fsPath

Function fsPath

src/shared/utils/fs.ts:14–33  ·  view source on GitHub ↗
(uri: URI, { useRealCasing = false }: { useRealCasing?: boolean; } = {})

Source from the content-addressed store, hash-verified

12import { sortBy } from "./array";
13
14export function fsPath(uri: URI, { useRealCasing = false }: { useRealCasing?: boolean; } = {}): string {
15 // eslint-disable-next-line no-restricted-properties
16 let newPath = typeof uri === "string" ? uri : uri.fsPath;
17
18 // Fix drive letter first, so we won't write warnings if that's the only difference.
19 newPath = forceWindowsDriveLetterToUppercase(newPath);
20
21 if (useRealCasing) {
22 const realPath = fs.existsSync(newPath) && safeRealpathSync(newPath, { useNative: true });
23 // Since realpathSync.native will resolve symlinks, only do anything if the paths differ
24 // _only_ by case.
25 // when there was no symlink (eg. the lowercase version of both paths match).
26 if (realPath && realPath.toLowerCase() === newPath.toLowerCase() && realPath !== newPath) {
27 console.warn(`Rewriting path:\n ${newPath}\nto:\n ${realPath} because the casing appears incorrect`);
28 newPath = realPath;
29 }
30 }
31
32 return newPath;
33}
34
35export function safeRealpathSync(filePath: string, { useNative = false }: { useNative?: boolean; } = {}): string {
36 try {

Callers 15

helpers.tsFile · 0.90
activateWithoutAnalysisFunction · 0.90
openFileFunction · 0.90
tryDeleteFunction · 0.90
waitForDiagnosticChangeFunction · 0.90
ensureWorkspaceSymbolFunction · 0.90
renderedItemLabelFunction · 0.90
findSuiteNodeFunction · 0.90
findProjectNodeFunction · 0.90

Calls 3

safeRealpathSyncFunction · 0.85
warnMethod · 0.65

Tested by 15

getTestRangesFunction · 0.72
getTempProjectFileFunction · 0.72
getTempTestFileFunction · 0.72
testBreakpointConditionFunction · 0.72
simplifyFunction · 0.72
expectLinkFunction · 0.72
setupTestFilesFunction · 0.72
expectStatusFunction · 0.72
createLaunchConfigFunction · 0.72
createTestEnvironmentFunction · 0.72
createTempFileFunction · 0.72