Skip to content

feat: virtual text support #28

Description

@sand4rt

Will there be support for virtual text, like in nvim-dap-virtual-text for debugging, or in noice.nvim for search results?

Activity

  1. sand4rt commented on Mar 4, 2025

    @sand4rt
    Author
    require("nvim-dap-virtual-text").setup({
        -- This just tries to mitigate the chance that I leak tokens here. Probably won't stop it from happening...
        display_callback = function(variable)
            local name = string.lower(variable.name)
            local value = string.lower(variable.value)
            if name:match("Secret") or name:match("api") or value:match("secret") or value:match("api") then
                return "*****"
            end
    
            if #variable.value > 15 then
                return " " .. string.sub(variable.value, 1, 15) .. "... "
            end
            return " " .. variable.value
        end,
    })

    might be usefull (copied from https://www.youtube.com/watch?v=lyNfnI-B640)

  2. ph1losof commented on Mar 5, 2025

    @ph1losof

    Personally I think that the best way to handle this is to export a function from cloak.nvim which does variable masking. This would require a plugin refactor, however I think that it very important. The core principle of this plugin is to be minimal and flexible approach. Here is an example of implementation from my plugin which also does sensitive value masking:

    https://github.com/philosofonusus/ecolog.nvim/blob/ba6fe51a53a0c5f9cb3c5c33008ff77bb653a090/lua/ecolog/shelter/utils.lua#L87

    @sand4rt Regarding your question, here is a crude example with my plugin and how this implementation could look like:

    local ok, ecolog_utils = pcall(require, "ecolog.shelter.utils")
    if not ok then
        require("nvim-dap-virtual-text").setup({
            display_callback = function(variable)
                -- Your original masking logic here
            end,
        })
        return
    end
    
    require("nvim-dap-virtual-text").setup({
        display_callback = function(variable)
            local settings = {
                key = variable.name,
                source = "dap",
                patterns = {
                    [".*secret.*"] = "full",
                    [".*token.*"] = "full",
                    [".*password.*"] = "full",
                    [".*api.*"] = "partial",
                },
            }
    
            local masked = ecolog_utils.determine_masked_value(variable.value, settings)
    
            if #masked > 15 then
                return " " .. string.sub(masked, 1, 15) .. "... "
            end
            return " " .. masked
        end,
    })

    This would require installing ecolog.nvim as a dependency

    require("ecolog").setup({
        shelter = {
            patterns = {
                [".*secret.*"] = "full",
                [".*token.*"] = "full",
                [".*password.*"] = "full",
                [".*api.*"] = "partial",
            },
            sources = {
                ["dap"] = "none"  -- Default behavior for DAP variables
            },
            partial_mode = {
                show_start = 3,
                show_end = 3,
                min_mask = 3,
            },
            mask_char = "*",
        }
    })
  3. sand4rt commented on Mar 5, 2025

    @sand4rt
    Author

    @philosofonusus Thanks for your reply! I believe this was mentioned earlier, but just a friendly reminder to be mindful of promoting your plugin in the issue section of a similar plugin. It wouldn’t be ideal if others did the same in your issue section, right?

    Why not collaborate and merge some of the proposals into Clock instead of creating an new plugin?

  4. laytan commented on Mar 5, 2025

    @laytan
    Owner

    Sorry I don't 100% understand, you want cloak.nvim to cloak the virtual text created by other plugins?

  5. sand4rt commented on Mar 5, 2025

    @sand4rt
    Author

    Sorry I don't 100% understand, you want cloak.nvim to cloak the virtual text created by other plugins?

    I just want to avoid leaking my env variables, that's all ;) But yeah, the text is created by dap / noice. I think its reasanable since Cloak already has telescope itegration, right?

  6. laytan commented on Mar 5, 2025

    @laytan
    Owner

    Alright, thanks, just wanted to make sure I understood!

  7. ph1losof commented on Mar 5, 2025

    @ph1losof

    @philosofonusus Thanks for your reply! I believe this was mentioned earlier, but just a friendly reminder to be mindful of promoting your plugin in the issue section of a similar plugin. It wouldn’t be ideal if others did the same in your issue section, right?

    Why not collaborate and merge some of the proposals into Clock instead of creating an new plugin?

    You can feel free to share your feedback, be it an issue or enhancement. The main idea of OSS is to contribute and collaborate.

    My contribution is that I provide a feedback, help you receive an immediate solution for your question. While proposing exact place in my code, which helps in making a pull request. This is my contribution to cloak.nvim as an opensource project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions