Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash with deleted file #2934

Merged
merged 2 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading