🐛 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:
parent
566830bdb8
commit
241de77152
|
|
@ -135,23 +135,42 @@ namespace lsp::manager
|
||||||
return decoded;
|
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())
|
if (!path.has_extension())
|
||||||
return false;
|
{
|
||||||
|
return TslFileKind::kOther;
|
||||||
|
}
|
||||||
|
|
||||||
std::string ext = path.extension().string();
|
std::string ext = path.extension().string();
|
||||||
std::transform(
|
std::transform(
|
||||||
ext.begin(),
|
ext.begin(),
|
||||||
ext.end(),
|
ext.end(),
|
||||||
ext.begin(),
|
ext.begin(),
|
||||||
[](unsigned char ch) { return static_cast<char>(std::tolower(ch)); });
|
[](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(
|
std::unique_ptr<language::symbol::SymbolTable> BuildSymbolTableFromFile(
|
||||||
const std::filesystem::path& file_path)
|
const std::filesystem::path& file_path)
|
||||||
{
|
{
|
||||||
if (!IsTsfFile(file_path))
|
if (GetTslFileKind(file_path) == TslFileKind::kOther)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
std::ifstream file(file_path, std::ios::binary);
|
std::ifstream file(file_path, std::ios::binary);
|
||||||
|
|
@ -268,6 +287,12 @@ namespace lsp::manager
|
||||||
if (!entry.is_regular_file())
|
if (!entry.is_regular_file())
|
||||||
continue;
|
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());
|
auto table = BuildSymbolTableFromFile(entry.path());
|
||||||
if (!table)
|
if (!table)
|
||||||
{
|
{
|
||||||
|
|
@ -330,7 +355,9 @@ namespace lsp::manager
|
||||||
{
|
{
|
||||||
if (!entry.is_regular_file())
|
if (!entry.is_regular_file())
|
||||||
continue;
|
continue;
|
||||||
if (!IsTsfFile(entry.path()))
|
|
||||||
|
auto kind = GetTslFileKind(entry.path());
|
||||||
|
if (kind == TslFileKind::kOther)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto table = BuildSymbolTableFromFile(entry.path());
|
auto table = BuildSymbolTableFromFile(entry.path());
|
||||||
|
|
@ -341,9 +368,11 @@ namespace lsp::manager
|
||||||
}
|
}
|
||||||
|
|
||||||
auto stem = entry.path().stem().string();
|
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;
|
++failed;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue