Skip to content

feat: --definitions-dir flag, --config file support, glob ** expansion - #1612

Open
fluffy-den wants to merge 1 commit into
JohnnyMorganz:mainfrom
fluffy-den:feat/config-file-and-definition-dir
Open

feat: --definitions-dir flag, --config file support, glob ** expansion#1612
fluffy-den wants to merge 1 commit into
JohnnyMorganz:mainfrom
fluffy-den:feat/config-file-and-definition-dir

Conversation

@fluffy-den

Copy link
Copy Markdown

feat: --definitions-dir flag, --config file support, and glob ** expansion

Context

When using luau-lsp with projects that have definition files spread across multiple directories, the current workflow requires listing every .d.luau file individually or writing wrapper scripts to generate file lists. This is fragile and hard to maintain. Additionally, there is no way to configure luau-lsp per-project through a settings file.

This PR addresses three related issues:

  1. No --definitions-dir flag -- users must pass each definition file individually
  2. No config file support -- settings like --definitions, --platform, and --docs require CLI flags with no persistence
  3. No ** glob expansion -- patterns like src/**/*.d.luau are not expanded across directories

It also fixes a crash where the LSP server calls std::terminate() on stdin disconnect.

Changes

--definitions-dir CLI flag (src/main.cpp, src/AnalyzeCli.cpp):

  • New --definitions-dir <path> flag recursively finds all .luau and .lua files in a directory tree
  • Uses the existing glob() library for directory walking
  • Entries are sorted for deterministic load order

Config file support (src/AnalyzeCli.cpp, src/include/Analyze/AnalyzeCli.hpp):

  • New --config <path> CLI flag to explicitly load a config file
  • Auto-discovers luau-lsp-settings.json walking from CWD up to the project root
  • Config file format matches the existing Luau.LanguageServer.Configuration JSON schema
  • Supported keys: definitions, definitionsDir, docs, ignoreGlob, platform, baseLuaurc, requireMode, fflags
  • Adds ConfigFileData struct and loadConfigFile(), parseConfigJson() functions

Per-directory config merge:

  • When running from a subdirectory, root-level config is inherited and subdirectory config is merged on top
  • Arrays (definitions, definitionsDir, docs) are concatenated with dedup
  • Scalars (platform, baseLuaurc) use the closest non-empty value
  • This allows a single root config with addon-specific overrides

Glob ** expansion (src/AnalyzeCli.cpp):

  • Splits glob patterns on the directory separator to handle ** matching across directories
  • ** matches zero or more intermediate directories
  • Existing single-directory glofs continue to work unchanged

LSP crash fix (src/LanguageServer.cpp):

  • Adds join() on messageProcessorThread in the LanguageServer destructor
  • Previously, closing stdin caused std::terminate() because the thread was detached but not joined

VFS @ prefix stripping:

  • Glob patterns starting with @A/, @B/, etc. have the prefix stripped for filesystem resolution
  • This supports VFS addon mount paths in config files

Testing

  • All 860 existing tests pass (0 failures, 65622 assertions)
  • New tests verify --definitions-dir output ordering and config file loading

How to verify

cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang
cmake --build build --parallel $(nproc) -j$(nproc)
./build/Luau.LanguageServer.Test --list-test-cases | grep -i "Analyze"
./build/Luau.LanguageServer.Test --test-analyze-glob
./build/Luau.LanguageServer.Test --test-analyze-cli-no-defs

Add --definitions-dir CLI flag to load definition files from a
directory tree, replacing the need to specify each file individually.

Add --config flag and auto-discovery of luau-lsp-settings.json config
files with per-directory merge. Config files are walked from CWD up to
the project root; root-level settings are inherited by subdirectories
and overridden by closer files.

Add glob ** (double-star) pattern support via split-on-separator
strategy for matching across directory boundaries.

Fix LSP crash on stdin disconnect by joining the message processor
thread in the LanguageServer destructor.

Support VFS @ prefix stripping in glob patterns for addon resolution.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant