LuaLS / LuaLS/lua-language-server

Feature Request: Do not diagnose unused-local for function parameters

オープン
#3,166 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Lua
スター
4.4k
フォーク
442
PR マージ指標
30日以内にマージされた PR はありません

説明

This is a feature request for a new setting for LLS which would not diagnose unused-local for variables which are parameters of a function. Something like

"Lua.diagnostics.unusedLocalExcludeFuncParam": true

The reason I'd like this feature is because we have a Lua codebase that heavily relies on something similar to virtual functions, where there are many tables that have functions defined that share the same name and list of parameters, but some of these functions don't need to use all of the parameters. Think of something like this

function menu1:on_select_item(item, mouse_button) do_something_with_item(item) end
function menu2:on_select_item(item, mouse_button) do_something_with_mouse_button(mouse_button) end

Of course this could be changed to appeal to the current unused-local diagnostics by changing it to

function menu1:on_select_item(item) do_something_with_item(item) end
function menu2:on_select_item(_, mouse_button) do_something_with_mouse_button(mouse_button) end

but, besides doing the fixup being a lot of work, it makes maintenance of the code base worse because a programmer can't easily know anymore what those _ parmeters are supposed to be. Another alternative would be to add all known function parameter names to "Lua.diagnostics.unusedLocalExclude" (introduced via #619) but of course that also would be sub-optimal, because ignoring generic names like item could defeat the purpose of the diagnostic.

Besides function parameters, having an option to ignore for-loop variables would also be very neat. It's often easier there to substitute the name for _ but still, sometimes that loses important information on what the key/value of a for-loop over pairs(...) is. So something like

"Lua.diagnostics.unusedLocalExcludeForLoopVars": true

would also be very appreciated.

Thank you for your consideration, and of course for making LLS, it's awesome!

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、unused-local 診断と既存の Lua.diagnostics.unusedLocalExclude 設定を見つけます。関数パラメーターと for ループ変数がどのように識別されるかを確認し、次に要求された 2 つのオプションを定義してテストします。これにより、有効にした設定ではそれらの診断だけが抑制され、その他の未使用ローカルは引き続き報告されます。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
lua
領域
devtools
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。