diff --git a/lsp-server/src/manager/symbol.cppm b/lsp-server/src/manager/symbol.cppm index 11758d3..dd21cfb 100644 --- a/lsp-server/src/manager/symbol.cppm +++ b/lsp-server/src/manager/symbol.cppm @@ -135,23 +135,42 @@ namespace lsp::manager return decoded; } - bool IsTsfFile(const std::filesystem::path& path) + enum class TslFileKind + { + kLibraryTsf, + kScriptTsl, + kOther, + }; + + TslFileKind GetTslFileKind(const std::filesystem::path& path) { if (!path.has_extension()) - return false; + { + return TslFileKind::kOther; + } + std::string ext = path.extension().string(); std::transform( ext.begin(), ext.end(), ext.begin(), [](unsigned char ch) { return static_cast(std::tolower(ch)); }); - return ext == ".tsf" || ext == ".tsl"; + + if (ext == ".tsf") + { + return TslFileKind::kLibraryTsf; + } + if (ext == ".tsl") + { + return TslFileKind::kScriptTsl; + } + return TslFileKind::kOther; } std::unique_ptr BuildSymbolTableFromFile( const std::filesystem::path& file_path) { - if (!IsTsfFile(file_path)) + if (GetTslFileKind(file_path) == TslFileKind::kOther) return nullptr; std::ifstream file(file_path, std::ios::binary); @@ -268,6 +287,12 @@ namespace lsp::manager if (!entry.is_regular_file()) continue; + // System library only accepts `.tsf` as a library unit. `.tsl` is a script and should be ignored here. + if (GetTslFileKind(entry.path()) != TslFileKind::kLibraryTsf) + { + continue; + } + auto table = BuildSymbolTableFromFile(entry.path()); if (!table) { @@ -330,7 +355,9 @@ namespace lsp::manager { if (!entry.is_regular_file()) continue; - if (!IsTsfFile(entry.path())) + + auto kind = GetTslFileKind(entry.path()); + if (kind == TslFileKind::kOther) continue; auto table = BuildSymbolTableFromFile(entry.path()); @@ -341,9 +368,11 @@ namespace lsp::manager } auto stem = entry.path().stem().string(); - if (!HasMatchingTopLevelSymbol(*table, stem)) + // Only `.tsf` is a library unit that must match the file name. + // `.tsl` is a script and should not be forced to have a top-level symbol. + if (kind == TslFileKind::kLibraryTsf && !HasMatchingTopLevelSymbol(*table, stem)) { - spdlog::warn("Skipping system file {}: top-level symbol does not match file name", entry.path().string()); + spdlog::warn("Skipping workspace file {}: top-level symbol does not match file name", entry.path().string()); ++failed; continue; }