Opt-out of build after initialize#420
Conversation
src/server.rs
Outdated
|
|
||
| let root_path = params.root_path.map(PathBuf::from).expect("No root path"); | ||
| let init_options: Option<InitializationOptions> = params.initialization_options | ||
| .and_then(|options| serde_json::from_value(options) |
There was a problem hiding this comment.
This could be just simplified to serde_json::from_value(options).ok() and not introduce 4 more lines for a debug! but I wanted to add a message in case deserialization fails for the options. Is that okay?
There was a problem hiding this comment.
Is deserialisation more likely to fail here than elsewhere? I would prefer the simpler version I think - this is kinda hard to read.
There was a problem hiding this comment.
@nrc this is somewhat more user-facing and gives LSP clients freedom to pass any JSON config (which is reasonable, since the configs will wildly differ for different servers), hence why I wanted to have a debug or preferably a user warning later that passed config is invalid or unsupported by the current server. Should I simplify that for now?
There was a problem hiding this comment.
I think it is fair to assume that clients will pass valid JSON. They might add options or have options missing and we should handle that gracefully, but if the send malformed JSON, then I think they are not sticking to the LSP and I hope that doesn't happen to often (and the extension developers should hit this before users do).
| })); | ||
| self.handler.init(root_path); | ||
| self.handler.inited().init(self.output.clone()); | ||
| self.handler.inited().init(init_options, self.output.clone()); |
There was a problem hiding this comment.
Not passing init_options to .init() since it'd have to store some state to be useful for .inited().init() and the only supported option right now will be only used once on init, which means it isn't probably worth keeping around. Is that okay for now?
There was a problem hiding this comment.
I'm not sure I understand, but the code looks fine to me.
src/actions/mod.rs
Outdated
| pub fn init<O: Output>(&self, out: O) { | ||
| self.build_current_project(BuildPriority::Cargo, out); | ||
| pub fn init<O: Output>(&self, init_options: Option<InitializationOptions>, out: O) { | ||
| let omit_init_build = init_options.and_then(|x| x.omit_init_build) |
There was a problem hiding this comment.
Should I move default values logic to an impl InitializationOptions?
There was a problem hiding this comment.
Sort of. I would implement Default for InitializationOptions and take a InitializationOptions here, rather than an Option
|
|
|
This version has a simplified default |
| Self::initialize_with_opts(id, root_path, None) | ||
| } | ||
|
|
||
| pub fn initialize_with_opts(id: usize, root_path: Option<String>, initialization_options: Option<InitializationOptions>) -> ServerMessage { |
There was a problem hiding this comment.
We only seem to call this function from a test, I'd expect to see a call when we receive the init message
There was a problem hiding this comment.
@nrc not sure I understand. This creates only a client-specific message. Since server itself has no use for it, it's used only in tests and once for our CLI "client". This is where we parse the additional options when the server receives the initialize request via JSON-RPC and here we're passing it to init action handler.
There was a problem hiding this comment.
oh of course, sorry, I thought this was still in server.rs, I didn't see it was in the tests
Fixes #419.
InitializationOptionsstructure defining options that are supported viainitialization_optionsininitializerequest.initialize, configurable viaomit_init_buildinInitializationOptionsonDidChangeConfigurationand start a Normal build - we always need Cargo as a first to resolve and build deps etc.)