Skip to content

Completer Rework #336

Open
Open
@jdugan6240

Description

@jdugan6240

Currently, Hilbish doesn't have a way to distinguish between the completion item shown when showing completions, and the actual value inserted into the prompt when the completion is accepted. This matters for a couple of reasons:

  • We cannot colorize/style the completions themselves, since this affects what gets inserted into the prompt if the completion is accepted. My carapace completer gets around this by colorizing the description instead, but this is not the correct way to do it.
  • Some completion sources such as carapace want the shell to support displaying text that's different than what's actually inserted in the prompt. For example, here's the output of carapace git export git a | jq on my system. As you can see, each entry has a separate "value" and "display" value, where "value" is what's actually inserted in the prompt, and "display" is what's displayed when completions are shown. In this case they are the same, but there are cases where they are not.
{
  "version": "v1.5.0",
  "messages": [],
  "nospace": "",
  "usage": "",
  "values": [
    {
      "value": "add",
      "display": "add",
      "description": "Add file contents to the index",
      "style": "blue",
      "tag": "main commands"
    },
    {
      "value": "am",
      "display": "am",
      "description": "Apply a series of patches from a mailbox",
      "style": "blue",
      "tag": "main commands"
    },
    {
      "value": "annotate",
      "display": "annotate",
      "description": "Show what revision and author last modified each line of a file",
      "style": "magenta",
      "tag": "interrogator commands"
    },
    {
      "value": "apply",
      "display": "apply",
      "description": "Apply a patch to files and/or to the index",
      "style": "dim yellow",
      "tag": "low-level manipulator commands"
    },
    {
      "value": "archimport",
      "display": "archimport",
      "description": "Import a GNU Arch repository into Git",
      "style": "cyan",
      "tag": "interaction commands"
    },
    {
      "value": "archive",
      "display": "archive",
      "description": "Create an archive of files from a named tree",
      "style": "blue",
      "tag": "main commands"
    }
  ]
}

The way I envision this working is as follows (yes, this is a breaking change):

Completions that are just a list of items are unaffected by this change. They could remain as is:

local cg = {
	items = {'just', 'a bunch', 'of items', 'here', 'hehe'},
	type = 'grid'
}

Completions where each item is a table, however, would need to be reworked. Something along these lines:

local cg = {
	items = {
		["item"] = {
			"description": "This is a completion value", -- Remove this if you don't want a description
			"display": "item", -- This is what's displayed in the completion menu. This can be colorized.
			"alias": "i" -- If you want to support aliases
		}
	}
}

Every item in said table can be explicitly optional. If "description" is omitted, then the completion has no description. If "display" is omitted, then the completion value is what's displayed in the completion menu (the current behavior). If "alias" is omitted, then the completion has no alias. You could make either "description" or "display" mandatory, however, since using a table wouldn't make sense if "description", "display", and "alias" are all omitted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions