Interactive setup for Lua LSP development environment
Sets up lua-language-server with formatting and linting tools for Lua development. Use this to configure a complete Lua LSP environment with code diagnostics and auto-formatting.
/plugin marketplace add zircote/lua-lsp/plugin install lua-lsp@zircote-lspThis command will configure your Lua development environment with lua-language-server and essential tools.
First, verify Lua is installed:
lua -v
macOS:
brew install lua-language-server
Linux:
# Download from GitHub releases
curl -L https://github.com/LuaLS/lua-language-server/releases/latest/download/lua-language-server-linux-x64.tar.gz -o luals.tar.gz
tar -xzf luals.tar.gz -C ~/.local/bin
rm luals.tar.gz
Windows:
# Download from GitHub releases
# https://github.com/LuaLS/lua-language-server/releases
# StyLua (Rust-based formatter)
cargo install stylua
# Luacheck (requires LuaRocks)
luarocks install luacheck
# Busted testing framework
luarocks install busted
lua-language-server --version
stylua --version
luacheck --version
export ENABLE_LSP_TOOL=1
Test the LSP integration:
# Create a test file
cat > test_lsp.lua << 'EOF'
local function greet(name)
return "Hello, " .. name .. "!"
end
print(greet("World"))
EOF
# Run Luacheck
luacheck test_lsp.lua
# Format with StyLua
stylua --check test_lsp.lua
# Clean up
rm test_lsp.lua
Create .luacheck for project-specific linting rules:
-- .luacheck
std = "lua51+busted"
ignore = {"212/self", "213"}
max_line_length = 120
Create .stylua.toml for formatting preferences:
# .stylua.toml
column_width = 100
line_endings = "Unix"
indent_type = "Spaces"
indent_width = 4
quote_style = "AutoPreferDouble"