Skip to content

Commit c43f068

Browse files
committed
Use virtual module name when resolving string requires
This fixes a bug where the types of a required file would not correctly update when that file changed. It is because, during string requires, we use the real file path as the module name. However, in other usages (e.g., during indexing), we use the virtual file path if available. This caused an inconsistency between the two. We fix this by calling "getModuleName" on the returned URI, which is consistent with indexing. Ideally in future, we should move towards a state where the language server always works in the context of real file paths, especially as string requires become more common. We should instead only use a sourcemap to resolve virtual requires to real file paths, rather than the other way round.
1 parent 3b92bd5 commit c43f068

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
2020
### Fixed
2121

2222
- Fixed autocompletion of strings with '/' characters causing the prefix to be duplicated rather than replaced ([#607](https://github.com/JohnnyMorganz/luau-lsp/issues/607))
23+
- Fixed bug with string requires where a required files types may not correctly update when the file contents changed
2324

2425
## [1.28.1] - 2024-03-04
2526

src/WorkspaceFileResolver.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,9 @@ std::optional<Luau::ModuleInfo> WorkspaceFileResolver::resolveStringRequire(cons
297297
}
298298

299299
// URI-ify the file path so that its normalised (in particular, the drive letter)
300-
return {{Uri::parse(Uri::file(filePath).toString()).fsPath().generic_string()}};
300+
auto uri = Uri::parse(Uri::file(filePath).toString());
301+
302+
return Luau::ModuleInfo{getModuleName(uri)};
301303
}
302304

303305
std::optional<Luau::ModuleInfo> WorkspaceFileResolver::resolveModule(const Luau::ModuleInfo* context, Luau::AstExpr* node)

0 commit comments

Comments
 (0)