EmmyLua Configuration Guide

May 18, 2026 · View on GitHub

中文版

EmmyLua Analyzer Rust recommends keeping project configuration in .emmyrc.json at the workspace root.

Supported config files:

  • .emmyrc.json: recommended, full feature support
  • .luarc.json: useful when migrating from existing LuaLS setups
  • .emmyrc.lua: useful for dynamically generated config

Quick Start

Put this minimal config in your project root:

{
  "$schema": "https://raw.githubusercontent.com/EmmyLuaLs/emmylua-analyzer-rust/refs/heads/main/crates/emmylua_code_analysis/resources/schema.json",
  "runtime": {
    "version": "LuaLatest"
  },
  "workspace": {
    "workspaceRoots": ["./src"]
  }
}

Schema Support

Adding $schema gives you:

  • config completion
  • field validation
  • enum suggestions
  • hover descriptions
{
  "$schema": "https://raw.githubusercontent.com/EmmyLuaLs/emmylua-analyzer-rust/refs/heads/main/crates/emmylua_code_analysis/resources/schema.json"
}

Path Rules

Paths in workspace and resource are expanded automatically when config is loaded.

SyntaxMeaning
./libsRelative to the workspace root
libs/runtimeAlso treated as workspace-relative
~/luaRelative to the user home directory
${workspaceFolder} or {workspaceFolder}Workspace root
{env:NAME}Environment variable NAME
$NAMEEnvironment variable NAME
{luarocks}LuaRocks deploy lua directory

Example:

{
  "workspace": {
    "library": [
      "${workspaceFolder}/types",
      "{env:HOME}/.lua",
      "{luarocks}"
    ],
    "workspaceRoots": [
      "./src",
      "./test"
    ]
  }
}

This template is a good starting point for most Lua projects:

{
  "$schema": "https://raw.githubusercontent.com/EmmyLuaLs/emmylua-analyzer-rust/refs/heads/main/crates/emmylua_code_analysis/resources/schema.json",
  "completion": {
    "autoRequire": true,
    "callSnippet": false,
    "postfix": "@"
  },
  "diagnostics": {
    "globals": [],
    "disable": ["undefined-global"]
  },
  "doc": {
    "syntax": "md"
  },
  "runtime": {
    "version": "LuaLatest",
    "requirePattern": ["?.lua", "?/init.lua"]
  }
}

Full Configuration Example

Note: the current top-level formatting key is format, not reformat.

Click to expand the full example
{
  "$schema": "https://raw.githubusercontent.com/EmmyLuaLs/emmylua-analyzer-rust/refs/heads/main/crates/emmylua_code_analysis/resources/schema.json",
  "codeAction": {
    "insertSpace": null
  },
  "codeLens": {
    "enable": true
  },
  "completion": {
    "enable": true,
    "autoRequire": true,
    "autoRequireFunction": "require",
    "autoRequireNamingConvention": "keep",
    "autoRequireSeparator": ".",
    "callSnippet": false,
    "postfix": "@",
    "baseFunctionIncludesName": true
  },
  "diagnostics": {
    "enable": true,
    "disable": [],
    "enables": [],
    "globals": [],
    "globalsRegex": [],
    "severity": {},
    "diagnosticInterval": 500
  },
  "doc": {
    "privateName": [],
    "knownTags": [],
    "syntax": "md"
  },
  "documentColor": {
    "enable": true
  },
  "format": {
    "externalTool": null,
    "externalToolRangeFormat": null,
    "useDiff": false
  },
  "hint": {
    "enable": true,
    "paramHint": true,
    "indexHint": true,
    "localHint": true,
    "overrideHint": true,
    "metaCallHint": true,
    "enumParamHint": false
  },
  "hover": {
    "enable": true,
    "customDetail": null
  },
  "inlineValues": {
    "enable": true
  },
  "references": {
    "enable": true,
    "fuzzySearch": true,
    "shortStringSearch": false
  },
  "resource": {
    "paths": []
  },
  "runtime": {
    "version": "LuaLatest",
    "requireLikeFunction": [],
    "frameworkVersions": [],
    "extensions": [],
    "requirePattern": [],
    "nonstandardSymbol": [],
    "special": {}
  },
  "semanticTokens": {
    "enable": true,
    "renderDocumentationMarkup": true
  },
  "signature": {
    "detailSignatureHelper": true
  },
  "strict": {
    "requirePath": false,
    "typeCall": false,
    "arrayIndex": true,
    "metaOverrideFileDefine": true,
    "docBaseConstMatchBaseType": true,
    "requireExportGlobal": false
  },
  "workspace": {
    "ignoreDir": [],
    "ignoreGlobs": [],
    "library": [],
    "packageDirs": [],
    "workspaceRoots": [],
    "preloadFileSize": 0,
    "encoding": "utf-8",
    "moduleMap": [],
    "reindexDuration": 5000,
    "enableReindex": false
  }
}

