Skip to content

Commit 8106d78

Browse files
committed
Merge branch 'fix-project-detection-from-worktree'
2 parents 1e2b228 + 221f950 commit 8106d78

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

src/lib.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ fn executable_name(binary: &str) -> String {
5151
}
5252
}
5353

54+
fn project_name_from_path(path: &str) -> Option<String> {
55+
Path::new(path)
56+
.file_name()
57+
.and_then(|file_name| file_name.to_str())
58+
.map(ToString::to_string)
59+
}
60+
5461
impl WakatimeExtension {
5562
fn target_triple(&self, binary: &str) -> Result<String, String> {
5663
let (platform, arch) = zed::current_platform();
@@ -213,7 +220,7 @@ impl zed::Extension for WakatimeExtension {
213220

214221
let ls_binary_path = self.language_server_binary_path(language_server_id)?;
215222

216-
let args = vec!["--wakatime-cli".to_string(), {
223+
let mut args = vec!["--wakatime-cli".to_string(), {
217224
use std::env;
218225
let current = env::current_dir().unwrap();
219226
let waka_cli = if is_absolute_path_wasm(&wakatime_cli_binary_path) {
@@ -228,6 +235,19 @@ impl zed::Extension for WakatimeExtension {
228235
sanitize_path(waka_cli.as_str())
229236
}];
230237

238+
let project_folder = sanitize_path(worktree.root_path().as_str());
239+
if !project_folder.is_empty() {
240+
args.push("--project-folder".to_string());
241+
args.push(project_folder.clone());
242+
243+
if let Some(project_name) = project_name_from_path(project_folder.as_str()) {
244+
if !project_name.is_empty() {
245+
args.push("--alternate-project".to_string());
246+
args.push(project_name);
247+
}
248+
}
249+
}
250+
231251
Ok(Command {
232252
args,
233253
command: ls_binary_path.to_str().unwrap().to_owned(),

wakatime-ls/src/main.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ struct WakatimeLanguageServer {
3333
client: Client,
3434
settings: ArcSwap<Settings>,
3535
wakatime_path: String,
36+
project_folder: String,
37+
alternate_project: String,
3638
current_file: Mutex<CurrentFile>,
3739
platform: ArcSwap<String>,
3840
}
@@ -82,6 +84,18 @@ impl WakatimeLanguageServer {
8284
.arg("--entity")
8385
.arg(event.uri.as_str());
8486

87+
if !self.project_folder.is_empty() {
88+
command
89+
.arg("--project-folder")
90+
.arg(self.project_folder.as_str());
91+
}
92+
93+
if !self.alternate_project.is_empty() {
94+
command
95+
.arg("--alternate-project")
96+
.arg(self.alternate_project.as_str());
97+
}
98+
8599
if !self.platform.load().is_empty() {
86100
command.arg("--plugin").arg(self.platform.load().as_str());
87101
}
@@ -265,6 +279,16 @@ async fn main() {
265279
.help("wakatime-cli path")
266280
.required(true),
267281
)
282+
.arg(
283+
Arg::new("project-folder")
284+
.long("project-folder")
285+
.help("project folder path"),
286+
)
287+
.arg(
288+
Arg::new("alternate-project")
289+
.long("alternate-project")
290+
.help("alternate project name"),
291+
)
268292
.get_matches();
269293

270294
let wakatime_cli = if let Some(s) = matches.get_one::<String>("wakatime-cli") {
@@ -273,6 +297,18 @@ async fn main() {
273297
"wakatime-cli".to_string()
274298
};
275299

300+
let project_folder = if let Some(s) = matches.get_one::<String>("project-folder") {
301+
s.to_string()
302+
} else {
303+
String::new()
304+
};
305+
306+
let alternate_project = if let Some(s) = matches.get_one::<String>("alternate-project") {
307+
s.to_string()
308+
} else {
309+
String::new()
310+
};
311+
276312
let stdin = tokio::io::stdin();
277313
let stdout = tokio::io::stdout();
278314

@@ -281,6 +317,8 @@ async fn main() {
281317
client,
282318
settings: ArcSwap::from_pointee(Settings::default()),
283319
wakatime_path: wakatime_cli,
320+
project_folder,
321+
alternate_project,
284322
platform: ArcSwap::from_pointee(String::new()),
285323
current_file: Mutex::new(CurrentFile {
286324
uri: String::new(),

0 commit comments

Comments
 (0)