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

Why type names of this crate don't follow the spec ? #278

Open
wiiznokes opened this issue Feb 26, 2024 · 0 comments
Open

Why type names of this crate don't follow the spec ? #278

wiiznokes opened this issue Feb 26, 2024 · 0 comments

Comments

@wiiznokes
Copy link

Example:

spec:

{
    "method": "textDocument/implementation",
    "result": {
        "kind": "or",
        "items": [
            {
                "kind": "reference",
                "name": "Definition"
            },
            {
                "kind": "array",
                "element": {
                    "kind": "reference",
                    "name": "DefinitionLink"
                }
            },
            {
                "kind": "base",
                "name": "null"
            }
        ]
    },
    "messageDirection": "clientToServer",
    "params": {
        "kind": "reference",
        "name": "ImplementationParams"
    },
    "partialResult": {
        "kind": "or",
        "items": [
            {
                "kind": "array",
                "element": {
                    "kind": "reference",
                    "name": "Location"
                }
            },
            {
                "kind": "array",
                "element": {
                    "kind": "reference",
                    "name": "DefinitionLink"
                }
            }
        ]
    },
    "registrationOptions": {
        "kind": "reference",
        "name": "ImplementationRegistrationOptions"
    },
    "documentation": "A request to resolve the implementation locations of a symbol at a given text\ndocument position. The request's parameter is of type [TextDocumentPositionParams]\n(#TextDocumentPositionParams) the response is of type {@link Definition} or a\nThenable that resolves to such."
}

lsp implementation

#[derive(Debug)]
pub enum GotoImplementation {}

pub type GotoImplementationParams = GotoTypeDefinitionParams;
pub type GotoImplementationResponse = GotoDefinitionResponse;

impl Request for GotoImplementation {
    type Params = GotoImplementationParams;
    type Result = Option<GotoImplementationResponse>;
    const METHOD: &'static str = "textDocument/implementation";
}

what's i would like

#[derive(Debug)]
pub enum ImplementationRequest {}

pub type ImplementationRequestParams = Something;
pub type ImplementationRequestResult = Option<Something2>;

impl Request for ImplementationRequest {
    type Params = ImplementationRequestParams;
    type Result = ImplementationRequestResult;
    const METHOD: &'static str = "textDocument/implementation";
}

This will allow to generate code without depending on rust macro, but on the meta json meta model.

This will have some benefits, expecially for async-lsp.

When rust-analyzer generate an overloading of one method, this is what i get:

fn implementation(&mut self, params: <lsp_request!("textDocument/implementation")as lsp_types::request::Request>::Params)
    -> BoxFuture<'static, Result<<lsp_request!("textDocument/implementation")as lsp_types::request::Request>::Result, Self::Error>>;

which is very much unhelpful.

With predictable names, i could change this to generate:

fn implementation(&mut self, params: ImplementationRequestParams)
    -> BoxFuture<'static, Result<ImplementationRequestResult, Self::Error>>;

Benefits for async-lsp:

  • faster compile time
  • better rust-analyzer integration
  • better documentation access
@wiiznokes wiiznokes changed the title Why the Type name of this crate don't follow the spec ? Why type names of this crate don't follow the spec ? Feb 26, 2024
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