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

Message traits #29

Merged
merged 5 commits into from
Nov 29, 2017
Merged

Message traits #29

merged 5 commits into from
Nov 29, 2017

Conversation

Xanewok
Copy link
Collaborator

@Xanewok Xanewok commented Nov 28, 2017

Attempt at #19. I took some sweet time with this, sorry for doing it so late.

Currently LSP spec provides new CompletionParams and CompletionContext types to be used with Completion Request, so I used LSP commit in the comment and used TextDocumentPositionParams as param type instead.

@Marwes does this align with what you wanted in #19?

@Marwes
Copy link
Member

Marwes commented Nov 28, 2017

Yep! This is pretty much what I wanted in #19. I actually did some further experimentation with this idea a few weeks ago but it never went anywhere since I was never completely happy with the result. Basically I wanted a way to also generate a trait with handler methods as well such as RustLSP uses but where it was fully customisable with respect to method return types. It turned out to not quite work so my efforts fizzled out at that point without me actually implementing this part even...

I think one idea from it can be salvaged to work with this PR. I thought that it might be better to describe the method/notification in terms of their actual name in the spec. So instead of PublishDiagnostics it would be request!("textDocument/publishDiagnostics"). It is perhaps a bit verbose but it might be easier to grep. Could try and implement it for real if it sounds useful, I am more or less undecided at this point.

src/lib.rs Outdated
pub trait Notification {
type Params;
const METHOD: &'static str;
}
Copy link
Member

@Marwes Marwes Nov 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder, would it be better to move the traits and their implementations to submodules so they are not confused with the data holding types? mod rpc or mod notification + mod request?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, actually the thought crossed my mind as well. I'll try to separate it into mod notification + mod request.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Marwes should I move there helper union return values that aren't defined by the protocol, but needed to encode the result type? e.g. https://github.com/gluon-lang/languageserver-types/pull/29/files#diff-b4aea3e418ccdb71239b96952d9cddb6R2000

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could see either place being good. Maybe an argument for keeping them here is that it makes the submodules only hold types that you aren't meant to instantiate (since they don't hold data).

Copy link
Member

@Marwes Marwes Nov 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping them here is referring to the result type you linked to.

src/lib.rs Outdated
@@ -57,6 +70,14 @@ pub enum NumberOrString {
/// A request that got canceled still needs to return from the server and send a response back.
/// It can not be left open / hanging. This is in line with the JSON RPC protocol that requires
/// that every request sends a response back. In addition it allows for returning partial results on cancel.
#[derive(Debug)]
pub struct Cancel;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these types aren't meant to be used as values we could have them as uninhabited enums maybe?

pub enum Cancel { }

That way they can only be used in as types and not values. Or pub struct Cancel(()); so they can't be instantiated.

@Xanewok
Copy link
Collaborator Author

Xanewok commented Nov 29, 2017

Rebased and force-pushed. I toyed with a simple request! macro generating type and impl, to not repeat that much, but I couldn't get doc comments to work with the macro-generated type, so I dropped it for now.

@Marwes
Copy link
Member

Marwes commented Nov 29, 2017

Looks good now I think!

For doc comments/attributes in macros this should match on them, in case you need it in the future https://github.com/Marwes/combine/blob/0dba46ca7a8682e1a048dee7fc9b63d6a588ea21/src/lib.rs#L295-L301

@Marwes Marwes merged commit 86908d3 into gluon-lang:master Nov 29, 2017
@Marwes
Copy link
Member

Marwes commented Nov 29, 2017

Publishes as 0.17.0

I will probably try and port gluon's language server to this over the weekend :)

@Xanewok
Copy link
Collaborator Author

Xanewok commented Nov 29, 2017

Cool, thanks! RLS will probably also benefit from this as well 😄

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 this pull request may close these issues.

2 participants