Neovim: Add .luarc.json to special directories to fix LSP "undefined global vim" warnings #91
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
問題
ftplugin/.lua、ftdetect/.lua、syntax/.lua、plugin/.luaなどの特殊ディレクトリ内のLuaファイルを編集する際、Lua Language Server(LSP)が
vimグローバル変数について「undefined globalvim」という警告を表示していました:これにより、Neovim Lua設定ファイルの編集が困難になり、LSPが適切な自動補完、型チェック、ドキュメント表示を提供できませんでした。
根本原因
ルートの
.config/nvim/.luarc.jsonは正しく設定されており、init.luaやlua/**/*内のファイルでは正常に動作していました。しかし、LSPが特殊ディレクトリ(after/ftplugin、ftdetect、syntax、plugin)内のファイルを編集する際にこのルート設定を認識していませんでした。解決策
各特殊ディレクトリに個別の
.luarc.jsonファイルを追加しました。これにより、これらのディレクトリ内のLuaファイルを編集する際にもLSPが適切に動作します:追加したファイル:
.config/nvim/after/ftplugin/.luarc.json(102個のLuaファイル用).config/nvim/ftdetect/.luarc.json(44個のLuaファイル用).config/nvim/syntax/.luarc.json(17個のLuaファイル用).config/nvim/plugin/.luarc.json(2個のLuaファイル用).config/nvim/after/syntax/.luarc.json(1個のLuaファイル用)各
.luarc.jsonの内容:{ "$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json", "Lua.runtime.version": "LuaJIT", "Lua.diagnostics.globals": ["vim"], "Lua.workspace.library": ["/home/linuxbrew/.linuxbrew/share/nvim/runtime"], "Lua.workspace.checkThirdParty": false, "Lua.completion.callSnippet": "Replace" }影響範囲
この変更により、特殊ディレクトリ内の166個のLuaファイルでLSPサポートが提供されます:
init.luaやlua/**/*内のカスタムLuaモジュール(171個)は引き続きルートの
.luarc.jsonを使用して正常に動作します。修正後
特殊ディレクトリ内のLuaファイル編集時にも、適切な自動補完、型チェック、ホバードキュメント、リファクタリングサポートが利用できるようになりました。
Fixes #90
Original prompt
Fixes #90
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.