Skip to content

Conversation

@tilladam
Copy link
Contributor

@tilladam tilladam commented Jan 4, 2026

Add proper line/column resolution for proc-macro spans via a callback mechanism. Previously these methods returned hardcoded 1 values.

The implementation adds:

SubRequest::LineColumn and SubResponse::LineColumnResult to the bidirectional protocol
ProcMacroClientInterface::line_column() method
Callback handling in load-cargo using LineIndex
Server implementation in RaSpanServer that uses the callback
Test infrastructure and a test for LineColumn

This is in service of resolving an issue with Slint: slint-ui/slint#685

The Slint side now implement this also as per:
slint-ui/slint@13ce62d

Owing to my limited experience with Rust (and rust-analyzer) this was created with help from Claude. I have attempted to steer and review to the best of my ability and attempted sufficient test coverage.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 4, 2026
@rustbot

This comment has been minimized.

@rustbot rustbot added has-merge-commits S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 4, 2026
@rustbot rustbot removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. has-merge-commits labels Jan 4, 2026
Copy link
Contributor

@Shourya742 Shourya742 left a comment

Choose a reason for hiding this comment

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

1 suggestion, rest of the changes looks good to me.

Comment on lines 575 to 584
let line_col =
line_index.try_line_col(range.range.start()).ok_or_else(|| ServerError {
message: format!("invalid offset {offset} for file {file_id}"),
io: None,
})?;
// proc_macro::Span line/column are 1-based
Ok(SubResponse::LineColumnResult {
line: line_col.line as u32 + 1,
column: line_col.col as u32 + 1,
})
Copy link
Contributor

Choose a reason for hiding this comment

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

We can return a default value instead of propagating an error, given how things are structured right now. If an error occurs in the callback, we end up interrupting the client request while the server continues to block waiting for a response. This is something we’ll improve, but since we’re still prototyping, returning a default value is the simplest and safest option for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

{1,1} then as in the previous implementation?

Add proper line/column resolution for proc-macro spans via a callback
mechanism. Previously these methods returned hardcoded 1 values.

The implementation adds:
- SubRequest::LineColumn and SubResponse::LineColumnResult to the
  bidirectional protocol
- ProcMacroClientInterface::line_column() method
- Callback handling in load-cargo using LineIndex
- Server implementation in RaSpanServer that uses the callback
- a test for Span::line() and Span::column() in proc-macro server

Add fn_like_span_line_column test proc-macro that exercises the new
line/column API, and a corresponding test with a mock callback.
@Veykril Veykril added this pull request to the merge queue Jan 5, 2026
Merged via the queue into rust-lang:master with commit 86e8b1b Jan 5, 2026
15 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 5, 2026
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.

4 participants