diff --git a/.chronus/changes/fix-crash-deleted-file-2024-1-17-1-27-24.md b/.chronus/changes/fix-crash-deleted-file-2024-1-17-1-27-24.md new file mode 100644 index 0000000000..e5ccd217ae --- /dev/null +++ b/.chronus/changes/fix-crash-deleted-file-2024-1-17-1-27-24.md @@ -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 diff --git a/packages/compiler/src/core/util.ts b/packages/compiler/src/core/util.ts index 6d781065eb..f2f2392dac 100644 --- a/packages/compiler/src/core/util.ts +++ b/packages/compiler/src/core/util.ts @@ -137,7 +137,15 @@ export function mapEquals( } 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 {