summaryrefslogtreecommitdiff
path: root/cli/lsp/tsc.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2024-04-12 00:17:10 +0100
committerGitHub <noreply@github.com>2024-04-12 01:17:10 +0200
commitf358ae627843182fb6aad69dae74f6d29788956b (patch)
treeb955ef5495bd7c7705aa9dbc909966962d44015f /cli/lsp/tsc.rs
parentade0cd5e97e25896457624a0ec6bf524a5fa5c20 (diff)
fix(inspector): don't panic if port is not free (#22745)
Closes https://github.com/denoland/deno/issues/22113 Closes https://github.com/denoland/deno/issues/23177 Closes https://github.com/denoland/deno/issues/22883 Closes https://github.com/denoland/deno/issues/22377
Diffstat (limited to 'cli/lsp/tsc.rs')
-rw-r--r--cli/lsp/tsc.rs29
1 files changed, 17 insertions, 12 deletions
diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs
index 48ca7355a..2aac251d3 100644
--- a/cli/lsp/tsc.rs
+++ b/cli/lsp/tsc.rs
@@ -36,6 +36,7 @@ use crate::util::path::to_percent_decoded_str;
use dashmap::DashMap;
use deno_ast::MediaType;
use deno_core::anyhow::anyhow;
+use deno_core::anyhow::Context as _;
use deno_core::error::custom_error;
use deno_core::error::AnyError;
use deno_core::futures::FutureExt;
@@ -268,17 +269,20 @@ impl TsServer {
}
}
- pub fn start(&self, inspector_server_addr: Option<String>) {
- let maybe_inspector_server = inspector_server_addr.and_then(|addr| {
- let addr: SocketAddr = match addr.parse() {
- Ok(addr) => addr,
- Err(err) => {
- lsp_warn!("Invalid inspector server address \"{}\": {}", &addr, err);
- return None;
- }
- };
- Some(Arc::new(InspectorServer::new(addr, "deno-lsp-tsc")))
- });
+ pub fn start(
+ &self,
+ inspector_server_addr: Option<String>,
+ ) -> Result<(), AnyError> {
+ let maybe_inspector_server = match inspector_server_addr {
+ Some(addr) => {
+ let addr: SocketAddr = addr.parse().with_context(|| {
+ format!("Invalid inspector server address \"{}\"", &addr)
+ })?;
+ let server = InspectorServer::new(addr, "deno-lsp-tsc")?;
+ Some(Arc::new(server))
+ }
+ None => None,
+ };
*self.inspector_server.lock() = maybe_inspector_server.clone();
// TODO(bartlomieju): why is the join_handle ignored here? Should we store it
// on the `TsServer` struct.
@@ -295,6 +299,7 @@ impl TsServer {
maybe_inspector_server,
)
});
+ Ok(())
}
pub async fn project_changed(
@@ -4750,7 +4755,7 @@ mod tests {
Arc::new(mock_state_snapshot(sources, &location, config).await);
let performance = Arc::new(Performance::default());
let ts_server = TsServer::new(performance, cache.clone());
- ts_server.start(None);
+ ts_server.start(None).unwrap();
(ts_server, snapshot, cache)
}