Skip to content

Conversation

@nkxxll
Copy link
Contributor

@nkxxll nkxxll commented Dec 12, 2025

  • added the ignore current file code action
  • the action adds the current file as relative file path to the codebook.toml
  • for that I have to resolve the relative (to the workspace_dir) path of the file
  • as the workspace_dir is 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 the Backend structure but I'll leave that up to you)
Screenshot 2025-12-12 at 18 28 01 Screenshot 2025-12-12 at 19 45 58 - another thing I though of is that the path is computed every time you want to get the code actions. It might be more performant to send the current uri as a whole and compute the relative path when the user actually invokes the command...Let me know if that is something you would want to have changed

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 codebook it 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 😄.

Copilot AI review requested due to automatic review settings December 12, 2025 18:58
Copy link

Copilot AI left a 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.ignoreFile with execution handler

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 263 to 277
let relative_path = self.get_relative_path(&params.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,
}));
Copy link

Copilot AI Dec 12, 2025

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.

Copilot uses AI. Check for mistakes.
data: None,
}));
}
let relative_path = self.get_relative_path(&params.text_document.uri);
Copy link

Copilot AI Dec 12, 2025

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.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

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

Comment on lines 318 to 326
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!",
),
Copy link

Copilot AI Dec 12, 2025

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.

Suggested change
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,

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings December 14, 2025 22:06
Copy link

Copilot AI left a 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.

Copilot AI review requested due to automatic review settings December 14, 2025 22:36
@nkxxll nkxxll force-pushed the ignore-current-file-code-action branch from f1fcfc5 to 7a04410 Compare December 14, 2025 22:38
Copy link

Copilot AI left a 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.

Copilot AI review requested due to automatic review settings December 23, 2025 21:02
Copy link

Copilot AI left a 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.

@blopker
Copy link
Owner

blopker commented Dec 23, 2025

Thanks! I've fixed the reload issue, and we're now caching the IO work to canonicalize the workspace directory. Works as expected now!

@blopker blopker merged commit e82e8fb into blopker:main Dec 23, 2025
10 checks passed
@nkxxll nkxxll deleted the ignore-current-file-code-action branch December 24, 2025 23:10
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.

2 participants