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

impl item after struct decl, confuses LSP "go to definition" #7025

Open
xunilrj opened this issue Mar 19, 2025 · 2 comments
Open

impl item after struct decl, confuses LSP "go to definition" #7025

xunilrj opened this issue Mar 19, 2025 · 2 comments
Assignees

Comments

@xunilrj
Copy link
Contributor

xunilrj commented Mar 19, 2025

The test go_to_definition_for_structs tests the "go to definition" handler in this file:

contract;

/// My data enum
enum Data {
    First: (),
    Second: (),
}

/// My struct type
struct MyStruct<T, U> {
    g: U,
    x: T,
    y: Data,
    z: (u64, Data),
    t: [Data; 5],
    j: (u32, (Data, [Data; 2])),
    o: Option<Identity>,
}

The request points to "U" of "g: U", and expects the response point to "U" of "struct MyStruct<T, U>". Which works currently; but if an impl item appears after the struct declaration such as

contract;

/// My data enum
enum Data { ... }

/// My struct type
struct MyStruct<T, U> { ... }

trait A {}
impl<T, U> A for MyStruct<T, U> {}

Now, the same "go to definition" request points to the second "U" of the new line "impl<T, U> A for MyStruct<T, U> {}", which is wrong.

@KevinMomanyi
Copy link

Am Kevin Momanyi Web3 developer in smart contract development, decentralized applications, and blockchain security. I have skills in Cairo, and Starknet, with a deep understanding of ZK-rollups and on-chain game mechanics. Am thriving in building scalable, secure, and efficient blockchain solutions, leveraging technologies like Starknet.js, Dojo, and Rust for cutting-edge development. My background in security research gives me a strong edge in writing secure and optimized smart contracts, ensuring reliability and efficiency in Web3 ecosystems.
I have read and understood what the sway project is all about looking forward to contribute in the required time framework. Your effort to assign me the issues will be highly appreciated, thanks.

@Dannynsikak
Copy link

I came across the issue regarding the incorrect "go to definition" behavior when an impl item follows a struct declaration. As a Web3 developer with experience in Rust and blockchain tooling, I have worked extensively with LSPs, compilers, and improving developer workflows.
I understand that the current issue arises due to the request incorrectly resolving to the U in impl<T, U> A for MyStruct<T, U> {} instead of the U in struct MyStruct<T, U>. I would love to investigate and contribute a fix to ensure proper reference resolution.
Looking forward to your guidance on where I can begin. Let me know if i can be assigned this issue .

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 a pull request may close this issue.

3 participants