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

leptos_dx: rust-analyzer support in Kate #103

Open
s-mayrh opened this issue May 29, 2024 · 1 comment
Open

leptos_dx: rust-analyzer support in Kate #103

s-mayrh opened this issue May 29, 2024 · 1 comment

Comments

@s-mayrh
Copy link

s-mayrh commented May 29, 2024

Kate's LSP client configuration is its own science. Therefore I want to share my configuration that includes ssr and leptosfmt override:

{
    "servers": {
        "rust": {
            "initializationOptions": {
                "procMacro": {
                    "ignored": {
                        "leptos_macro": [
                            "server"
                        ]
                    }
                },
                "cargo": {
                    "features": ["ssr"]
                },
                "rustfmt": {
                    "overrideCommand": [
                        "leptosfmt", "--stdin", "--rustfmt"
                    ]
                }
            }
        }
    }
}

I did not include the comments

// optional:
// "component",
…
// if code that is cfg-gated for the `ssr` feature is shown as inactive,
// you may want to tell rust-analyzer to enable the `ssr` feature by default
//
// you can also use `rust-analyzer.cargo.allFeatures` to enable all features

because a warning appears that the JSON was invalid if comments are in them. Maybe someone can incorporate this in the book or find another good place where Kate users can find it and @bram209 might find this useful as well for rustfmt.

@s-mayrh
Copy link
Author

s-mayrh commented May 31, 2024

Figured out how to do this on a per-project basis: You need to create a .kateproject file in your Leptos project's root directory that looks like this:

{
    "files": [
        {
            "git": 1
        }
    ],
    "lspclient": {
        "servers": {
            "rust": {
                "initializationOptions": {
                    "procMacro": {
                        "ignored": {
                            "leptos_macro": [
                                "server"
                            ]
                        }
                    },
                    "cargo": {
                        "features": [
                            "ssr", "hydrate"
                        ]
                    },
                    "rustfmt": {
                        "overrideCommand": [
                            "leptosfmt", "--stdin", "--rustfmt"
                        ]
                    }
                }
            }
        }
    }
}

Setting the initial example above in the Kate settings, like I did before, will brake rust-analyzer for other projects not using leptos.

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

No branches or pull requests

1 participant