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

Model inheritance using macros? #147

Open
kjeremy opened this issue Mar 2, 2020 · 0 comments
Open

Model inheritance using macros? #147

kjeremy opened this issue Mar 2, 2020 · 0 comments

Comments

@kjeremy
Copy link
Contributor

kjeremy commented Mar 2, 2020

We currently model inheritance using #[serde(flatten)] like below:

#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CompletionParams {
    // This field was "mixed-in" from TextDocumentPositionParams
    #[serde(flatten)]
    pub text_document_position: TextDocumentPositionParams,


    #[serde(flatten)]
    pub work_done_progress_params: WorkDoneProgressParams,


    #[serde(flatten)]
    pub partial_result_params: PartialResultParams,


    // CompletionParams properties:
    #[serde(skip_serializing_if = "Option::is_none")]
    pub context: Option<CompletionContext>,
}

The above corresponds to the following typescript

export interface CompletionParams extends TextDocumentPositionParams, WorkDoneProgressParams, PartialResultParams {


	/**
	 * The completion context. This is only available it the client specifies
	 * to send this using the client capability `textDocument.completion.contextSupport === true`
	 */
	context?: CompletionContext;
}

This becomes difficult to maintain when a concept like partial results or progress are added to the protocol (which changes server and client caps, params and result types). Maybe we should investigate a macro (or custom derive?) approach to make this sort of thing easier and less error prone.

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