DetachHead / basedpyright

pyright fork with various type checking improvements, improved vscode support and pylance features built into the language server
http://docs.basedpyright.com/
Other
613 stars 13 forks source link

Implementing Jumpable Symbolic References in Comments #378

Open sena-nana opened 1 month ago

sena-nana commented 1 month ago

In the course of learning Rust recently, I discovered that Rust has the syntax to reference symbols in comments and make them clickable jumps. This feature is often requested in Python as well, but the previous language server wasn't able to provide support for it.

The original Rust syntax is similar to the following.The comment [`Option`] will be recognized as a clickable jump to a defined symbol

/// `add_one` Return[`Option`]
pub fn add_one(x: i32) -> Option<i32> {
    Some(x + 1)
}

Since there isn't a unified comment syntax in Python, I thought it might be possible for basedpyright to add a syntax of its own to implement that functionality, and a similar writeup wouldn't conflict with the three dominant comment styles

The net effect is that symbols marked in comments by this syntax can be highlighted and can be jumped to by the Go to Definition or Go to Reference functions. If not specified, the symbols referenced by this syntax are looked for at the comment location, or in the case of a function or class documentation string, in the scope of the function or class. The location where the symbol is referenced can be specified using a syntax similar to Rust annotations or a syntax defined at the judgment of the basedpyright team.

If basedpyright supports it, perhaps the variable definition not found error could be made valid for this syntax as well?

Thank you very much for your work, this feature doesn't seem to be well implemented, but it's very cool and can bring a huge enhancement to the Python code experience I think.

DetachHead commented 1 month ago

good idea. typescript supports this in jsdoc comments too:

const foo = 1

/** see {@link foo} */
const bar = foo