Skip to content
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

Optimise clearing and traversing code to only re-parse the modified file #6292

Closed
JoshuaBatty opened this issue Jul 23, 2024 · 0 comments · Fixed by #6464
Closed

Optimise clearing and traversing code to only re-parse the modified file #6292

JoshuaBatty opened this issue Jul 23, 2024 · 0 comments · Fixed by #6464
Assignees
Labels

Comments

@JoshuaBatty
Copy link
Member

When traversing, skip over AST nodes that originate from cached modules and only traverse and collect tokens from the file that was modified.

TokenMap

/// Remove all tokens for the given file from the token map.
pub fn remove_tokens_for_file(&self, path_to_remove: &PathBuf) {
    self.0.retain(|key, _value| {
        key.path.as_ref().map_or(true, |path| path != path_to_remove)
    });

the in the traverse function

pub fn traverse(
    results: Vec<(Option<Programs>, Handler)>,
    engines_clone: &Engines,
    session: Arc<Session>,
    file_versions: &BTreeMap<PathBuf, Option<u64>>
) -> Result<Option<CompileResults>, LanguageServerError> {
    // Clear the tokens out of the TokenMap if the file has changed.
    let modified_file = file_versions.iter().find_map(|(path, version)| {
        version.map(|_| path)
    });
    match modified_file {
        Some(path) => {
            session.token_map.remove_tokens_for_file(path);
        },
        None => {
            session.token_map.clear();
        },
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant