From d8214448aa1ba338c84184239bfee66cea24fbaa Mon Sep 17 00:00:00 2001 From: Mark Skelton Date: Mon, 24 Apr 2023 05:46:15 -0500 Subject: [PATCH] Fix realpath exception (#1641) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dirk Bäumer --- server/src/paths.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/server/src/paths.ts b/server/src/paths.ts index 26720ecb..d8b0afac 100644 --- a/server/src/paths.ts +++ b/server/src/paths.ts @@ -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; @@ -112,4 +118,4 @@ export function getUri(documentOrUri: string | TextDocument | URI): URI { : documentOrUri instanceof URI ? documentOrUri : URI.parse(documentOrUri.uri); -} \ No newline at end of file +}