mirror of
https://github.com/xHyroM/zed-discord-presence.git
synced 2024-11-23 14:31:05 +01:00
Compare commits
No commits in common. "c0df28876f0c3eace44ca5b16609f2ae8c732bbf" and "79b39ca2cadd393ffa5915055d44688dcdb5ecbb" have entirely different histories.
c0df28876f
...
79b39ca2ca
7 changed files with 14 additions and 49 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -125,7 +125,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "discord-presence-lsp"
|
name = "discord-presence-lsp"
|
||||||
version = "0.6.0"
|
version = "0.5.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"discord-rich-presence",
|
"discord-rich-presence",
|
||||||
"git2",
|
"git2",
|
||||||
|
|
|
@ -31,8 +31,6 @@ You can configure state, details and git integration by changing Discord Presenc
|
||||||
"lsp": {
|
"lsp": {
|
||||||
"discord_presence": {
|
"discord_presence": {
|
||||||
"initialization_options": {
|
"initialization_options": {
|
||||||
// application id for the rich presence (required, keep it if you don't know what you're doing)
|
|
||||||
"application_id": "1263505205522337886"
|
|
||||||
// Base url for all language icons
|
// Base url for all language icons
|
||||||
"base_icons_url": "https://raw.githubusercontent.com/xhyrom/zed-discord-presence/main/assets/icons/",
|
"base_icons_url": "https://raw.githubusercontent.com/xhyrom/zed-discord-presence/main/assets/icons/",
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "discord-presence-lsp"
|
name = "discord-presence-lsp"
|
||||||
version = "0.6.0"
|
version = "0.5.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -10,5 +10,5 @@ tower-lsp = "0.20.0"
|
||||||
git2 = { version = "0.19.0", default-features = false }
|
git2 = { version = "0.19.0", default-features = false }
|
||||||
serde_json = { version = "1.0.122", features = ["std"] }
|
serde_json = { version = "1.0.122", features = ["std"] }
|
||||||
lazy_static = "1.5.0"
|
lazy_static = "1.5.0"
|
||||||
regex = { version = "1.10.6", default-features = false, features = ["std", "perf", "unicode-case", "unicode-perl"] }
|
regex = { version = "1.10.6", default-features = false, features = ["std", "perf", "unicode-case"] }
|
||||||
urlencoding = "2.1.3"
|
urlencoding = "2.1.3"
|
||||||
|
|
|
@ -54,7 +54,6 @@ impl Rules {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Configuration {
|
pub struct Configuration {
|
||||||
pub application_id: String,
|
|
||||||
pub base_icons_url: String,
|
pub base_icons_url: String,
|
||||||
|
|
||||||
pub state: Option<String>,
|
pub state: Option<String>,
|
||||||
|
@ -93,7 +92,6 @@ macro_rules! set_string {
|
||||||
impl Configuration {
|
impl Configuration {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
application_id: String::from("1263505205522337886"),
|
|
||||||
base_icons_url: String::from(
|
base_icons_url: String::from(
|
||||||
"https://raw.githubusercontent.com/xhyrom/zed-discord-presence/main/assets/icons/",
|
"https://raw.githubusercontent.com/xhyrom/zed-discord-presence/main/assets/icons/",
|
||||||
),
|
),
|
||||||
|
@ -110,7 +108,6 @@ impl Configuration {
|
||||||
|
|
||||||
pub fn set(&mut self, initialization_options: Option<Value>) {
|
pub fn set(&mut self, initialization_options: Option<Value>) {
|
||||||
if let Some(options) = initialization_options {
|
if let Some(options) = initialization_options {
|
||||||
set_string!(self, options, application_id, "application_id");
|
|
||||||
set_string!(self, options, base_icons_url, "base_icons_url");
|
set_string!(self, options, base_icons_url, "base_icons_url");
|
||||||
set_option!(self, options, state, "state");
|
set_option!(self, options, state, "state");
|
||||||
set_option!(self, options, details, "details");
|
set_option!(self, options, details, "details");
|
||||||
|
|
|
@ -31,30 +31,25 @@ use crate::util;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Discord {
|
pub struct Discord {
|
||||||
client: Option<Mutex<DiscordIpcClient>>,
|
client: Mutex<DiscordIpcClient>,
|
||||||
start_timestamp: Duration,
|
start_timestamp: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Discord {
|
impl Discord {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
|
let discord_client = DiscordIpcClient::new("1263505205522337886")
|
||||||
|
.expect("Failed to initialize Discord Ipc Client");
|
||||||
let start_timestamp = SystemTime::now();
|
let start_timestamp = SystemTime::now();
|
||||||
let since_epoch = start_timestamp
|
let since_epoch = start_timestamp
|
||||||
.duration_since(UNIX_EPOCH)
|
.duration_since(UNIX_EPOCH)
|
||||||
.expect("Failed to get duration since UNIX_EPOCH");
|
.expect("Failed to get duration since UNIX_EPOCH");
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
client: None,
|
client: Mutex::new(discord_client),
|
||||||
start_timestamp: since_epoch,
|
start_timestamp: since_epoch,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_client(&mut self, application_id: String) {
|
|
||||||
let discord_client = DiscordIpcClient::new(application_id.as_str())
|
|
||||||
.expect("Failed to initialize Discord Ipc Client");
|
|
||||||
|
|
||||||
self.client = Some(Mutex::new(discord_client));
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn connect(&self) {
|
pub fn connect(&self) {
|
||||||
let mut client = self.get_client();
|
let mut client = self.get_client();
|
||||||
let result = client.connect();
|
let result = client.connect();
|
||||||
|
@ -67,12 +62,8 @@ impl Discord {
|
||||||
result.unwrap();
|
result.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_client(&self) -> MutexGuard<'_, DiscordIpcClient> {
|
pub fn get_client(&self) -> MutexGuard<DiscordIpcClient> {
|
||||||
self.client
|
return self.client.lock().expect("Failed to lock discord client");
|
||||||
.as_ref()
|
|
||||||
.expect("Discord client not initialized")
|
|
||||||
.lock()
|
|
||||||
.expect("Failed to lock discord client")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
|
|
@ -45,17 +45,3 @@ pub fn get_language(document: &Document) -> String {
|
||||||
|
|
||||||
String::from("text")
|
String::from("text")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use tower_lsp::lsp_types::Url;
|
|
||||||
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_unicode_perl() {
|
|
||||||
let document = Document::new(Url::parse("file:///home/user/file.php").unwrap());
|
|
||||||
let lang = get_language(&document);
|
|
||||||
assert_eq!(lang, "php");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -45,8 +45,8 @@ struct Document {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Backend {
|
struct Backend {
|
||||||
|
discord: discord::Discord,
|
||||||
client: Client,
|
client: Client,
|
||||||
discord: Mutex<Discord>,
|
|
||||||
workspace_file_name: Mutex<String>,
|
workspace_file_name: Mutex<String>,
|
||||||
git_remote_url: Mutex<Option<String>>,
|
git_remote_url: Mutex<Option<String>>,
|
||||||
config: Mutex<Configuration>,
|
config: Mutex<Configuration>,
|
||||||
|
@ -82,7 +82,7 @@ impl Backend {
|
||||||
fn new(client: Client) -> Self {
|
fn new(client: Client) -> Self {
|
||||||
Self {
|
Self {
|
||||||
client,
|
client,
|
||||||
discord: Mutex::new(Discord::new()),
|
discord: Discord::new(),
|
||||||
workspace_file_name: Mutex::new(String::new()),
|
workspace_file_name: Mutex::new(String::new()),
|
||||||
git_remote_url: Mutex::new(None),
|
git_remote_url: Mutex::new(None),
|
||||||
config: Mutex::new(Configuration::new()),
|
config: Mutex::new(Configuration::new()),
|
||||||
|
@ -120,7 +120,7 @@ impl Backend {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|text| placeholders.replace(text));
|
.map(|text| placeholders.replace(text));
|
||||||
|
|
||||||
self.get_discord().change_activity(
|
self.discord.change_activity(
|
||||||
state,
|
state,
|
||||||
details,
|
details,
|
||||||
large_image,
|
large_image,
|
||||||
|
@ -154,10 +154,6 @@ impl Backend {
|
||||||
fn get_config(&self) -> MutexGuard<Configuration> {
|
fn get_config(&self) -> MutexGuard<Configuration> {
|
||||||
return self.config.lock().expect("Failed to lock config");
|
return self.config.lock().expect("Failed to lock config");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_discord(&self) -> MutexGuard<Discord> {
|
|
||||||
return self.discord.lock().expect("Failed to lock discord");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tower_lsp::async_trait]
|
#[tower_lsp::async_trait]
|
||||||
|
@ -183,16 +179,13 @@ impl LanguageServer for Backend {
|
||||||
let mut config = self.config.lock().unwrap();
|
let mut config = self.config.lock().unwrap();
|
||||||
config.set(params.initialization_options);
|
config.set(params.initialization_options);
|
||||||
|
|
||||||
let mut discord = self.get_discord();
|
|
||||||
discord.create_client(config.application_id.to_string());
|
|
||||||
|
|
||||||
if config.rules.suitable(
|
if config.rules.suitable(
|
||||||
workspace_path
|
workspace_path
|
||||||
.to_str()
|
.to_str()
|
||||||
.expect("Failed to transform workspace path to str"),
|
.expect("Failed to transform workspace path to str"),
|
||||||
) {
|
) {
|
||||||
// Connect discord client
|
// Connect discord client
|
||||||
discord.connect();
|
self.discord.connect();
|
||||||
} else {
|
} else {
|
||||||
// Exit LSP
|
// Exit LSP
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -222,7 +215,7 @@ impl LanguageServer for Backend {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn shutdown(&self) -> Result<()> {
|
async fn shutdown(&self) -> Result<()> {
|
||||||
self.get_discord().kill();
|
self.discord.kill();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue