Neovim LSP Lua Configuration: Fixing the 'checkThirdParty' Workspace Warning
Learn how to properly configure Neovim LSP for Lua development and eliminate the persistent 'checkThirdParty' workspace warning
Neovim LSP Lua Configuration: Fixing the ‘checkThirdParty’ Workspace Warning
If you’re a Lua developer using Neovim with Language Server Protocol (LSP), you’ve likely encountered the persistent warning message: “LSP Lua config required for workspace checkThirdParty”. This warning can be annoying and may indicate that your LSP configuration isn’t optimized for your development environment.
Understanding the Problem
The checkThirdParty
warning appears when the Lua Language Server (lua_ls) is trying to validate third-party libraries in your workspace but doesn’t have the proper configuration to do so efficiently. This can happen when:
- Working with large projects that have many dependencies
- Using frameworks like OpenResty, Love2D, or other Lua-based tools
- Having multiple Lua versions or environments in your project
- Working with projects that have complex dependency structures
The Solution: Proper LSP Configuration
To resolve this warning and optimize your Lua development experience, you need to add specific configuration to your Neovim LSP setup.
Basic Configuration
Add the following configuration to your LSP Lua setup:
lua_ls = {
Lua = {
workspace = { checkThirdParty = false },
telemetry = { enable = false },
},
},
Complete LSP Configuration Example
Here’s a more comprehensive configuration that you can use in your Neovim setup:
-- In your LSP configuration file (e.g., lsp.lua or init.lua)
local lspconfig = require('lspconfig')
lspconfig.lua_ls.setup({
settings = {
Lua = {
workspace = {
checkThirdParty = false,
library = {
-- Add any additional library paths here
-- [vim.fn.expand("$VIMRUNTIME/lua")] = true,
-- [vim.fn.stdpath("data") .. "/lazy/lazy.nvim/lua/lazy"] = true,
},
},
telemetry = { enable = false },
diagnostics = {
globals = { 'vim' }, -- Add any global variables you use
},
completion = {
callSnippet = "Replace",
},
},
},
})
Configuration Breakdown
Let’s understand what each setting does:
workspace.checkThirdParty = false
- Purpose: Disables the third-party library checking that causes the warning
- When to use: When you don’t need strict validation of external libraries
- Benefits: Faster startup times and reduced false positives
telemetry.enable = false
- Purpose: Disables telemetry data collection
- Benefits: Privacy protection and slightly better performance
- Note: This is optional but recommended for privacy
Additional Useful Settings
You can also add these settings for a better development experience:
lua_ls = {
Lua = {
workspace = {
checkThirdParty = false,
maxPreload = 1000,
preloadFileSize = 100,
},
telemetry = { enable = false },
diagnostics = {
globals = { 'vim', 'require' },
disable = { 'lowercase-global' },
},
completion = {
callSnippet = "Replace",
keywordSnippet = "Replace",
},
runtime = {
version = 'LuaJIT',
path = vim.split(package.path, ';'),
},
},
},
When to Keep checkThirdParty
Enabled
There are scenarios where you might want to keep this feature enabled:
1. Library Development
If you’re developing Lua libraries that others will use:
workspace = { checkThirdParty = true }
2. Strict Code Quality
For projects requiring strict validation:
workspace = {
checkThirdParty = true,
library = {
-- Specify exact library paths
[vim.fn.expand("$VIMRUNTIME/lua")] = true,
},
}
3. Framework Development
When working on frameworks like OpenResty:
workspace = {
checkThirdParty = true,
library = {
-- Add framework-specific paths
["/usr/local/openresty/lualib"] = true,
},
}
Troubleshooting Common Issues
Issue 1: Configuration Not Applied
Make sure your configuration is loaded after the LSP setup:
-- Ensure this runs after lspconfig setup
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
if client.name == "lua_ls" then
-- Your lua_ls specific configuration here
end
end,
})
Issue 2: Warning Persists
If the warning still appears:
- Restart Neovim completely
- Check if you have multiple LSP configurations
- Verify the configuration syntax is correct
Issue 3: Performance Issues
If you experience slow performance:
workspace = {
checkThirdParty = false,
maxPreload = 500, -- Reduce from default 1000
preloadFileSize = 50, -- Reduce from default 100
}
Best Practices
1. Project-Specific Configuration
Consider using project-specific configurations:
-- .nvim.lua in your project root
vim.lsp.start({
name = 'lua_ls',
cmd = { 'lua-language-server' },
settings = {
Lua = {
workspace = { checkThirdParty = false },
},
},
})
2. Environment Variables
Use environment variables for different setups:
local check_third_party = os.getenv("LUA_STRICT") == "1"
lua_ls = {
Lua = {
workspace = { checkThirdParty = check_third_party },
},
}
3. Regular Updates
Keep your Lua Language Server updated:
# If using Mason
:MasonUpdate lua-language-server
# If using package manager
npm update -g lua-language-server
Conclusion
The checkThirdParty
warning in Neovim LSP for Lua is easily resolved with proper configuration. By setting checkThirdParty = false
, you’ll eliminate the warning and often improve performance, especially in larger projects.
Remember that this setting is about finding the right balance between code validation and development efficiency. For most development scenarios, disabling third-party checking provides a better experience without sacrificing code quality.
The configuration provided in this article should resolve your warning and give you a smoother Lua development experience in Neovim.