LuaLS / LuaLS/lua-language-server

"Save as" can cause "duplicate defined alias"

Open
#2,745 0 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?

Annotations

### Expected Behaviour

"Save as" should clear the cached aliases from the previous file (in the case of no workspace/folder)

### Actual Behaviour

With a new window with no workspace, when I used "save as" I noticed the aliases from the file were still being used, causing a conflict _duplicate defined alias_ with the newly named file. See repro steps.

![image](https://github.com/LuaLS/lua-language-server/assets/1103761/3a8fffad-8ab5-4128-8361-6418873acc8f)

### Reproduction steps

0. Start with a new window, no workspace, etc
1. Create a new file, e.g., "test.lua"
2. Add some code and save the file ( `--@alias id integer\n` )
3. "Save as" test_2.lua
4. (Optional) You may need to repeatedly "Save as" (e.g., test_3.lua) to trigger the bug, I couldn't 100% repro
5. Observe _Duplicate defined alias `id`_

Reload editor to clear error

### Additional Notes

This is an edge case, as typically you'd have an workspace or folder open (in which case 'save as' should keep the previous file cached also).

### 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

No source file or test is named. Start by reproducing the issue in the Visual Studio Code extension with a new window and no workspace, then trace the Save as handling and cached annotation aliases. Done means repeated Save as operations no longer report a duplicate defined alias, while preserving the stated workspace behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, vscode
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.