Skip to content

Commit

Permalink
Fix crash with deleted file (microsoft#2934)
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheeguerin authored and markcowl committed Mar 5, 2024
1 parent 43ecec1 commit 73845a2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .chronus/changes/fix-crash-deleted-file-2024-1-17-1-27-24.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: fix
packages:
- "@typespec/compiler"
---

[IDE] Fix issue when deleting an open file outside the IDE that would crash the language server
10 changes: 9 additions & 1 deletion packages/compiler/src/core/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,15 @@ export function mapEquals<K, V>(
}

export async function getNormalizedRealPath(host: CompilerHost, path: string) {
return normalizePath(await host.realpath(path));
try {
return normalizePath(await host.realpath(path));
} catch (error: any) {
// This could mean the file got deleted but VSCode still has it in memory. So keep the original path.
if (error.code === "ENOENT") {
return normalizePath(path);
}
throw error;
}
}

export interface FileHandlingOptions {
Expand Down

0 comments on commit 73845a2

Please sign in to comment.