andweeb / presence.nvim

Discord Rich Presence for Neovim
818 stars 65 forks source link

Message doesn't get sent if workspace_text is empty #136

Open dev-ardi opened 10 months ago

dev-ardi commented 10 months ago

Description

  workspace_text = function(name)
    if name == "" or name == nil then
      return ""
    end

That doesn't work

Neovim version

NVIM v0.9.4
Build type: Release
LuaJIT 2.1.1699392533

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

OS information

Linux arch 6.6.1-arch1-1 #1 SMP PREEMPT_DYNAMIC Wed, 08 Nov 2023 16:05:38 +0000 x86_64 GNU/Linux

Steps to reproduce

Use "" or the given function in something that doesn't have a filename (like telescope)

Logs

[presence.nvim] Failed to set activity in Discord: Received error event - child "activity" fails because [ child "details" fails because ["details" is not allowed to be empty]] (code 4000)

dev-ardi commented 10 months ago

Temporary workaround for me:

local function workspace(name)
    if name == "nvim" then
      return "Wasting time on my config"
    end

    if name == "rust" then
      return "Hacking away at the compiler!"
    end

    if name == "" or name == nil then
      local pwd = vim.fn.getcwd()
      local ws = pwd:match("^.+/(.+)/?$")
      if ws == "" then
        return "I hope you're having a great day :)" -- Friendly error message: This is not allowed to be empty!!
      end
      return workspace(ws)
    end
    return "Working on " .. name
end

then workspace_text = workspace,