Compare commits

...

1 Commits

Author SHA1 Message Date
Conrad Irwin
d797750f74 Disable binary downloads
Co-Authored-By: Mikayla <mikayla@zed.dev>
Co-Authored-By: Marshall <marshall@zed.dev>
2024-07-09 16:39:35 -06:00
7 changed files with 58 additions and 9 deletions

1
Cargo.lock generated
View File

@@ -6797,6 +6797,7 @@ dependencies = [
"async_zip",
"futures 0.3.28",
"http 0.1.0",
"language",
"log",
"paths",
"semver",

View File

@@ -83,6 +83,9 @@
"confirm_quit": false,
// Whether to restore last closed project when fresh Zed instance is opened.
"restore_on_startup": "last_workspace",
// Whether zed should automatically download binaries to run
// language servers if they are missing.
"download_missing_binaries": true,
// Size of the drop target in the editor.
"drop_target_size": 0.2,
// Whether the window should be closed when using 'close active item' on a window with no tabs.
@@ -128,14 +131,7 @@
// The default number of lines to expand excerpts in the multibuffer by.
"expand_excerpt_lines": 3,
// Globs to match against file paths to determine if a file is private.
"private_files": [
"**/.env*",
"**/*.pem",
"**/*.key",
"**/*.cert",
"**/*.crt",
"**/secrets.yml"
],
"private_files": ["**/.env*", "**/*.pem", "**/*.key", "**/*.cert", "**/*.crt", "**/secrets.yml"],
// Whether to use additional LSP queries to format (and amend) the code after
// every "trigger" symbol input, defined by LSP server capabilities.
"use_on_type_format": true,

View File

@@ -18,6 +18,7 @@ use language::LanguageRegistry;
use node_runtime::NodeRuntime;
use release_channel::ReleaseChannel;
use semantic_version::SemanticVersion;
use std::sync::atomic::AtomicBool;
use std::{
path::{Path, PathBuf},
sync::{Arc, OnceLock},
@@ -39,6 +40,7 @@ pub(crate) struct WasmHost {
pub(crate) work_dir: PathBuf,
_main_thread_message_task: Task<()>,
main_thread_message_tx: mpsc::UnboundedSender<MainThreadCall>,
enable_binary_downloads: bool,
}
#[derive(Clone)]
@@ -91,7 +93,11 @@ impl WasmHost {
message(&mut cx).await;
}
});
Arc::new(Self {
let enable_binary_downloads =
AtomicBool::new(DownloadConfiguration::get_global(cx).enable_binary_downloads);
let this = Arc::new(Self {
engine: wasm_engine(),
fs,
work_dir,
@@ -101,7 +107,18 @@ impl WasmHost {
release_channel: ReleaseChannel::global(cx),
_main_thread_message_task: task,
main_thread_message_tx: tx,
enable_binary_downloads: enable_binary_downloads.clone(),
});
cx.observe_global::<SettingsStore>(move |cx| {
enable_binary_downloads.store(
DownloadConfiguration::get_global(cx).enable_binary_downloads,
Ordering::SeqCst,
)
})
.detach();
this
}
pub fn load_extension(

View File

@@ -198,6 +198,10 @@ impl nodejs::Host for WasmState {
package_name: String,
version: String,
) -> wasmtime::Result<Result<(), String>> {
if !self.host.enable_binary_downloads.get() {
return Err("binary downloads are disabled".into()).to_wasmtime_result();
}
self.host
.node_runtime
.npm_install_packages(&self.work_dir(), &[(&package_name, &version)])
@@ -372,6 +376,10 @@ impl ExtensionImports for WasmState {
file_type: DownloadedFileType,
) -> wasmtime::Result<Result<(), String>> {
maybe!(async {
if !self.host.enable_binary_downloads.get() {
return Err("binary downloads are disabled".into()).to_wasmtime_result();
}
let path = PathBuf::from(path);
let extension_work_dir = self.host.work_dir.join(self.manifest.id.as_ref());
@@ -435,6 +443,10 @@ impl ExtensionImports for WasmState {
}
async fn make_file_executable(&mut self, path: String) -> wasmtime::Result<Result<(), String>> {
if !self.host.enable_binary_downloads.get() {
return Err("binary downloads are disabled".into()).to_wasmtime_result();
}
#[allow(unused)]
let path = self
.host

View File

@@ -27,6 +27,27 @@ impl<'a> Into<SettingsLocation<'a>> for &'a dyn File {
/// Initializes the language settings.
pub fn init(cx: &mut AppContext) {
AllLanguageSettings::register(cx);
DownloadConfiguration::register(cx);
}
#[derive(Default, Serialize, Deserialize, Clone)]
pub struct DownloadConfiguration {
enable_binary_downloads: bool,
}
#[derive(Deserialize)]
struct DownloadConfigurationContent {
enable_binary_downloads: Option<bool>,
}
impl settings::Settings for DownloadConfiguration {
const KEY: Option<&'static str> = None;
type FileContent = DownloadConfigurationContent;
fn load(sources: SettingsSources<Self::FileContent>, _: &mut AppContext) -> Result<Self> {
sources.json_merge()
}
}
/// Returns the settings for the specified language from the provided file.

View File

@@ -24,6 +24,7 @@ async_zip.workspace = true
futures.workspace = true
http.workspace = true
log.workspace = true
language.workspace = true
paths.workspace = true
semver.workspace = true
serde.workspace = true

View File

@@ -14,6 +14,7 @@ pub struct WorkspaceSettings {
pub restore_on_startup: RestoreOnStartupBehaviour,
pub drop_target_size: f32,
pub when_closing_with_no_tabs: CloseWindowWhenNoItems,
pub download_missing_binaries: bool,
}
#[derive(Copy, Clone, Default, Serialize, Deserialize, JsonSchema)]