Skip to content

Commit

Permalink
aaa
Browse files Browse the repository at this point in the history
  • Loading branch information
bestgopher committed Aug 29, 2024
1 parent fc272e6 commit c5075e6
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions wakatime-ls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
arc-swap = "1.7.1"
chrono = "0.4.38"
clap = "4.5.16"
tokio = { version = "1.39.3", features = ["full"] }
Expand Down
35 changes: 32 additions & 3 deletions wakatime-ls/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::Arc;

use arc_swap::ArcSwap;
use chrono::{DateTime, Local, TimeDelta};
use clap::{Arg, Command};
use tokio::{process::Command as TokioCommand, sync::Mutex};
Expand All @@ -25,6 +26,7 @@ struct WakatimeLanguageServer {
wakatime_path: String,
api_key: Option<String>,
current_file: Mutex<CurrentFile>,
platform: ArcSwap<String>,
}

impl WakatimeLanguageServer {
Expand All @@ -46,7 +48,8 @@ impl WakatimeLanguageServer {
let mut command = TokioCommand::new(self.wakatime_path.as_str());

command
.arg("--verbose")
.arg("--plugin")
.arg(self.platform.load().as_str())
.arg("--time")
.arg((now.timestamp() as f64).to_string())
.arg("--write")
Expand All @@ -60,6 +63,16 @@ impl WakatimeLanguageServer {

if let Some(ref language) = event.language {
command.arg("--language").arg(language);
} else {
command.arg("--guess-language");
}

if let Some(lineno) = event.lineno {
command.arg("--lineno").arg(lineno.to_string());
}

if let Some(cursorpos) = event.cursorpos {
command.arg("--cursorpos").arg(cursorpos.to_string());
}

self.client
Expand Down Expand Up @@ -92,7 +105,22 @@ impl WakatimeLanguageServer {

#[tower_lsp::async_trait]
impl LanguageServer for WakatimeLanguageServer {
async fn initialize(&self, _params: InitializeParams) -> Result<InitializeResult> {
async fn initialize(&self, params: InitializeParams) -> Result<InitializeResult> {
if let Some(ref client_info) = params.client_info {
let mut platform = String::new();
platform.push_str(client_info.name.as_str());

if let Some(ref version) = client_info.version {
platform.push_str("/");
platform.push_str(version.as_str());
}

platform.push(' ');
platform.push_str(self.platform.load().as_str());

self.platform.store(Arc::new(platform));
}

Ok(InitializeResult {
server_info: Some(ServerInfo {
name: env!("CARGO_PKG_NAME").to_string(),
Expand All @@ -110,7 +138,7 @@ impl LanguageServer for WakatimeLanguageServer {

async fn initialized(&self, _params: InitializedParams) {
self.client
.log_message(MessageType::ERROR, "Wakatime language server initialized")
.log_message(MessageType::INFO, "Wakatime language server initialized")
.await;
}

Expand Down Expand Up @@ -187,6 +215,7 @@ async fn main() {
client,
wakatime_path: wakatime_cli.to_string(),
api_key,
platform: ArcSwap::from_pointee(format!("wakatime-ls/{}", env!("CARGO_PKG_VERSION"))),
current_file: Mutex::new(CurrentFile {
uri: String::new(),
timestamp: Local::now(),
Expand Down
14 changes: 7 additions & 7 deletions wakatime/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::{
env, fs,
path::{Path, PathBuf},
};
use std::fs;

use zed_extension_api::{
self as zed, settings::LspSettings, Command, LanguageServerId, Result, Worktree,
Expand Down Expand Up @@ -148,6 +145,8 @@ impl WakatimeExtension {
let binary_path =
self.download(language_server_id, "wakatime-cli", "wakatime/wakatime-cli")?;

zed::make_file_executable(&binary_path)?;

self.cached_wakatime_cli_binary_path = Some(binary_path.clone());

Ok(binary_path)
Expand Down Expand Up @@ -177,13 +176,14 @@ impl zed::Extension for WakatimeExtension {
let mut args = vec!["--wakatime-cli".to_string(), {
use std::env;
let current = env::current_dir().unwrap();
current
let waka_cli = current
.join(wakatime_cli_binary_path)
.to_str()
.unwrap()
.to_string()
}];
.to_string();

waka_cli
}];
if let Some(ref value) = setting.settings {
if let Some(y) = value.get("api-key") {
if let Some(x) = y.as_str() {
Expand Down

0 comments on commit c5075e6

Please sign in to comment.