Skip to content

fix: honor explicit library roots despite workspace excludes - #981

Merged
CppCXY merged 1 commit into
EmmyLuaLs:mainfrom
lewis6991:fix/excludelib
Mar 11, 2026
Merged

CppCXY merged 1 commit into
EmmyLuaLs:mainfrom
lewis6991:fix/excludelib

Conversation

@lewis6991

Copy link
Copy Markdown
Collaborator

Explicitly configured libraries and package directories should still be
indexed even when they live under paths excluded from the main
workspace.

Separate the expanded file-matching roots from the client workspace
roots so explicit library roots can bypass parent ignoreDir filtering
during collection and watched-file matching without being fed back into
init_analysis as main workspaces on reload.

Keep global ignore globs and library-specific ignore rules applying
inside those library roots, and add regression coverage for matching,
collection, and reload state.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a long-standing issue where explicitly configured library and package directories were not being properly indexed if they happened to be located within a path that was globally excluded from the main workspace. The changes introduce a more robust workspace management system by separating the core client workspace roots from an expanded set of roots used specifically for file matching and watching. This allows the language server to correctly identify and process files within libraries, ensuring they are fully analyzed while still honoring both global and library-specific ignore patterns.

Highlights

  • Library Indexing: Explicitly configured libraries and package directories are now indexed even if they reside within paths globally excluded from the main workspace.
  • Workspace Separation: Introduced a distinction between client-provided workspace roots (for configuration scope) and expanded file-matching roots (for file collection and watching), allowing libraries to bypass parent ignoreDir filtering.
  • Granular Exclusion: Library roots can now bypass parent ignoreDir filtering, while still respecting their own specific ignore rules and global ignore globs.
  • Improved File Matching: The file matching logic has been refactored to select the most specific workspace for a given file and apply its corresponding include/exclude rules.
  • Comprehensive Testing: Added new regression tests to ensure correct behavior for library indexing, specific ignore rules, and global ignore globs across matching, collection, and reload states.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • crates/emmylua_code_analysis/src/vfs/collect_workspace_files.rs
    • Modified collect_workspace_files to prevent library workspaces from inheriting parent exclude_dir settings.
    • Removed redundant comments related to merging library excludes.
    • Added unit tests to verify library indexing and ignore rule application.
  • crates/emmylua_ls/src/context/workspace_manager.rs
    • Added EmmyLibraryItem import.
    • Introduced match_workspace_folders to store expanded workspace roots for file matching.
    • Implemented set_match_workspace_folders and file_match_workspaces methods.
    • Refactored is_workspace_file to use the new file_match_workspaces and an updated WorkspaceFileMatcher.
    • Updated WorkspaceFileMatcher::new to accept emmyrc and precompute library-specific exclusion rules.
    • Added select_workspace and workspace_import_depth helper functions for precise workspace selection.
    • Included new unit tests for WorkspaceFileMatcher behavior.
  • crates/emmylua_ls/src/handlers/initialized/mod.rs
    • Updated initialized_handler to set match_workspace_folders using a new build_match_file_workspaces function.
    • Modified WorkspaceFileMatcher instantiation to pass the emmyrc configuration.
    • Added build_match_file_workspaces to construct the comprehensive list of workspaces for file matching, including libraries and package directories.
  • crates/emmylua_ls/src/handlers/text_document/register_file_watch.rs
    • Adjusted file watcher registration to use the expanded file_match_workspaces to ensure all relevant roots, including libraries, are monitored.
    • Utilized a HashSet to prevent redundant watching of the same root directory.
Activity
  • No specific activity was recorded for this pull request.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

Explicitly configured libraries and package directories should still be
indexed even when they live under paths excluded from the main
workspace.

Separate the expanded file-matching roots from the client workspace
roots so explicit library roots can bypass parent ignoreDir filtering
during collection and watched-file matching without being fed back into
init_analysis as main workspaces on reload.

Keep global ignore globs and library-specific ignore rules applying
inside those library roots, and add regression coverage for matching,
collection, and reload state.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request significantly refactors and enhances the file matching and watching logic within the EmmyLua language server, particularly for handling library files and package directories. Key changes include introducing a separate match_workspace_folders list in WorkspaceManager to distinguish between client-provided workspace roots and an expanded list used for internal matching and watching. The WorkspaceFileMatcher was updated to precompute library-specific exclusion rules from the emmyrc configuration and to use a new select_workspace function for more precise application of include/exclude rules based on the most specific workspace a file belongs to. A new build_match_file_workspaces function dynamically constructs this expanded list, incorporating configured libraries and package directories as library workspace roots. Consequently, the file watcher now monitors all these relevant roots, ensuring consistent and accurate indexing. New unit tests were added to validate the complex interactions of workspace, library, and exclusion rules, confirming that library-specific ignores are correctly applied, global directory ignores do not apply to libraries by default, and global glob ignores still affect libraries.

@clason

clason commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

Note that this was already fixed back on December 8 but got reverted in faf2233 (see #873).

@CppCXY
CppCXY merged commit a051277 into EmmyLuaLs:main Mar 11, 2026
22 checks passed
@clason

clason commented Mar 11, 2026 •

Copy link
Copy Markdown
Contributor

This fixes my issue.

@lewis6991
lewis6991 deleted the fix/excludelib branch March 17, 2026 08:33
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.

3 participants