diff options
| author | Yong He <yonghe@outlook.com> | 2023-12-08 16:10:27 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-08 16:10:27 -0800 |
| commit | 12fcffaaaf2d1ffa2eefa680e2d7c9971e38a5db (patch) | |
| tree | fab26218d438d6d6057eab2d3548a72561c18fae /source/slang/slang.cpp | |
| parent | 4321929879c1ed5b87ff95a99ca7da91e28d18fd (diff) | |
Handle import, entrypoint and global params in included files. (#3395)
* Handle `import`, entrypoint and global params in included files.
* Fix language server.
* Extend `_createScopeForLegacyLookup` for `__include`.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang.cpp')
| -rw-r--r-- | source/slang/slang.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 2852dd43e..744033a0f 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -3367,6 +3367,25 @@ Linkage::IncludeResult Linkage::findAndIncludeFile(Module* module, TranslationUn return result; } + if (isInLanguageServer()) + { + // HACK: When in language server mode, we will always load the currently opend file as a fresh module + // even if some previously opened file already references the current file via `import` or `include`. + // see comments in `WorkspaceVersion::getOrLoadModule()` for the reason behind this. + // An undesired outcome of this decision is that we could endup including the currently opened file itself + // via chain of `__include`s because the currently opened file will not have a true unique file system + // identity that allows it to be deduplicated correct. Therefore we insert a hack logic here to detect + // re-inclusion by just the file path. + // We can clean up this hack by making the language server truly support incremental checking so we can + // reuse the previously loaded module instead of needing to always start with a fresh copy. + // + for (auto file : translationUnit->getSourceFiles()) + { + if (file->getPathInfo().hasFoundPath() && Path::equals(file->getPathInfo().foundPath, sourceFile->getPathInfo().foundPath)) + return result; + } + } + module->addFileDependency(sourceFile); // Create a transparent FileDecl to hold all children from the included file. |
