Use LanguageServerName in more places (#18167)

This pushes the new LanguageServerName type to more places.

As both languages and language servers were identified by Arc<str>, it
was
sometimes hard to tell which was intended.

Release Notes:

- N/A
This commit is contained in:
Conrad Irwin 2024-09-20 18:51:34 -06:00 committed by GitHub
parent 743feb98bc
commit 4f227fd3bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 150 additions and 85 deletions

View file

@ -13,13 +13,13 @@ use util::{fs::remove_matching, maybe, ResultExt};
pub struct CLspAdapter;
impl CLspAdapter {
const SERVER_NAME: &'static str = "clangd";
const SERVER_NAME: LanguageServerName = LanguageServerName::new_static("clangd");
}
#[async_trait(?Send)]
impl super::LspAdapter for CLspAdapter {
fn name(&self) -> LanguageServerName {
LanguageServerName(Self::SERVER_NAME.into())
Self::SERVER_NAME.clone()
}
async fn check_if_user_installed(
@ -28,7 +28,8 @@ impl super::LspAdapter for CLspAdapter {
cx: &AsyncAppContext,
) -> Option<LanguageServerBinary> {
let configured_binary = cx.update(|cx| {
language_server_settings(delegate, Self::SERVER_NAME, cx).and_then(|s| s.binary.clone())
language_server_settings(delegate, &Self::SERVER_NAME, cx)
.and_then(|s| s.binary.clone())
});
match configured_binary {

View file

@ -33,7 +33,7 @@ fn server_binary_arguments() -> Vec<OsString> {
pub struct GoLspAdapter;
impl GoLspAdapter {
const SERVER_NAME: &'static str = "gopls";
const SERVER_NAME: LanguageServerName = LanguageServerName::new_static("gopls");
}
static GOPLS_VERSION_REGEX: LazyLock<Regex> =
@ -46,7 +46,7 @@ static GO_ESCAPE_SUBTEST_NAME_REGEX: LazyLock<Regex> = LazyLock::new(|| {
#[async_trait(?Send)]
impl super::LspAdapter for GoLspAdapter {
fn name(&self) -> LanguageServerName {
LanguageServerName(Self::SERVER_NAME.into())
Self::SERVER_NAME.clone()
}
async fn fetch_latest_server_version(
@ -71,7 +71,8 @@ impl super::LspAdapter for GoLspAdapter {
cx: &AsyncAppContext,
) -> Option<LanguageServerBinary> {
let configured_binary = cx.update(|cx| {
language_server_settings(delegate, Self::SERVER_NAME, cx).and_then(|s| s.binary.clone())
language_server_settings(delegate, &Self::SERVER_NAME, cx)
.and_then(|s| s.binary.clone())
});
match configured_binary {

View file

@ -30,7 +30,7 @@ pub struct PythonLspAdapter {
}
impl PythonLspAdapter {
const SERVER_NAME: &'static str = "pyright";
const SERVER_NAME: LanguageServerName = LanguageServerName::new_static("pyright");
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
PythonLspAdapter { node }
@ -40,7 +40,7 @@ impl PythonLspAdapter {
#[async_trait(?Send)]
impl LspAdapter for PythonLspAdapter {
fn name(&self) -> LanguageServerName {
LanguageServerName(Self::SERVER_NAME.into())
Self::SERVER_NAME.clone()
}
async fn fetch_latest_server_version(
@ -49,7 +49,7 @@ impl LspAdapter for PythonLspAdapter {
) -> Result<Box<dyn 'static + Any + Send>> {
Ok(Box::new(
self.node
.npm_package_latest_version(Self::SERVER_NAME)
.npm_package_latest_version(Self::SERVER_NAME.as_ref())
.await?,
) as Box<_>)
}
@ -62,16 +62,23 @@ impl LspAdapter for PythonLspAdapter {
) -> Result<LanguageServerBinary> {
let latest_version = latest_version.downcast::<String>().unwrap();
let server_path = container_dir.join(SERVER_PATH);
let package_name = Self::SERVER_NAME;
let should_install_language_server = self
.node
.should_install_npm_package(package_name, &server_path, &container_dir, &latest_version)
.should_install_npm_package(
Self::SERVER_NAME.as_ref(),
&server_path,
&container_dir,
&latest_version,
)
.await;
if should_install_language_server {
self.node
.npm_install_packages(&container_dir, &[(package_name, latest_version.as_str())])
.npm_install_packages(
&container_dir,
&[(Self::SERVER_NAME.as_ref(), latest_version.as_str())],
)
.await?;
}
@ -182,7 +189,7 @@ impl LspAdapter for PythonLspAdapter {
cx: &mut AsyncAppContext,
) -> Result<Value> {
cx.update(|cx| {
language_server_settings(adapter.as_ref(), Self::SERVER_NAME, cx)
language_server_settings(adapter.as_ref(), &Self::SERVER_NAME, cx)
.and_then(|s| s.settings.clone())
.unwrap_or_default()
})

View file

@ -25,13 +25,13 @@ use util::{fs::remove_matching, maybe, ResultExt};
pub struct RustLspAdapter;
impl RustLspAdapter {
const SERVER_NAME: &'static str = "rust-analyzer";
const SERVER_NAME: LanguageServerName = LanguageServerName::new_static("rust-analyzer");
}
#[async_trait(?Send)]
impl LspAdapter for RustLspAdapter {
fn name(&self) -> LanguageServerName {
LanguageServerName(Self::SERVER_NAME.into())
Self::SERVER_NAME.clone()
}
async fn check_if_user_installed(
@ -41,7 +41,7 @@ impl LspAdapter for RustLspAdapter {
) -> Option<LanguageServerBinary> {
let configured_binary = cx
.update(|cx| {
language_server_settings(delegate, Self::SERVER_NAME, cx)
language_server_settings(delegate, &Self::SERVER_NAME, cx)
.and_then(|s| s.binary.clone())
})
.ok()?;
@ -60,7 +60,7 @@ impl LspAdapter for RustLspAdapter {
path_lookup: None,
..
}) => {
let path = delegate.which(Self::SERVER_NAME.as_ref()).await;
let path = delegate.which("rust-analyzer".as_ref()).await;
let env = delegate.shell_env().await;
if let Some(path) = path {

View file

@ -32,7 +32,8 @@ pub struct TailwindLspAdapter {
}
impl TailwindLspAdapter {
const SERVER_NAME: &'static str = "tailwindcss-language-server";
const SERVER_NAME: LanguageServerName =
LanguageServerName::new_static("tailwindcss-language-server");
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
TailwindLspAdapter { node }
@ -42,7 +43,7 @@ impl TailwindLspAdapter {
#[async_trait(?Send)]
impl LspAdapter for TailwindLspAdapter {
fn name(&self) -> LanguageServerName {
LanguageServerName(Self::SERVER_NAME.into())
Self::SERVER_NAME.clone()
}
async fn check_if_user_installed(
@ -52,7 +53,7 @@ impl LspAdapter for TailwindLspAdapter {
) -> Option<LanguageServerBinary> {
let configured_binary = cx
.update(|cx| {
language_server_settings(delegate, Self::SERVER_NAME, cx)
language_server_settings(delegate, &Self::SERVER_NAME, cx)
.and_then(|s| s.binary.clone())
})
.ok()??;
@ -152,7 +153,7 @@ impl LspAdapter for TailwindLspAdapter {
cx: &mut AsyncAppContext,
) -> Result<Value> {
let tailwind_user_settings = cx.update(|cx| {
language_server_settings(delegate.as_ref(), Self::SERVER_NAME, cx)
language_server_settings(delegate.as_ref(), &Self::SERVER_NAME, cx)
.and_then(|s| s.settings.clone())
.unwrap_or_default()
})?;

View file

@ -71,7 +71,8 @@ pub struct TypeScriptLspAdapter {
impl TypeScriptLspAdapter {
const OLD_SERVER_PATH: &'static str = "node_modules/typescript-language-server/lib/cli.js";
const NEW_SERVER_PATH: &'static str = "node_modules/typescript-language-server/lib/cli.mjs";
const SERVER_NAME: &'static str = "typescript-language-server";
const SERVER_NAME: LanguageServerName =
LanguageServerName::new_static("typescript-language-server");
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
TypeScriptLspAdapter { node }
}
@ -97,7 +98,7 @@ struct TypeScriptVersions {
#[async_trait(?Send)]
impl LspAdapter for TypeScriptLspAdapter {
fn name(&self) -> LanguageServerName {
LanguageServerName(Self::SERVER_NAME.into())
Self::SERVER_NAME.clone()
}
async fn fetch_latest_server_version(
@ -239,7 +240,7 @@ impl LspAdapter for TypeScriptLspAdapter {
cx: &mut AsyncAppContext,
) -> Result<Value> {
let override_options = cx.update(|cx| {
language_server_settings(delegate.as_ref(), Self::SERVER_NAME, cx)
language_server_settings(delegate.as_ref(), &Self::SERVER_NAME, cx)
.and_then(|s| s.settings.clone())
})?;
if let Some(options) = override_options {
@ -304,7 +305,7 @@ impl EsLintLspAdapter {
const GITHUB_ASSET_KIND: AssetKind = AssetKind::Zip;
const SERVER_PATH: &'static str = "vscode-eslint/server/out/eslintServer.js";
const SERVER_NAME: &'static str = "eslint";
const SERVER_NAME: LanguageServerName = LanguageServerName::new_static("eslint");
const FLAT_CONFIG_FILE_NAMES: &'static [&'static str] =
&["eslint.config.js", "eslint.config.mjs", "eslint.config.cjs"];
@ -331,7 +332,7 @@ impl LspAdapter for EsLintLspAdapter {
let workspace_root = delegate.worktree_root_path();
let eslint_user_settings = cx.update(|cx| {
language_server_settings(delegate.as_ref(), Self::SERVER_NAME, cx)
language_server_settings(delegate.as_ref(), &Self::SERVER_NAME, cx)
.and_then(|s| s.settings.clone())
.unwrap_or_default()
})?;
@ -403,7 +404,7 @@ impl LspAdapter for EsLintLspAdapter {
}
fn name(&self) -> LanguageServerName {
LanguageServerName(Self::SERVER_NAME.into())
Self::SERVER_NAME.clone()
}
async fn fetch_latest_server_version(

View file

@ -48,11 +48,11 @@ struct TypeScriptVersions {
server_version: String,
}
const SERVER_NAME: &str = "vtsls";
const SERVER_NAME: LanguageServerName = LanguageServerName::new_static("vtsls");
#[async_trait(?Send)]
impl LspAdapter for VtslsLspAdapter {
fn name(&self) -> LanguageServerName {
LanguageServerName(SERVER_NAME.into())
SERVER_NAME.clone()
}
async fn fetch_latest_server_version(
@ -74,7 +74,7 @@ impl LspAdapter for VtslsLspAdapter {
cx: &AsyncAppContext,
) -> Option<LanguageServerBinary> {
let configured_binary = cx.update(|cx| {
language_server_settings(delegate, SERVER_NAME, cx).and_then(|s| s.binary.clone())
language_server_settings(delegate, &SERVER_NAME, cx).and_then(|s| s.binary.clone())
});
match configured_binary {
@ -267,7 +267,7 @@ impl LspAdapter for VtslsLspAdapter {
cx: &mut AsyncAppContext,
) -> Result<Value> {
let override_options = cx.update(|cx| {
language_server_settings(delegate.as_ref(), SERVER_NAME, cx)
language_server_settings(delegate.as_ref(), &SERVER_NAME, cx)
.and_then(|s| s.settings.clone())
})?;

View file

@ -30,7 +30,7 @@ pub struct YamlLspAdapter {
}
impl YamlLspAdapter {
const SERVER_NAME: &'static str = "yaml-language-server";
const SERVER_NAME: LanguageServerName = LanguageServerName::new_static("yaml-language-server");
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
YamlLspAdapter { node }
}
@ -39,7 +39,7 @@ impl YamlLspAdapter {
#[async_trait(?Send)]
impl LspAdapter for YamlLspAdapter {
fn name(&self) -> LanguageServerName {
LanguageServerName(Self::SERVER_NAME.into())
Self::SERVER_NAME.clone()
}
async fn check_if_user_installed(
@ -49,7 +49,7 @@ impl LspAdapter for YamlLspAdapter {
) -> Option<LanguageServerBinary> {
let configured_binary = cx
.update(|cx| {
language_server_settings(delegate, Self::SERVER_NAME, cx)
language_server_settings(delegate, &Self::SERVER_NAME, cx)
.and_then(|s| s.binary.clone())
})
.ok()??;
@ -145,7 +145,7 @@ impl LspAdapter for YamlLspAdapter {
let mut options = serde_json::json!({"[yaml]": {"editor.tabSize": tab_size}});
let project_options = cx.update(|cx| {
language_server_settings(delegate.as_ref(), Self::SERVER_NAME, cx)
language_server_settings(delegate.as_ref(), &Self::SERVER_NAME, cx)
.and_then(|s| s.settings.clone())
})?;
if let Some(override_options) = project_options {