-
Notifications
You must be signed in to change notification settings - Fork 37
add ignore current file to code actions #178
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
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.
Pull request overview
This PR adds a new code action that allows users to ignore the current file by adding its relative path to the codebook.toml configuration file. The implementation includes command handling, path resolution with workspace directory canonicalization, and configuration updates.
Key changes:
- Adds "Ignore Current File" code action to LSP code action menu
- Implements relative path computation by canonicalizing the workspace directory
- Adds new command
codebook.ignoreFilewith execution handler
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
crates/codebook-lsp/src/lsp.rs
Outdated
| let relative_path = self.get_relative_path(¶ms.text_document.uri); | ||
| actions.push(CodeActionOrCommand::CodeAction(CodeAction { | ||
| title: format!("Add current file to ignore list"), | ||
| kind: Some(CodeActionKind::QUICKFIX), | ||
| diagnostics: None, | ||
| edit: None, | ||
| command: Some(Command { | ||
| title: format!("Add current file to ignore list"), | ||
| command: CodebookCommand::IgnoreFile.into(), | ||
| arguments: Some(vec![relative_path.into()]), | ||
| }), | ||
| is_preferred: None, | ||
| disabled: None, | ||
| data: None, | ||
| })); |
Copilot
AI
Dec 12, 2025
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 ignore file code action is being added unconditionally, even when there are no diagnostics in the file. This means the action will appear in files that are already being ignored or have no spelling issues. Consider only showing this action when there are actual diagnostics present, similar to how the word-related actions are only shown within the diagnostic loop.
crates/codebook-lsp/src/lsp.rs
Outdated
| data: None, | ||
| })); | ||
| } | ||
| let relative_path = self.get_relative_path(¶ms.text_document.uri); |
Copilot
AI
Dec 12, 2025
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 get_relative_path method is called on every code action request, which triggers filesystem canonicalization each time. This is inefficient, especially since code actions are requested frequently (on cursor movement, file changes, etc.). Consider caching the canonicalized workspace directory in the Backend struct or computing the relative path only when the command is actually executed.
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.
removed and placed in the add_ignore_file function
crates/codebook-lsp/src/lsp.rs
Outdated
| let file_uri = params | ||
| .arguments | ||
| .first() | ||
| .expect("CodebookCommand::IgnoreFile: There has to be a file URI here!"); | ||
| let updated = self.add_ignore_file( | ||
| config.as_ref(), | ||
| file_uri.as_str().expect( | ||
| "CodebookCommand::IgnoreFile: Argument should be convertable to a String!", | ||
| ), |
Copilot
AI
Dec 12, 2025
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.
Using expect() here will cause a panic if the argument is not a string. This could crash the LSP server if there's a protocol error. Consider using pattern matching or returning an error instead.
| let file_uri = params | |
| .arguments | |
| .first() | |
| .expect("CodebookCommand::IgnoreFile: There has to be a file URI here!"); | |
| let updated = self.add_ignore_file( | |
| config.as_ref(), | |
| file_uri.as_str().expect( | |
| "CodebookCommand::IgnoreFile: Argument should be convertable to a String!", | |
| ), | |
| let file_uri = match params.arguments.first() { | |
| Some(uri) => uri, | |
| None => { | |
| error!("CodebookCommand::IgnoreFile: There has to be a file URI here!"); | |
| return Err(jsonrpc_v2::Error::invalid_params( | |
| "Missing file URI argument for IgnoreFile command", | |
| )); | |
| } | |
| }; | |
| let file_uri_str = match file_uri.as_str() { | |
| Some(s) => s, | |
| None => { | |
| error!("CodebookCommand::IgnoreFile: Argument should be convertible to a String!"); | |
| return Err(jsonrpc_v2::Error::invalid_params( | |
| "File URI argument for IgnoreFile command is not a string", | |
| )); | |
| } | |
| }; | |
| let updated = self.add_ignore_file( | |
| config.as_ref(), | |
| file_uri_str, |
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.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
f1fcfc5 to
7a04410
Compare
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.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
|
Thanks! I've fixed the reload issue, and we're now caching the IO work to canonicalize the workspace directory. Works as expected now! |
codebook.tomlworkspace_dir) path of the fileworkspace_diris not canonicalised I'll have to do that every time (but I don't like doing the canonicalisation every time somebody hits show code action maybe one can add the canonicalised path to theBackendstructure but I'll leave that up to you)PROBLEM: relative paths like shown in the screenshot above are not correctly ignored. Did I mess up the path or is this a bug?
I'll need some feedback from you on that but I'll also look into it when I have the time to.
Update: I looked into it a bit and the paths are correctly shown as ignored from the config somehow the LSP does not respect that. When trying the cli
codebookit works just as expected. I think it is something specific to the LSP, but I cant quite grasp what it is.Apart from that the code action works like a charm. Let me know if you have some feedback 😄.