mirror of
https://github.com/denoland/deno.git
synced 2025-09-24 19:32:30 +00:00
perf(lsp): lazily start the ts server (#28392)
This commit is contained in:
parent
e579440170
commit
0ef3f6ba88
4 changed files with 86 additions and 60 deletions
|
@ -213,9 +213,7 @@ pub struct Inner {
|
|||
registered_semantic_tokens_capabilities: bool,
|
||||
pub resolver: Arc<LspResolver>,
|
||||
task_queue: LanguageServerTaskQueue,
|
||||
/// A memoized version of fixable diagnostic codes retrieved from TypeScript.
|
||||
ts_fixable_diagnostics: Vec<String>,
|
||||
/// An abstraction that handles interactions with TypeScript.
|
||||
ts_fixable_diagnostics: tokio::sync::OnceCell<Vec<String>>,
|
||||
pub ts_server: Arc<TsServer>,
|
||||
/// A map of specifiers and URLs used to translate over the LSP.
|
||||
pub url_map: urls::LspUrlMap,
|
||||
|
@ -621,6 +619,19 @@ impl Inner {
|
|||
})
|
||||
}
|
||||
|
||||
pub async fn ts_fixable_diagnostics(&self) -> &Vec<String> {
|
||||
self
|
||||
.ts_fixable_diagnostics
|
||||
.get_or_init(|| async {
|
||||
self
|
||||
.ts_server
|
||||
.get_supported_code_fixes(self.snapshot())
|
||||
.await
|
||||
.unwrap()
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
pub fn update_tracing(&mut self) {
|
||||
let tracing =
|
||||
self
|
||||
|
@ -777,7 +788,7 @@ impl Inner {
|
|||
|
||||
// lspower::LanguageServer methods. This file's LanguageServer delegates to us.
|
||||
impl Inner {
|
||||
async fn initialize(
|
||||
fn initialize(
|
||||
&mut self,
|
||||
params: InitializeParams,
|
||||
) -> LspResult<InitializeResult> {
|
||||
|
@ -862,26 +873,13 @@ impl Inner {
|
|||
}
|
||||
|
||||
self.diagnostics_server.start();
|
||||
if let Err(e) = self
|
||||
self
|
||||
.ts_server
|
||||
.start(self.config.internal_inspect().to_address())
|
||||
{
|
||||
lsp_warn!("{}", e);
|
||||
self.client.show_message(MessageType::ERROR, e);
|
||||
return Err(tower_lsp::jsonrpc::Error::internal_error());
|
||||
};
|
||||
.set_inspector_server_addr(self.config.internal_inspect().to_address());
|
||||
|
||||
self.update_tracing();
|
||||
self.update_debug_flag();
|
||||
|
||||
if capabilities.code_action_provider.is_some() {
|
||||
let fixable_diagnostics = self
|
||||
.ts_server
|
||||
.get_supported_code_fixes(self.snapshot())
|
||||
.await?;
|
||||
self.ts_fixable_diagnostics = fixable_diagnostics;
|
||||
}
|
||||
|
||||
if capabilities.semantic_tokens_provider.is_some() {
|
||||
self.registered_semantic_tokens_capabilities = true;
|
||||
}
|
||||
|
@ -1746,6 +1744,7 @@ impl Inner {
|
|||
let line_index = asset_or_doc.line_index();
|
||||
|
||||
// QuickFix
|
||||
let ts_fixable_diagnosics = self.ts_fixable_diagnostics().await;
|
||||
let fixable_diagnostics: Vec<&Diagnostic> = params
|
||||
.context
|
||||
.diagnostics
|
||||
|
@ -1754,10 +1753,10 @@ impl Inner {
|
|||
Some(source) => match source.as_str() {
|
||||
"deno-ts" => match &d.code {
|
||||
Some(NumberOrString::String(code)) => {
|
||||
self.ts_fixable_diagnostics.contains(code)
|
||||
ts_fixable_diagnosics.contains(code)
|
||||
}
|
||||
Some(NumberOrString::Number(code)) => {
|
||||
self.ts_fixable_diagnostics.contains(&code.to_string())
|
||||
ts_fixable_diagnosics.contains(&code.to_string())
|
||||
}
|
||||
_ => false,
|
||||
},
|
||||
|
@ -3399,6 +3398,9 @@ impl Inner {
|
|||
params: RenameFilesParams,
|
||||
token: &CancellationToken,
|
||||
) -> LspResult<Option<WorkspaceEdit>> {
|
||||
if !self.ts_server.is_started() {
|
||||
return Ok(None);
|
||||
}
|
||||
let mut changes = vec![];
|
||||
for rename in params.files {
|
||||
let old_specifier = self.url_map.uri_to_specifier(
|
||||
|
@ -3461,6 +3463,10 @@ impl Inner {
|
|||
params: WorkspaceSymbolParams,
|
||||
token: &CancellationToken,
|
||||
) -> LspResult<Option<Vec<SymbolInformation>>> {
|
||||
if !self.ts_server.is_started() {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let mark = self.performance.mark_with_args("lsp.symbol", ¶ms);
|
||||
|
||||
let navigate_to_items = self
|
||||
|
@ -3588,7 +3594,7 @@ impl tower_lsp::LanguageServer for LanguageServer {
|
|||
&self,
|
||||
params: InitializeParams,
|
||||
) -> LspResult<InitializeResult> {
|
||||
self.inner.write().await.initialize(params).await
|
||||
self.inner.write().await.initialize(params)
|
||||
}
|
||||
|
||||
async fn initialized(&self, _: InitializedParams) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue