LuaLS / LuaLS/lua-language-server

Class definitions get confused with same filenames across folders.

Open
#3,018 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the warning using test/file.lua, file.lua, and a main file that requires both, as described in the reproduction steps. Start by examining diagnostics/syntax checking around class and table resolution; done means the instance from file.lua is checked against its own class rather than the same-named class in test/file.lua.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, vscode
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.