Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Opt-out of build after initialize#420

Merged
nrc merged 4 commits intorust-lang:masterfrom
Xanewok:init-build
Jul 27, 2017
Merged

Opt-out of build after initialize#420
nrc merged 4 commits intorust-lang:masterfrom
Xanewok:init-build

Conversation

@Xanewok
Copy link
Copy Markdown
Contributor

@Xanewok Xanewok commented Jul 19, 2017

Fixes #419.

  • Introduces new InitializationOptions structure defining options that are supported via initialization_options in initialize request.
  • Allow for not building immediately after initialize, configurable via omit_init_build in InitializationOptions
  • Bump up build priority from Normal to Cargo when compilation context isn't cached yet (in case we omit first build, don't catch onDidChangeConfiguration and start a Normal build - we always need Cargo as a first to resolve and build deps etc.)

@Xanewok Xanewok changed the title Init build Opt-out of build after initialize Jul 19, 2017
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)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is deserialisation more likely to fail here than elsewhere? I would prefer the simpler version I think - this is kinda hard to read.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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());
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure I understand, but the code looks fine to me.

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)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should I move default values logic to an impl InitializationOptions?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sort of. I would implement Default for InitializationOptions and take a InitializationOptions here, rather than an Option

@Xanewok
Copy link
Copy Markdown
Contributor Author

Xanewok commented Jul 19, 2017

x86_64-pc-windows-msvc failed with:

error: could not download file from 'https://static.rust-lang.org/dist/channel-rust-nightly.toml.sha256' to 'C:\Users\appveyor\.rustup\tmp\yfwm5cm7aj55oiqv_file'
info: caused by: error during download
info: caused by: [35] SSL connect error (schannel: next InitializeSecurityContext failed: Unknown error (0x80092013) - The revocation function was unable to check revocation because the revocation server was offline.)

@Xanewok
Copy link
Copy Markdown
Contributor Author

Xanewok commented Jul 26, 2017

This version has a simplified default InitializationOptions, implemented in 4fdd0b1. When fields are missing, they're filled using Default trait and handling parsing error is simplified now.

Self::initialize_with_opts(id, root_path, None)
}

pub fn initialize_with_opts(id: usize, root_path: Option<String>, initialization_options: Option<InitializationOptions>) -> ServerMessage {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We only seem to call this function from a test, I'd expect to see a call when we receive the init message

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

oh of course, sorry, I thought this was still in server.rs, I didn't see it was in the tests

@nrc nrc merged commit 5fb0afd into rust-lang:master Jul 27, 2017
@Xanewok Xanewok deleted the init-build branch July 27, 2017 00:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

opt out of build on init

2 participants