Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Add Label Details (Display Source) on Autocomplete #97

Open
0xJWLabs opened this issue Oct 11, 2024 · 2 comments
Open

Comments

@0xJWLabs
Copy link
Contributor

I would like to request a feature enhancement for the autocomplete suggestions when working with modules let’s say in TypeScript. Specifically, when typing a symbol (e.g., a.ab), it would be useful to see the source module or origin of the symbol alongside the kind and label.

For example, when importing a module like:

import a from "abc_module";

As we type a.ab, the autocomplete should display the following format:

[kind] [label] [label_detail]

Where:

•	Kind refers to the symbol type (e.g., function, variable, class).
•	Label refers to the symbol name (e.g., ab).
•	Label Detail refers to the source or module name (e.g., abc_module).

So, for the example above, the autocomplete would display:

[function] [ab] [abc_module]

Motivation

This feature would greatly improve the developer experience by providing additional context in the autocomplete dropdown. It would help users quickly identify where a symbol is coming from, especially when working with multiple modules or libraries.

Use Case

•	Improves Productivity: Developers can identify the source of a symbol more easily without needing to navigate or hover over the code.
•	Reduces Confusion: When multiple modules or libraries export similarly named symbols, showing the module source can clarify which one is being suggested.

Expected Behavior

The autocomplete suggestions should have an additional field for label_detail, which shows the originating module or source of the symbol.

Example Autocomplete Suggestion Format

For a.ab, imported from abc_module:

[function] [ab] [abc_module]

Example from other plugin

nvim-cmp:
image

@AbaoFromCUG
Copy link

Not what you want, but it should be helpful!

TIP: render what your want from ctx

    ---@param ctx blink.cmp.CompletionRenderContext
    ---@return blink.cmp.Component
    local function render_item(ctx)
        local map = {
            ["blink.cmp.sources.lsp"] = "[LSP]",
            ["blink.cmp.sources.path"] = "[PATH]",
            ["blink.cmp.sources.snippets"] = "[SNIP]",
        }
        return {
            {
                " " .. ctx.item.label,
                fill = true,
                -- hl_group = ctx.deprecated and "BlinkCmpLabelDeprecated" or "BlinkCmpLabel",
            },
            { string.format(" %s%s%-10s", ctx.kind_icon, ctx.icon_gap, ctx.kind), hl_group = "BlinkCmpKind" .. ctx.kind },
            {
                string.format("%6s ", map[ctx.item.source] or "UNKNOWN"),
                hl_group = "BlinkCmpSource",
            },
        }
    end
    require("blink-cmp").setup({
        windows = {
            autocomplete = {
                draw = render_item,
            },
        },
    })

image

@0xJWLabs
Copy link
Contributor Author

I know about this, thanks btw, but I’m talking about source like where it comes from, like module a or module b etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants