1
0
Fork 0
mirror of https://github.com/jiriks74/presence.nvim synced 2025-06-22 20:38:57 +02:00

Use workspace text option when no project is detected

This commit is contained in:
Andrew Kwon 2021-03-08 18:56:53 -08:00
parent 0537801065
commit 9162582eb6
2 changed files with 17 additions and 5 deletions
lua/presence

View file

@ -350,18 +350,30 @@ function Presence:update_for_buffer(buffer)
},
}
-- Include project details if available
local workspace_text = self.options.workspace_text
local project_name = self:get_project_name(parent_dirpath)
-- Include project details if available
if project_name then
self.log:debug(string.format("Detected project: %s", project_name))
local workspace_text = self.options.workspace_text
activity.details = type(workspace_text) == "function"
and workspace_text(project_name, buffer)
or string.format(workspace_text, project_name)
else
self.log:debug("No project detected")
-- When no project is detected, set custom workspace text if:
-- * The custom function returns custom workspace text
-- * The configured workspace text does not contain a directive
if type(workspace_text) == "function" then
local custom_workspace_text = workspace_text(nil, buffer)
if custom_workspace_text then
activity.details = custom_workspace_text
end
elseif not workspace_text:find("%s") then
activity.details = workspace_text
end
end
self.discord:set_activity(activity, function(err)