Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use zed_extension_api::{Worktree, serde_json::Value};

use crate::util::expand_home_path;

pub fn get_java_home(configuration: &Option<Value>, worktree: &Worktree) -> Option<String> {
// try to read the value from settings
if let Some(configuration) = configuration
&& let Some(java_home) = configuration.pointer("/java/home").and_then(|x| x.as_str()) {
match expand_home_path(worktree, java_home.to_string()) {
Ok(home_path) => return Some(home_path),
Err(err) => {
println!("{}", err);
}
};
}

// try to read the value from env
match worktree
.shell_env()
.into_iter()
.find(|(k, _)| k == "JAVA_HOME")
{
Some((_, value)) if !value.is_empty() => Some(value),
_ => None,
}
}

pub fn is_lombok_enabled(configuration: &Option<Value>) -> bool {
configuration
.as_ref()
.and_then(|configuration| {
configuration
.pointer("/java/jdt/ls/lombokSupport/enabled")
.and_then(|enabled| enabled.as_bool())
})
.unwrap_or(false)
}
16 changes: 8 additions & 8 deletions src/debugger.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, env, fs, path::PathBuf};
use std::{collections::HashMap, fs, path::PathBuf};

use serde::{Deserialize, Serialize};
use zed_extension_api::{
Expand All @@ -9,7 +9,10 @@ use zed_extension_api::{
set_language_server_installation_status,
};

use crate::lsp::LspWrapper;
use crate::{
lsp::LspWrapper,
util::{get_curr_dir, path_to_string},
};

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -53,8 +56,6 @@ const RUNTIME_SCOPE: &str = "$Runtime";

const SCOPES: [&str; 3] = [TEST_SCOPE, AUTO_SCOPE, RUNTIME_SCOPE];

const PATH_TO_STR_ERROR: &str = "Failed to convert path to string";

const JAVA_DEBUG_PLUGIN_FORK_URL: &str = "https://github.com/zed-industries/java-debug/releases/download/0.53.2/com.microsoft.java.debug.plugin-0.53.2.jar";

const MAVEN_METADATA_URL: &str = "https://repo1.maven.org/maven2/com/microsoft/java/com.microsoft.java.debug.plugin/maven-metadata.xml";
Expand Down Expand Up @@ -105,7 +106,7 @@ impl Debugger {

download_file(
JAVA_DEBUG_PLUGIN_FORK_URL,
jar_path.to_str().ok_or(PATH_TO_STR_ERROR)?,
&path_to_string(jar_path.clone())?,
DownloadedFileType::Uncompressed,
)
.map_err(|err| {
Expand Down Expand Up @@ -215,7 +216,7 @@ impl Debugger {

download_file(
url.as_str(),
jar_path.to_str().ok_or(PATH_TO_STR_ERROR)?,
&path_to_string(&jar_path)?,
DownloadedFileType::Uncompressed,
)
.map_err(|err| format!("Failed to download {url} {err}"))?;
Expand Down Expand Up @@ -345,8 +346,7 @@ impl Debugger {
&self,
initialization_options: Option<Value>,
) -> zed::Result<Value> {
let current_dir =
env::current_dir().map_err(|err| format!("could not get current dir: {err}"))?;
let current_dir = get_curr_dir()?;

let canonical_path = Value::String(
current_dir
Expand Down
Loading