languages: Pass fs into the init function (#38007)
Release Notes: - N/A --------- Co-authored-by: Cole Miller <cole@zed.dev>
This commit is contained in:
co-authored by
Cole Miller
parent
46aa05e240
commit
3cb3f01406
@@ -5,7 +5,7 @@ use gpui::AsyncApp;
|
||||
use language::{LspAdapter, LspAdapterDelegate, Toolchain};
|
||||
use lsp::{LanguageServerBinary, LanguageServerName};
|
||||
use node_runtime::{NodeRuntime, VersionStrategy};
|
||||
use project::{Fs, lsp_store::language_server_settings};
|
||||
use project::lsp_store::language_server_settings;
|
||||
use serde_json::json;
|
||||
use smol::fs;
|
||||
use std::{
|
||||
@@ -133,7 +133,6 @@ impl LspAdapter for CssLspAdapter {
|
||||
|
||||
async fn initialization_options(
|
||||
self: Arc<Self>,
|
||||
_: &dyn Fs,
|
||||
_: &Arc<dyn LspAdapterDelegate>,
|
||||
) -> Result<Option<serde_json::Value>> {
|
||||
Ok(Some(json!({
|
||||
@@ -143,7 +142,6 @@ impl LspAdapter for CssLspAdapter {
|
||||
|
||||
async fn workspace_configuration(
|
||||
self: Arc<Self>,
|
||||
_: &dyn Fs,
|
||||
delegate: &Arc<dyn LspAdapterDelegate>,
|
||||
_: Option<Toolchain>,
|
||||
cx: &mut AsyncApp,
|
||||
|
||||
@@ -6,7 +6,7 @@ use gpui::{App, AsyncApp, Task};
|
||||
use http_client::github::latest_github_release;
|
||||
pub use language::*;
|
||||
use lsp::{LanguageServerBinary, LanguageServerName};
|
||||
use project::Fs;
|
||||
|
||||
use regex::Regex;
|
||||
use serde_json::json;
|
||||
use smol::fs;
|
||||
@@ -200,7 +200,6 @@ impl super::LspAdapter for GoLspAdapter {
|
||||
|
||||
async fn initialization_options(
|
||||
self: Arc<Self>,
|
||||
_: &dyn Fs,
|
||||
_: &Arc<dyn LspAdapterDelegate>,
|
||||
) -> Result<Option<serde_json::Value>> {
|
||||
Ok(Some(json!({
|
||||
@@ -568,12 +567,7 @@ impl ContextProvider for GoContextProvider {
|
||||
)))
|
||||
}
|
||||
|
||||
fn associated_tasks(
|
||||
&self,
|
||||
_: Arc<dyn Fs>,
|
||||
_: Option<Arc<dyn File>>,
|
||||
_: &App,
|
||||
) -> Task<Option<TaskTemplates>> {
|
||||
fn associated_tasks(&self, _: Option<Arc<dyn File>>, _: &App) -> Task<Option<TaskTemplates>> {
|
||||
let package_cwd = if GO_PACKAGE_TASK_VARIABLE.template_value() == "." {
|
||||
None
|
||||
} else {
|
||||
|
||||
@@ -13,7 +13,7 @@ use language::{
|
||||
};
|
||||
use lsp::{LanguageServerBinary, LanguageServerName};
|
||||
use node_runtime::{NodeRuntime, VersionStrategy};
|
||||
use project::{Fs, lsp_store::language_server_settings};
|
||||
use project::lsp_store::language_server_settings;
|
||||
use serde_json::{Value, json};
|
||||
use settings::{KeymapFile, SettingsJsonSchemaParams, SettingsStore};
|
||||
use smol::{
|
||||
@@ -46,7 +46,6 @@ pub(crate) struct JsonTaskProvider;
|
||||
impl ContextProvider for JsonTaskProvider {
|
||||
fn associated_tasks(
|
||||
&self,
|
||||
_: Arc<dyn Fs>,
|
||||
file: Option<Arc<dyn language::File>>,
|
||||
cx: &App,
|
||||
) -> gpui::Task<Option<TaskTemplates>> {
|
||||
@@ -393,7 +392,6 @@ impl LspAdapter for JsonLspAdapter {
|
||||
|
||||
async fn initialization_options(
|
||||
self: Arc<Self>,
|
||||
_: &dyn Fs,
|
||||
_: &Arc<dyn LspAdapterDelegate>,
|
||||
) -> Result<Option<serde_json::Value>> {
|
||||
Ok(Some(json!({
|
||||
@@ -403,7 +401,6 @@ impl LspAdapter for JsonLspAdapter {
|
||||
|
||||
async fn workspace_configuration(
|
||||
self: Arc<Self>,
|
||||
_: &dyn Fs,
|
||||
delegate: &Arc<dyn LspAdapterDelegate>,
|
||||
_: Option<Toolchain>,
|
||||
cx: &mut AsyncApp,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use anyhow::Context as _;
|
||||
use gpui::{App, SharedString, UpdateGlobal};
|
||||
use node_runtime::NodeRuntime;
|
||||
use project::Fs;
|
||||
use python::PyprojectTomlManifestProvider;
|
||||
use rust::CargoManifestProvider;
|
||||
use rust_embed::RustEmbed;
|
||||
@@ -53,7 +54,7 @@ pub static LANGUAGE_GIT_COMMIT: std::sync::LazyLock<Arc<Language>> =
|
||||
))
|
||||
});
|
||||
|
||||
pub fn init(languages: Arc<LanguageRegistry>, node: NodeRuntime, cx: &mut App) {
|
||||
pub fn init(languages: Arc<LanguageRegistry>, fs: Arc<dyn Fs>, node: NodeRuntime, cx: &mut App) {
|
||||
#[cfg(feature = "load-grammars")]
|
||||
languages.register_native_grammars([
|
||||
("bash", tree_sitter_bash::LANGUAGE),
|
||||
@@ -94,9 +95,12 @@ pub fn init(languages: Arc<LanguageRegistry>, node: NodeRuntime, cx: &mut App) {
|
||||
let rust_context_provider = Arc::new(rust::RustContextProvider);
|
||||
let rust_lsp_adapter = Arc::new(rust::RustLspAdapter);
|
||||
let tailwind_adapter = Arc::new(tailwind::TailwindLspAdapter::new(node.clone()));
|
||||
let typescript_context = Arc::new(typescript::TypeScriptContextProvider::new());
|
||||
let typescript_lsp_adapter = Arc::new(typescript::TypeScriptLspAdapter::new(node.clone()));
|
||||
let vtsls_adapter = Arc::new(vtsls::VtslsLspAdapter::new(node.clone()));
|
||||
let typescript_context = Arc::new(typescript::TypeScriptContextProvider::new(fs.clone()));
|
||||
let typescript_lsp_adapter = Arc::new(typescript::TypeScriptLspAdapter::new(
|
||||
node.clone(),
|
||||
fs.clone(),
|
||||
));
|
||||
let vtsls_adapter = Arc::new(vtsls::VtslsLspAdapter::new(node.clone(), fs.clone()));
|
||||
let yaml_lsp_adapter = Arc::new(yaml::YamlLspAdapter::new(node));
|
||||
|
||||
let built_in_languages = [
|
||||
|
||||
@@ -119,7 +119,6 @@ impl LspAdapter for PythonLspAdapter {
|
||||
|
||||
async fn initialization_options(
|
||||
self: Arc<Self>,
|
||||
_: &dyn Fs,
|
||||
_: &Arc<dyn LspAdapterDelegate>,
|
||||
) -> Result<Option<Value>> {
|
||||
// Provide minimal initialization options
|
||||
@@ -324,7 +323,7 @@ impl LspAdapter for PythonLspAdapter {
|
||||
|
||||
async fn workspace_configuration(
|
||||
self: Arc<Self>,
|
||||
_: &dyn Fs,
|
||||
|
||||
adapter: &Arc<dyn LspAdapterDelegate>,
|
||||
toolchain: Option<Toolchain>,
|
||||
cx: &mut AsyncApp,
|
||||
@@ -471,7 +470,6 @@ impl ContextProvider for PythonContextProvider {
|
||||
|
||||
fn associated_tasks(
|
||||
&self,
|
||||
_: Arc<dyn Fs>,
|
||||
file: Option<Arc<dyn language::File>>,
|
||||
cx: &App,
|
||||
) -> Task<Option<TaskTemplates>> {
|
||||
@@ -1270,7 +1268,6 @@ impl LspAdapter for PyLspAdapter {
|
||||
|
||||
async fn workspace_configuration(
|
||||
self: Arc<Self>,
|
||||
_: &dyn Fs,
|
||||
adapter: &Arc<dyn LspAdapterDelegate>,
|
||||
toolchain: Option<Toolchain>,
|
||||
cx: &mut AsyncApp,
|
||||
@@ -1405,7 +1402,6 @@ impl LspAdapter for BasedPyrightLspAdapter {
|
||||
|
||||
async fn initialization_options(
|
||||
self: Arc<Self>,
|
||||
_: &dyn Fs,
|
||||
_: &Arc<dyn LspAdapterDelegate>,
|
||||
) -> Result<Option<Value>> {
|
||||
// Provide minimal initialization options
|
||||
@@ -1576,7 +1572,6 @@ impl LspAdapter for BasedPyrightLspAdapter {
|
||||
|
||||
async fn workspace_configuration(
|
||||
self: Arc<Self>,
|
||||
_: &dyn Fs,
|
||||
adapter: &Arc<dyn LspAdapterDelegate>,
|
||||
toolchain: Option<Toolchain>,
|
||||
cx: &mut AsyncApp,
|
||||
|
||||
@@ -7,7 +7,6 @@ use http_client::github::AssetKind;
|
||||
use http_client::github::{GitHubLspBinaryVersion, latest_github_release};
|
||||
pub use language::*;
|
||||
use lsp::{InitializeParams, LanguageServerBinary};
|
||||
use project::Fs;
|
||||
use project::lsp_store::rust_analyzer_ext::CARGO_DIAGNOSTICS_SOURCE_NAME;
|
||||
use project::project_settings::ProjectSettings;
|
||||
use regex::Regex;
|
||||
@@ -632,7 +631,6 @@ impl ContextProvider for RustContextProvider {
|
||||
|
||||
fn associated_tasks(
|
||||
&self,
|
||||
_: Arc<dyn Fs>,
|
||||
file: Option<Arc<dyn language::File>>,
|
||||
cx: &App,
|
||||
) -> Task<Option<TaskTemplates>> {
|
||||
|
||||
@@ -6,7 +6,7 @@ use gpui::AsyncApp;
|
||||
use language::{LanguageName, LspAdapter, LspAdapterDelegate, Toolchain};
|
||||
use lsp::{LanguageServerBinary, LanguageServerName};
|
||||
use node_runtime::{NodeRuntime, VersionStrategy};
|
||||
use project::{Fs, lsp_store::language_server_settings};
|
||||
use project::lsp_store::language_server_settings;
|
||||
use serde_json::{Value, json};
|
||||
use smol::fs;
|
||||
use std::{
|
||||
@@ -138,7 +138,6 @@ impl LspAdapter for TailwindLspAdapter {
|
||||
|
||||
async fn initialization_options(
|
||||
self: Arc<Self>,
|
||||
_: &dyn Fs,
|
||||
_: &Arc<dyn LspAdapterDelegate>,
|
||||
) -> Result<Option<serde_json::Value>> {
|
||||
Ok(Some(json!({
|
||||
@@ -154,7 +153,6 @@ impl LspAdapter for TailwindLspAdapter {
|
||||
|
||||
async fn workspace_configuration(
|
||||
self: Arc<Self>,
|
||||
_: &dyn Fs,
|
||||
delegate: &Arc<dyn LspAdapterDelegate>,
|
||||
_: Option<Toolchain>,
|
||||
cx: &mut AsyncApp,
|
||||
|
||||
@@ -27,8 +27,8 @@ use util::{ResultExt, fs::remove_matching, maybe};
|
||||
|
||||
use crate::{PackageJson, PackageJsonData, github_download::download_server_binary};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct TypeScriptContextProvider {
|
||||
fs: Arc<dyn Fs>,
|
||||
last_package_json: PackageJsonContents,
|
||||
}
|
||||
|
||||
@@ -253,8 +253,9 @@ impl PackageJsonData {
|
||||
}
|
||||
|
||||
impl TypeScriptContextProvider {
|
||||
pub fn new() -> Self {
|
||||
pub fn new(fs: Arc<dyn Fs>) -> Self {
|
||||
Self {
|
||||
fs,
|
||||
last_package_json: PackageJsonContents::default(),
|
||||
}
|
||||
}
|
||||
@@ -358,7 +359,6 @@ async fn detect_package_manager(
|
||||
impl ContextProvider for TypeScriptContextProvider {
|
||||
fn associated_tasks(
|
||||
&self,
|
||||
fs: Arc<dyn Fs>,
|
||||
file: Option<Arc<dyn File>>,
|
||||
cx: &App,
|
||||
) -> Task<Option<TaskTemplates>> {
|
||||
@@ -369,8 +369,12 @@ impl ContextProvider for TypeScriptContextProvider {
|
||||
return Task::ready(None);
|
||||
};
|
||||
let file_relative_path = file.path().clone();
|
||||
let package_json_data =
|
||||
self.combined_package_json_data(fs.clone(), &worktree_root, &file_relative_path, cx);
|
||||
let package_json_data = self.combined_package_json_data(
|
||||
self.fs.clone(),
|
||||
&worktree_root,
|
||||
&file_relative_path,
|
||||
cx,
|
||||
);
|
||||
|
||||
cx.background_spawn(async move {
|
||||
let mut task_templates = TaskTemplates(Vec::new());
|
||||
@@ -514,6 +518,7 @@ fn replace_test_name_parameters(test_name: &str) -> String {
|
||||
}
|
||||
|
||||
pub struct TypeScriptLspAdapter {
|
||||
fs: Arc<dyn Fs>,
|
||||
node: NodeRuntime,
|
||||
}
|
||||
|
||||
@@ -523,10 +528,10 @@ impl TypeScriptLspAdapter {
|
||||
const SERVER_NAME: LanguageServerName =
|
||||
LanguageServerName::new_static("typescript-language-server");
|
||||
const PACKAGE_NAME: &str = "typescript";
|
||||
pub fn new(node: NodeRuntime) -> Self {
|
||||
TypeScriptLspAdapter { node }
|
||||
pub fn new(node: NodeRuntime, fs: Arc<dyn Fs>) -> Self {
|
||||
TypeScriptLspAdapter { fs, node }
|
||||
}
|
||||
async fn tsdk_path(fs: &dyn Fs, adapter: &Arc<dyn LspAdapterDelegate>) -> Option<&'static str> {
|
||||
async fn tsdk_path(&self, adapter: &Arc<dyn LspAdapterDelegate>) -> Option<&'static str> {
|
||||
let is_yarn = adapter
|
||||
.read_text_file(PathBuf::from(".yarn/sdks/typescript/lib/typescript.js"))
|
||||
.await
|
||||
@@ -538,7 +543,8 @@ impl TypeScriptLspAdapter {
|
||||
"node_modules/typescript/lib"
|
||||
};
|
||||
|
||||
if fs
|
||||
if self
|
||||
.fs
|
||||
.is_dir(&adapter.worktree_root_path().join(tsdk_path))
|
||||
.await
|
||||
{
|
||||
@@ -696,10 +702,9 @@ impl LspAdapter for TypeScriptLspAdapter {
|
||||
|
||||
async fn initialization_options(
|
||||
self: Arc<Self>,
|
||||
fs: &dyn Fs,
|
||||
adapter: &Arc<dyn LspAdapterDelegate>,
|
||||
) -> Result<Option<serde_json::Value>> {
|
||||
let tsdk_path = Self::tsdk_path(fs, adapter).await;
|
||||
let tsdk_path = self.tsdk_path(adapter).await;
|
||||
Ok(Some(json!({
|
||||
"provideFormatter": true,
|
||||
"hostInfo": "zed",
|
||||
@@ -721,7 +726,7 @@ impl LspAdapter for TypeScriptLspAdapter {
|
||||
|
||||
async fn workspace_configuration(
|
||||
self: Arc<Self>,
|
||||
_: &dyn Fs,
|
||||
|
||||
delegate: &Arc<dyn LspAdapterDelegate>,
|
||||
_: Option<Toolchain>,
|
||||
cx: &mut AsyncApp,
|
||||
@@ -821,7 +826,6 @@ impl LspAdapter for EsLintLspAdapter {
|
||||
|
||||
async fn workspace_configuration(
|
||||
self: Arc<Self>,
|
||||
_: &dyn Fs,
|
||||
delegate: &Arc<dyn LspAdapterDelegate>,
|
||||
_: Option<Toolchain>,
|
||||
cx: &mut AsyncApp,
|
||||
@@ -1145,7 +1149,7 @@ mod tests {
|
||||
)
|
||||
.await;
|
||||
|
||||
let provider = TypeScriptContextProvider::new();
|
||||
let provider = TypeScriptContextProvider::new(fs.clone());
|
||||
let package_json_data = cx
|
||||
.update(|cx| {
|
||||
provider.combined_package_json_data(
|
||||
|
||||
@@ -21,6 +21,7 @@ fn typescript_server_binary_arguments(server_path: &Path) -> Vec<OsString> {
|
||||
|
||||
pub struct VtslsLspAdapter {
|
||||
node: NodeRuntime,
|
||||
fs: Arc<dyn Fs>,
|
||||
}
|
||||
|
||||
impl VtslsLspAdapter {
|
||||
@@ -30,11 +31,11 @@ impl VtslsLspAdapter {
|
||||
const TYPESCRIPT_PACKAGE_NAME: &'static str = "typescript";
|
||||
const TYPESCRIPT_TSDK_PATH: &'static str = "node_modules/typescript/lib";
|
||||
|
||||
pub fn new(node: NodeRuntime) -> Self {
|
||||
VtslsLspAdapter { node }
|
||||
pub fn new(node: NodeRuntime, fs: Arc<dyn Fs>) -> Self {
|
||||
VtslsLspAdapter { node, fs }
|
||||
}
|
||||
|
||||
async fn tsdk_path(fs: &dyn Fs, adapter: &Arc<dyn LspAdapterDelegate>) -> Option<&'static str> {
|
||||
async fn tsdk_path(&self, adapter: &Arc<dyn LspAdapterDelegate>) -> Option<&'static str> {
|
||||
let is_yarn = adapter
|
||||
.read_text_file(PathBuf::from(".yarn/sdks/typescript/lib/typescript.js"))
|
||||
.await
|
||||
@@ -46,7 +47,8 @@ impl VtslsLspAdapter {
|
||||
Self::TYPESCRIPT_TSDK_PATH
|
||||
};
|
||||
|
||||
if fs
|
||||
if self
|
||||
.fs
|
||||
.is_dir(&adapter.worktree_root_path().join(tsdk_path))
|
||||
.await
|
||||
{
|
||||
@@ -210,12 +212,11 @@ impl LspAdapter for VtslsLspAdapter {
|
||||
|
||||
async fn workspace_configuration(
|
||||
self: Arc<Self>,
|
||||
fs: &dyn Fs,
|
||||
delegate: &Arc<dyn LspAdapterDelegate>,
|
||||
_: Option<Toolchain>,
|
||||
cx: &mut AsyncApp,
|
||||
) -> Result<Value> {
|
||||
let tsdk_path = Self::tsdk_path(fs, delegate).await;
|
||||
let tsdk_path = self.tsdk_path(delegate).await;
|
||||
let config = serde_json::json!({
|
||||
"tsdk": tsdk_path,
|
||||
"suggest": {
|
||||
|
||||
@@ -5,7 +5,7 @@ use gpui::AsyncApp;
|
||||
use language::{LspAdapter, LspAdapterDelegate, Toolchain, language_settings::AllLanguageSettings};
|
||||
use lsp::{LanguageServerBinary, LanguageServerName};
|
||||
use node_runtime::{NodeRuntime, VersionStrategy};
|
||||
use project::{Fs, lsp_store::language_server_settings};
|
||||
use project::lsp_store::language_server_settings;
|
||||
use serde_json::Value;
|
||||
use settings::{Settings, SettingsLocation};
|
||||
use smol::fs;
|
||||
@@ -132,7 +132,7 @@ impl LspAdapter for YamlLspAdapter {
|
||||
|
||||
async fn workspace_configuration(
|
||||
self: Arc<Self>,
|
||||
_: &dyn Fs,
|
||||
|
||||
delegate: &Arc<dyn LspAdapterDelegate>,
|
||||
_: Option<Toolchain>,
|
||||
cx: &mut AsyncApp,
|
||||
|
||||
Reference in New Issue
Block a user