Use cli.mjs
when available in TypeScript language server
Otherwise, fall back to using `cli.js`.
This commit is contained in:
parent
8e02266d07
commit
9779663c6b
1 changed files with 9 additions and 5 deletions
|
@ -12,7 +12,8 @@ use util::ResultExt;
|
||||||
pub struct TypeScriptLspAdapter;
|
pub struct TypeScriptLspAdapter;
|
||||||
|
|
||||||
impl TypeScriptLspAdapter {
|
impl TypeScriptLspAdapter {
|
||||||
const BIN_PATH: &'static str = "node_modules/typescript-language-server/lib/cli.js";
|
const OLD_BIN_PATH: &'static str = "node_modules/typescript-language-server/lib/cli.js";
|
||||||
|
const NEW_BIN_PATH: &'static str = "node_modules/typescript-language-server/lib/cli.mjs";
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Versions {
|
struct Versions {
|
||||||
|
@ -57,7 +58,7 @@ impl LspAdapter for TypeScriptLspAdapter {
|
||||||
fs::create_dir_all(&version_dir)
|
fs::create_dir_all(&version_dir)
|
||||||
.await
|
.await
|
||||||
.context("failed to create version directory")?;
|
.context("failed to create version directory")?;
|
||||||
let binary_path = version_dir.join(Self::BIN_PATH);
|
let binary_path = version_dir.join(Self::NEW_BIN_PATH);
|
||||||
|
|
||||||
if fs::metadata(&binary_path).await.is_err() {
|
if fs::metadata(&binary_path).await.is_err() {
|
||||||
npm_install_packages(
|
npm_install_packages(
|
||||||
|
@ -98,9 +99,12 @@ impl LspAdapter for TypeScriptLspAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let last_version_dir = last_version_dir.ok_or_else(|| anyhow!("no cached binary"))?;
|
let last_version_dir = last_version_dir.ok_or_else(|| anyhow!("no cached binary"))?;
|
||||||
let bin_path = last_version_dir.join(Self::BIN_PATH);
|
let old_bin_path = last_version_dir.join(Self::OLD_BIN_PATH);
|
||||||
if bin_path.exists() {
|
let new_bin_path = last_version_dir.join(Self::NEW_BIN_PATH);
|
||||||
Ok(bin_path)
|
if new_bin_path.exists() {
|
||||||
|
Ok(new_bin_path)
|
||||||
|
} else if old_bin_path.exists() {
|
||||||
|
Ok(old_bin_path)
|
||||||
} else {
|
} else {
|
||||||
Err(anyhow!(
|
Err(anyhow!(
|
||||||
"missing executable in directory {:?}",
|
"missing executable in directory {:?}",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue