Skip to content

Commit

Permalink
Fix realpath exception (#1641)
Browse files Browse the repository at this point in the history
Co-authored-by: Dirk Bäumer <dirkb@microsoft.com>
  • Loading branch information
mskelton and dbaeumer authored Apr 24, 2023
1 parent 0608fb4 commit d821444
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions server/src/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,16 @@ export function getFileSystemPath(uri: URI): string {
result = result[0].toUpperCase() + result.substr(1);
}
if (process.platform === 'win32' || process.platform === 'darwin') {
const realpath = fs.realpathSync.native(result);
// Only use the real path if only the casing has changed.
if (realpath.toLowerCase() === result.toLowerCase()) {
result = realpath;
try {
const realpath = fs.realpathSync.native(result);
// Only use the real path if only the casing has changed.
if (realpath.toLowerCase() === result.toLowerCase()) {
result = realpath;
}
} catch {
// Silently ignore errors from `fs.realpathSync` to handle scenarios where
// the file being linted is not yet written to disk. This occurs in editors
// such as Neovim for non-written buffers.
}
}
return result;
Expand All @@ -112,4 +118,4 @@ export function getUri(documentOrUri: string | TextDocument | URI): URI {
: documentOrUri instanceof URI
? documentOrUri
: URI.parse(documentOrUri.uri);
}
}

0 comments on commit d821444

Please sign in to comment.