LuaLS / LuaLS/lua-language-server

Class definitions get confused with same filenames across folders.

未关闭
#3,018 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Lua
星标
4.4k
派生
442
PR 合并指标
30 天内没有已合并 PR

描述

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Windows

What is the issue affecting?

Diagnostics/Syntax Checking

Expected Behaviour

I have two files, both named the same but in different paths. Each file has its own class and table structure name, which differs from each other.

class A doesn't have method "MyMethod"
class B does
When creating an instance of the class B, and using MyMethod from class B it says that Class A has undefined field "MyMethod" despite being an instance of class B

Renaming class B's file name to something else stops the undefined field warning.

I expect the classes to have differentiation based on the ---@class ClassName syntax, and not the file name.

Actual Behaviour

As you might expect from my description, it does give that warning until the file is renamed.

Reproduction steps
  1. Create a file "test/file.lua" with a class that doesn't implement "MyMethod"
  2. Create a file "file.lua" with a class that does implement "MyMethod"
  3. In your main file, require both, create an instance of both, and try to use MyMethod from instance from step 2
  4. Notice warning about class from step 1 not implementing MyMethod, despite not being used.
Additional Notes

In a small scale test, this didn't seem to happen. But in a full project, the program ran the method LLS says is undefined. Renaming the file and nothing else fixed it so it had something to do with that.

Log File

No response

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

按照复现步骤中的描述,使用 test/file.lua、file.lua 以及一个同时 require 两者的 main 文件来复现该警告。首先检查与 class 和 table 解析相关的 diagnostics/syntax checking;完成的标准是,file.lua 中的实例应针对其自身的 class 进行检查,而不是针对 test/file.lua 中的同名 class。

由索引模型根据 Issue 内容生成。

评估

技术栈
lua, vscode
领域
devtools
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。