🐛 fix(symbol): treat .tsl as script, not library

- LoadSystemLibrary now only scans .tsf files.
- LoadWorkspace still indexes .tsl scripts but skips the file-stem/top-level check for them.
This commit is contained in:
csh 2025-12-14 13:28:14 +08:00
parent 566830bdb8
commit 241de77152
1 changed files with 36 additions and 7 deletions

View File

@ -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<char>(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<language::symbol::SymbolTable> 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;
}