-
Notifications
You must be signed in to change notification settings - Fork 51
feat(emmylua_ls): show progress percentage while indexing workspace #861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Summary of ChangesHello @Davidyz, 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 enhances the user experience of the EmmyLua Language Server by introducing detailed progress reporting during its initial workspace indexing. Instead of a static message, users will now observe a dynamic percentage indicating the completion status of the indexing process, providing better feedback and transparency during startup. Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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 introduces progress percentage reporting during workspace indexing, which is a great user experience improvement. However, the current implementation introduces a performance issue by updating files one by one within a loop, which can be slow for large projects. I've provided a suggestion to refactor this to use a more performant bulk update approach while still reporting progress. The suggestion also includes a fix for the percentage calculation to ensure it reaches 100%.
| let files: Vec<emmylua_code_analysis::LuaFileInfo> = collect_files(&workspace_folders, &emmyrc); | ||
| let file_count = files.len() as u32; | ||
| if file_count > 0 { | ||
| files.into_iter().enumerate().for_each(|(index, file)| { | ||
| let (path, text) = file.into_tuple(); | ||
| status_bar.update_progress_task( | ||
| ProgressTask::LoadWorkspace, | ||
| Some((index as u32) * 100 / file_count), | ||
| Some(format!("Indexing {} files", file_count)), | ||
| ); | ||
| mut_analysis.update_file_by_path(&path, text); | ||
| }); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation updates files one by one within a loop by calling update_file_by_path. This is inefficient because update_file_by_path triggers index removal and update operations for each file, which can be very slow for large workspaces.
A more performant approach is to first iterate through the files to update them in the Virtual File System (VFS) while reporting progress, collect their IDs, and then perform a single bulk operation to update the index for all files at once.
Additionally, the progress calculation (index as u32) * 100 / file_count will never reach 100%. The suggested code fixes this by using index + 1 to ensure the progress completes at 100%.
let files: Vec<emmylua_code_analysis::LuaFileInfo> = collect_files(&workspace_folders, &emmyrc);
let file_count = files.len();
if file_count > 0 {
let mut file_ids = Vec::with_capacity(file_count);
let vfs = mut_analysis.compilation.get_db_mut().get_vfs_mut();
for (index, file) in files.into_iter().enumerate() {
let (path, text) = file.into_tuple();
status_bar.update_progress_task(
ProgressTask::LoadWorkspace,
Some(((index + 1) as u32 * 100) / file_count as u32),
Some(format!("Indexing {} files", file_count)),
);
if let Some(uri) = emmylua_code_analysis::file_path_to_uri(&path) {
let file_id = vfs.set_file_content(&uri, text);
file_ids.push(file_id);
}
}
mut_analysis.compilation.remove_index(file_ids.clone());
mut_analysis.compilation.update_index(file_ids);
}|
This is an incorrect use of the API. Loading all files together and performing out-of-order analysis aligns with the reality of Lua. Introducing progress reporting and loading them separately not only reduces performance but also leads to incorrect results. |
|
I see. I have another design: create a new function |
9ac6cde to
8d35f3d
Compare
|
Your current progress report only monitors the construction of the syntax tree, which constitutes a very small part of the analysis process. The time spent reporting progress may far exceed the time required to build the syntax tree. This is an unacceptable performance degradation. Progress bars should not be used to monitor performance-intensive analysis stages. |
|
Indeed. I noticed that the progress will stay at 100% for a while, which means the progress representation is inaccurate.
The progress percentage is a notification, so it doesn't need to wait for a response, and therefore shouldn't be a performance bottleneck. Also, if a task doesn't take very long, there's no point of using a progress bar, because you'll hardly be able to see the "progress". |
This PR adds support for sending percentage progress when initializing the codebase.