mirror of
https://github.com/xHyroM/zed-discord-presence.git
synced 2024-11-27 16:21:08 +01:00
Compare commits
No commits in common. "ba4caf2dc0a26c38f5f1312679ef63d1e4854182" and "3c74a0fe4f6e8243fc78b2a74d98246cd6c218be" have entirely different histories.
ba4caf2dc0
...
3c74a0fe4f
5 changed files with 6 additions and 83 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -124,7 +124,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "discord-presence-lsp"
|
||||
version = "0.5.0"
|
||||
version = "0.4.2"
|
||||
dependencies = [
|
||||
"discord-rich-presence",
|
||||
"git2",
|
||||
|
|
11
README.md
11
README.md
|
@ -34,15 +34,6 @@ You can configure state, details and git integration by changing Discord Presenc
|
|||
// URL for small image
|
||||
"small_image": "{base_icons_url}/zed.png",
|
||||
"small_text": "Zed",
|
||||
|
||||
// Rules - disable presence in some workspaces
|
||||
"rules": {
|
||||
"mode": "blacklist" // or whitelist
|
||||
"paths": [
|
||||
"absolute path"
|
||||
]
|
||||
},
|
||||
|
||||
"git_integration": true
|
||||
}
|
||||
}
|
||||
|
@ -50,4 +41,4 @@ You can configure state, details and git integration by changing Discord Presenc
|
|||
}
|
||||
```
|
||||
|
||||
You can also use `null` to unset the option. Possible for everything except `base_icons_url`, `rules` and `git_integration`
|
||||
You can also use `null` to unset the option. Possible for everything except `base_icons_url` and `git_integration`
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "discord-presence-lsp"
|
||||
version = "0.5.0"
|
||||
version = "0.4.2"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
|
|
@ -19,39 +19,6 @@
|
|||
|
||||
use serde_json::Value;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum RulesMode {
|
||||
Whitelist,
|
||||
Blacklist,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Rules {
|
||||
pub mode: RulesMode,
|
||||
pub paths: Vec<String>,
|
||||
}
|
||||
|
||||
impl Default for Rules {
|
||||
fn default() -> Self {
|
||||
Rules {
|
||||
mode: RulesMode::Blacklist,
|
||||
paths: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Rules {
|
||||
pub fn suitable(&self, path: &str) -> bool {
|
||||
let contains = self.paths.contains(&path.to_string());
|
||||
|
||||
if self.mode == RulesMode::Blacklist {
|
||||
!contains
|
||||
} else {
|
||||
contains
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Configuration {
|
||||
pub base_icons_url: String,
|
||||
|
@ -64,8 +31,6 @@ pub struct Configuration {
|
|||
pub small_image: Option<String>,
|
||||
pub small_text: Option<String>,
|
||||
|
||||
pub rules: Rules,
|
||||
|
||||
pub git_integration: bool,
|
||||
}
|
||||
|
||||
|
@ -101,7 +66,6 @@ impl Configuration {
|
|||
large_text: Some(String::from("{language:u}")),
|
||||
small_image: Some(String::from("{base_icons_url}/zed.png")),
|
||||
small_text: Some(String::from("Zed")),
|
||||
rules: Rules::default(),
|
||||
git_integration: true,
|
||||
}
|
||||
}
|
||||
|
@ -116,28 +80,6 @@ impl Configuration {
|
|||
set_option!(self, options, small_image, "small_image");
|
||||
set_option!(self, options, small_text, "small_text");
|
||||
|
||||
if let Some(rules) = options.get("rules") {
|
||||
self.rules.mode = rules.get("mode").and_then(|m| m.as_str()).map_or(
|
||||
RulesMode::Blacklist,
|
||||
|mode| match mode {
|
||||
"whitelist" => RulesMode::Whitelist,
|
||||
"blacklist" => RulesMode::Blacklist,
|
||||
_ => RulesMode::Blacklist,
|
||||
},
|
||||
);
|
||||
|
||||
self.rules.paths =
|
||||
rules
|
||||
.get("paths")
|
||||
.and_then(|p| p.as_array())
|
||||
.map_or(Vec::new(), |paths| {
|
||||
paths
|
||||
.iter()
|
||||
.filter_map(|p| p.as_str().map(|s| s.to_string()))
|
||||
.collect()
|
||||
});
|
||||
}
|
||||
|
||||
if let Some(git_integration) = options.get("git_integration") {
|
||||
self.git_integration = git_integration.as_bool().unwrap_or(true);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ use std::ffi::OsStr;
|
|||
use std::fmt::Debug;
|
||||
use std::ops::Deref;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::exit;
|
||||
use std::sync::{Mutex, MutexGuard};
|
||||
|
||||
use configuration::Configuration;
|
||||
|
@ -156,6 +155,9 @@ impl Backend {
|
|||
#[tower_lsp::async_trait]
|
||||
impl LanguageServer for Backend {
|
||||
async fn initialize(&self, params: InitializeParams) -> Result<InitializeResult> {
|
||||
// Connect discord client
|
||||
self.discord.connect();
|
||||
|
||||
// Set workspace name
|
||||
let root_uri = params.root_uri.expect("Failed to get root uri");
|
||||
let workspace_path = Path::new(root_uri.path());
|
||||
|
@ -176,18 +178,6 @@ impl LanguageServer for Backend {
|
|||
let mut config = self.config.lock().unwrap();
|
||||
config.set(params.initialization_options);
|
||||
|
||||
if config.rules.suitable(
|
||||
workspace_path
|
||||
.to_str()
|
||||
.expect("Failed to transform workspace path to str"),
|
||||
) {
|
||||
// Connect discord client
|
||||
self.discord.connect();
|
||||
} else {
|
||||
// Exit LSP
|
||||
exit(0);
|
||||
}
|
||||
|
||||
Ok(InitializeResult {
|
||||
server_info: Some(ServerInfo {
|
||||
name: env!("CARGO_PKG_NAME").into(),
|
||||
|
|
Loading…
Reference in a new issue