Top-Level Overview

SectionPurposeCommon fields
completionCompletion and auto-requireautoRequire, callSnippet, postfix
diagnosticsDiagnostic toggles, allowlists, severity overridesdisable, globals, severity
docDocumentation parsing and renderingsyntax, knownTags, privateName
runtimeLua version, extra syntax, require behaviorversion, extensions, requirePattern
workspaceRoots, libraries, ignore ruleslibrary, workspaceRoots, ignoreGlobs
strictStricter typing and visibility rulesarrayIndex, requireExportGlobal
formatExternal formatter integrationexternalTool, externalToolRangeFormat
hintInlay hintsparamHint, localHint, enumParamHint
hoverHover informationenable, customDetail
referencesReference search behaviorfuzzySearch, shortStringSearch

Configuration Reference

completion

FieldTypeDefaultDescription
enablebooleantrueEnable completion
autoRequirebooleantrueInsert require automatically for symbols from other modules
autoRequireFunctionstring"require"Function name used for auto-require
autoRequireNamingConventionstring"keep"Filename conversion mode: keep, snake-case, pascal-case, camel-case, keep-class
autoRequireSeparatorstring"."Separator used in auto-require paths
callSnippetbooleanfalseInclude call snippets in function completion
postfixstring"@"Postfix completion trigger
baseFunctionIncludesNamebooleantrueInclude the function name when generating base function snippets

diagnostics

FieldTypeDefaultDescription
enablebooleantrueEnable diagnostics
disablestring[][]Disabled diagnostic rules
enablesstring[][]Additional rules to enable
globalsstring[][]Global variable allowlist
globalsRegexstring[][]Regex allowlist for global variables
severityobject{}Per-rule severity overrides
diagnosticInterval`numbernull`500

Supported severities: error, warning, information, hint.

Example:

{
  "diagnostics": {
    "disable": ["undefined-global"],
    "severity": {
      "undefined-global": "warning",
      "unused": "hint"
    },
    "enables": ["unknown-doc-tag"]
  }
}
Show diagnostic rules

Default error rules:

  • syntax-error
  • doc-syntax-error
  • undefined-global
  • local-const-reassign
  • annotation-usage-error
  • iter-variable-reassign (enabled by default on Lua 5.5+)

Default hint rules:

  • unreachable-code
  • unused
  • deprecated
  • redefined-local
  • duplicate-require
  • preferred-local-alias

Disabled by default:

  • code-style-check
  • incomplete-signature-doc
  • missing-global-doc
  • unknown-doc-tag
  • non-literal-expressions-in-assert

All remaining built-in rules default to warning:

  • type-not-found
  • missing-return
  • param-type-mismatch
  • missing-parameter
  • redundant-parameter
  • access-invisible
  • discard-returns
  • undefined-field
  • duplicate-type
  • redefined-label
  • need-check-nil
  • await-in-sync
  • return-type-mismatch
  • missing-return-value
  • redundant-return-value
  • undefined-doc-param
  • duplicate-doc-field
  • missing-fields
  • inject-field
  • circle-doc-class
  • assign-type-mismatch
  • unbalanced-assignments
  • unnecessary-assert
  • unnecessary-if
  • duplicate-set-field
  • duplicate-index
  • generic-constraint-mismatch
  • cast-type-mismatch
  • unresolved-require
  • require-module-not-visible
  • enum-value-mismatch
  • read-only
  • global-in-non-module
  • attribute-param-type-mismatch
  • attribute-missing-parameter
  • attribute-redundant-parameter
  • invert-if
  • call-non-callable

doc

FieldTypeDefaultDescription
privateNamestring[][]Treat matching field names as private members, for example m_*
knownTagsstring[][]Additional documentation tags to recognize
syntaxstring"md"Documentation syntax: none, md, myst, rst
rstPrimaryDomain`stringnull`null
rstDefaultRole`stringnull`null

