Allow extensions to define more of the methods in the LspAdapter trait (#9554)
Our goal is to extract Svelte support into an extension, since we've seen problems with the Tree-sitter Svelte parser crashing due to bugs in the external scanner. In order to do this, we need a couple more capabilities in LSP extensions: * [x] `initialization_options` - programmatically controlling the JSON initialization params sent to the language server * [x] `prettier_plugins` - statically specifying a list of prettier plugins that apply for a given language. * [x] `npm_install_package` Release Notes: - N/A --------- Co-authored-by: Marshall <marshall@zed.dev> Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
This commit is contained in:
parent
0ce5cdc48f
commit
d699b8e104
26 changed files with 318 additions and 208 deletions
|
@ -63,7 +63,7 @@ pub enum LanguageServerBinaryStatus {
|
|||
|
||||
pub struct PendingLanguageServer {
|
||||
pub server_id: LanguageServerId,
|
||||
pub task: Task<Result<lsp::LanguageServer>>,
|
||||
pub task: Task<Result<(lsp::LanguageServer, Option<serde_json::Value>)>>,
|
||||
pub container_dir: Option<Arc<Path>>,
|
||||
}
|
||||
|
||||
|
@ -629,6 +629,15 @@ impl LanguageRegistry {
|
|||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn all_prettier_plugins(&self) -> Vec<Arc<str>> {
|
||||
let state = self.state.read();
|
||||
state
|
||||
.languages
|
||||
.iter()
|
||||
.flat_map(|language| language.config.prettier_plugins.iter().cloned())
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn update_lsp_status(
|
||||
&self,
|
||||
server_name: LanguageServerName,
|
||||
|
@ -680,6 +689,12 @@ impl LanguageRegistry {
|
|||
)
|
||||
.await?;
|
||||
|
||||
let options = adapter
|
||||
.adapter
|
||||
.clone()
|
||||
.initialization_options(&delegate)
|
||||
.await?;
|
||||
|
||||
if let Some(task) = adapter.will_start_server(&delegate, &mut cx) {
|
||||
task.await?;
|
||||
}
|
||||
|
@ -727,18 +742,21 @@ impl LanguageRegistry {
|
|||
})
|
||||
.detach();
|
||||
|
||||
return Ok(server);
|
||||
return Ok((server, options));
|
||||
}
|
||||
|
||||
drop(this);
|
||||
lsp::LanguageServer::new(
|
||||
stderr_capture,
|
||||
server_id,
|
||||
binary,
|
||||
&root_path,
|
||||
adapter.code_action_kinds(),
|
||||
cx,
|
||||
)
|
||||
Ok((
|
||||
lsp::LanguageServer::new(
|
||||
stderr_capture,
|
||||
server_id,
|
||||
binary,
|
||||
&root_path,
|
||||
adapter.code_action_kinds(),
|
||||
cx,
|
||||
)?,
|
||||
options,
|
||||
))
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue