diff --git a/README.md b/README.md index 83306f7e..3b802a92 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ require('cord').setup({ editing = 'Editing {}', -- Text to display when editing a file file_browser = 'Browsing files in {}', -- Text to display when browsing files (Empty string to disable) plugin_manager = 'Managing plugins in {}', -- Text to display when managing plugins (Empty string to disable) + lsp_manager = 'Configuring LSP servers in {}', -- Text to display when managing LSP servers (Empty string to disable) workspace = 'In {}', -- Text to display when in a workspace (Empty string to disable) }, buttons = { @@ -105,12 +106,12 @@ require('cord').setup({ -- url = 'https://github.com/vyfor/cord.nvim', -- } }, - assets = { + assets = { -- Custom file icons -- lazy = { -- Vim filetype or file name or file extension = table or string (see wiki)* -- name = 'Lazy', -- Optional override for the icon name, redundant for language types -- icon = 'https://example.com/lazy.png', -- Rich Presence asset name or URL -- tooltip = 'lazy.nvim', - -- type = 2, -- 0 = language, 1 = file browser, 2 = plugin manager; defaults to language + -- type = 2, -- 0 = language, 1 = file browser, 2 = plugin manager, 3 = lsp manager; defaults to language -- }, -- ['Cargo.toml'] = 'crates', }, diff --git a/assets/lsp/default.png b/assets/lsp/default.png new file mode 100644 index 00000000..c3efc4d5 Binary files /dev/null and b/assets/lsp/default.png differ diff --git a/lua/cord.lua b/lua/cord.lua index 686d014b..b3890d7b 100644 --- a/lua/cord.lua +++ b/lua/cord.lua @@ -40,6 +40,7 @@ cord.config = { editing = 'Editing {}', file_browser = 'Browsing files in {}', plugin_manager = 'Managing plugins in {}', + lsp_manager = 'Configuring LSP servers in {}', workspace = 'In {}', }, buttons = { @@ -73,6 +74,7 @@ local function connect(config) config.text.editing, config.text.file_browser, config.text.plugin_manager, + config.text.lsp_manager, config.text.workspace, vim.fn.getcwd(), config.display.show_repository and ffi.new( diff --git a/lua/cord/utils.lua b/lua/cord/utils.lua index c5367805..956493da 100644 --- a/lua/cord/utils.lua +++ b/lua/cord/utils.lua @@ -48,6 +48,7 @@ local function init_discord(ffi) const char* editing_text, const char* file_browser_text, const char* plugin_manager_text, + const char* lsp_manager_text, const char* workspace_text, const char* initial_path, const Buttons* buttons, diff --git a/src/lib.rs b/src/lib.rs index ab41406b..c7ce2627 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,6 +36,7 @@ struct Config { editing_text: String, file_browser_text: String, plugin_manager_text: String, + lsp_manager_text: String, workspace_text: String, workspace: String, buttons: Vec, @@ -61,6 +62,7 @@ pub extern "C" fn init( editing_text: *const c_char, file_browser_text: *const c_char, plugin_manager_text: *const c_char, + lsp_manager_text: *const c_char, workspace_text: *const c_char, initial_path: *const c_char, buttons_ptr: *const Buttons, @@ -105,6 +107,7 @@ pub extern "C" fn init( let editing_text = ptr_to_string(editing_text); let file_browser_text = ptr_to_string(file_browser_text); let plugin_manager_text = ptr_to_string(plugin_manager_text); + let lsp_manager_text = ptr_to_string(lsp_manager_text); let workspace_text = ptr_to_string(workspace_text); let workspace = find_workspace(&ptr_to_string(initial_path)); @@ -138,6 +141,7 @@ pub extern "C" fn init( editing_text: editing_text, file_browser_text: file_browser_text, plugin_manager_text: plugin_manager_text, + lsp_manager_text: lsp_manager_text, workspace_text: workspace_text, workspace: workspace .file_name() @@ -351,6 +355,35 @@ pub extern "C" fn update_presence_with_assets( (details, icon, tooltip) } + Some(AssetType::LSP) => { + let details = + config.lsp_manager_text.replace("{}", &name); + + if icon.is_empty() || tooltip.is_empty() { + if let Some((default_icon, default_tooltip)) = + mappings::lsp_manager::get(&filetype) + { + if icon.is_empty() { + icon = format!( + "{}/lsp/{}.png?v=5", + GITHUB_ASSETS_URL, default_icon + ) + } + if tooltip.is_empty() { + tooltip = default_tooltip.to_string() + } + } else { + if icon.is_empty() { + return false; + } + if tooltip.is_empty() { + tooltip = name; + } + } + } + + (details, icon, tooltip) + } None => return false, }; diff --git a/src/mappings/lsp_manager.rs b/src/mappings/lsp_manager.rs new file mode 100644 index 00000000..4de2a7ea --- /dev/null +++ b/src/mappings/lsp_manager.rs @@ -0,0 +1,9 @@ +pub fn get<'a>(filetype: &'a str) -> Option<(&'a str, &'a str)> { + let lsp_manager = match filetype { + "lspinfo" => ("default", "LSP Config"), + "mason" => ("default", "Mason"), + _ => return None, + }; + + Some(lsp_manager) +} diff --git a/src/mappings/mod.rs b/src/mappings/mod.rs index dedc7179..8b5ece19 100644 --- a/src/mappings/mod.rs +++ b/src/mappings/mod.rs @@ -1,5 +1,6 @@ pub mod file_browser; pub mod language; +pub mod lsp_manager; pub mod plugin_manager; pub fn get_by_filetype<'a>(filetype: &'a str, filename: &str) -> Filetype<'a> { @@ -12,6 +13,9 @@ pub fn get_by_filetype<'a>(filetype: &'a str, filename: &str) -> Filetype<'a> { if let Some(plugin_manager) = plugin_manager::get(filetype) { return Filetype::PluginManager(plugin_manager.0, plugin_manager.1); } + if let Some(lsp_manager) = lsp_manager::get(filetype) { + return Filetype::LSP(lsp_manager.0, lsp_manager.1); + } Filetype::Language("text", filetype) } @@ -19,4 +23,5 @@ pub enum Filetype<'a> { Language(&'a str, &'a str), FileBrowser(&'a str, &'a str), PluginManager(&'a str, &'a str), + LSP(&'a str, &'a str), } diff --git a/src/types.rs b/src/types.rs index 05fc81f1..9cde11ab 100644 --- a/src/types.rs +++ b/src/types.rs @@ -2,6 +2,7 @@ pub enum AssetType { Language, FileBrowser, PluginManager, + LSP, } impl AssetType { @@ -11,6 +12,7 @@ impl AssetType { 0 => Some(AssetType::Language), 1 => Some(AssetType::FileBrowser), 2 => Some(AssetType::PluginManager), + 3 => Some(AssetType::LSP), _ => None, } } diff --git a/src/utils.rs b/src/utils.rs index c5beb143..179c9357 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -174,6 +174,11 @@ pub fn build_presence( plugin_manager_presence(config, tooltip, icon); (details, Some(icon), tooltip) } + Filetype::LSP(icon, tooltip) => { + let (details, icon, tooltip) = + lsp_manager_presence(config, tooltip, icon); + (details, Some(icon), tooltip) + } } } @@ -256,6 +261,20 @@ fn plugin_manager_presence( (presence_details, presence_large_image, presence_large_text) } +#[inline(always)] +fn lsp_manager_presence( + config: &Config, + tooltip: &str, + icon: &str, +) -> (String, String, String) { + let presence_details = config.lsp_manager_text.replace("{}", tooltip); + let presence_large_image = + format!("{}/lsp_manager/{}.png?v=5", GITHUB_ASSETS_URL, icon); + let presence_large_text = tooltip.to_string(); + + (presence_details, presence_large_image, presence_large_text) +} + #[inline(always)] fn find_repository(workspace_path: &str) -> Option { let config_path = format!("{}/{}", workspace_path, ".git/config");