runtime

FieldTypeDefaultDescription
versionstring"LuaLatest"Lua version: Lua5.1, LuaJIT, Lua5.2, Lua5.3, Lua5.4, Lua5.5, LuaLatest
requireLikeFunctionstring[][]Function names treated like require
frameworkVersionsstring[][]Framework version identifiers
extensionsstring[][]Additional file extensions treated as Lua
requirePatternstring[][]Module search patterns such as ?.lua and ?/init.lua
nonstandardSymbolstring[][]Allowed non-standard syntax symbols
specialobject{}Special function mappings

Supported nonstandardSymbol values:

  • //
  • /**/
  • `
  • +=
  • -=
  • *=
  • /=
  • %=
  • ^=
  • //=
  • |=
  • &=
  • <<=
  • >>=
  • ||
  • &&
  • !
  • !=
  • continue

Supported special values: none, require, error, assert, type, setmetatable.

workspace

FieldTypeDefaultDescription
ignoreDirstring[][]Ignored directories
ignoreGlobsstring[][]Glob patterns to ignore
librarystring[]object[][]
packagesstring[]object[][]
workspaceRootsstring[][]Workspace source roots
preloadFileSizenumber0Reserved field, currently unused
encodingstring"utf-8"File encoding
moduleMapobject[][]Module name rewrite rules
reindexDurationnumber5000Delay before full reindex, in milliseconds
enableReindexbooleanfalseEnable full reindex after file changes

library and packages can be either a string path or an object:

{
  "workspace": {
    "library": [
      "./types",
      {
        "path": "./vendor",
        "ignoreDir": ["test"],
        "ignoreGlobs": ["**/*.spec.lua"]
      }
    ]
  }
}

moduleMap example:

{
  "workspace": {
    "moduleMap": [
      {
        "pattern": "^lib(.*)$",
        "replace": "script\$1"
      }
    ]
  }
}

strict

FieldTypeDefaultDescription
requirePathbooleanfalseRequire import paths must match configured module paths
typeCallbooleanfalseApply stricter checking to type calls
arrayIndexbooleantrueApply stricter array index checks
metaOverrideFileDefinebooleantrueMeta definitions override file-local definitions
docBaseConstMatchBaseTypebooleantrueAllow base constant doc types to match base scalar types
requireExportGlobalbooleanfalseThird-party libraries must use ---@export global before they become importable

format

For more details, see External Formatter Options.

FieldTypeDefaultDescription
externalTool`objectnull`null
externalToolRangeFormat`objectnull`null
useDiffbooleanfalseMerge formatter output through a diff step

External tool object:

FieldTypeDefaultDescription
programstring""Executable to run
argsstring[][]Argument list
timeoutnumber5000Timeout in milliseconds

Other sections

SectionFieldDefaultDescription
codeActioninsertSpacenullOverride formatter emmy_doc.space_between_tag_columns when inserting @diagnostic disable-next-line
codeLensenabletrueEnable CodeLens
documentColorenabletrueDetect color-like strings and show color previews
hintenabletrueMaster switch
hintparamHinttrueParameter name and parameter type hints
hintindexHinttrueNamed array index hints
hintlocalHinttrueLocal variable type hints
hintoverrideHinttrueOverride hints
hintmetaCallHinttrueHints for metatable __call dispatch
hintenumParamHintfalseEnum literal hints
hoverenabletrueEnable hover docs
hovercustomDetailnullCustom hover detail level, typically 1 to 255
inlineValuesenabletrueShow inline values during debugging
referencesenabletrueEnable reference search
referencesfuzzySearchtrueFall back to fuzzy matching when normal search finds nothing
referencesshortStringSearchfalseAlso search inside short strings
resourcepaths[]Resource roots for path completion and navigation
semanticTokensenabletrueEnable semantic highlighting
semanticTokensrenderDocumentationMarkuptrueRender documentation markup, used together with doc.syntax
signaturedetailSignatureHelpertrueShow detailed signature help

Recommendations

  • Prefer .emmyrc.json for new projects
  • When migrating from LuaLS, keep .luarc.json first and move to .emmyrc.json gradually
  • Configure workspace.library and workspace.workspaceRoots early, otherwise navigation, completion, and diagnostics will be less precise
  • If your team uses custom doc tags, remember to add them to doc.knownTags
  • If you want stricter third-party library visibility, consider enabling strict.requireExportGlobal

Back to top