[AI Context] Add consistency to context items to make them more data driven

Background

Duo Chat AIContextItems are grouped into categories. Each category has icon and name properties we use when rendering the categories list.

However the items themselves have a mix of different properties. They do not have an icon, and we map to an icon based on various criteria (gitType for git items, category for others). Currently all have a title, but we use various other properties for secondary text etc (e.g. filePath for files, repoName+commitId for git).

Problem to solve

Adding new categories and item types currently involves changes in several places:

  • language server (where the bulk of the logic happens for searching/providing the categories and items) (also where the contextItem object structure is defined and where we map values for each property)
  • clients (VSCode, Jetbrains) where there is a mapping form category (string) to category (object including icon property)
  • gitlab/ui (where we customise the display of different items)

It would be nice to unify some of the properties we use for rendering, to allow adding new item types without making changes in each place. This will keep the UI components thinner and data-driven, rather than having custom display logic written for various categories.

Proposed solution

  1. Move category object mapping into language server. This way, new categories can be added by registering the language server provider. The clients would simply pass through whatever they get from the LS to the Vue frontend.
  2. Add icons to context items. This will allow us to remove the switching logic for selecting icons and mean adding new item types does not require UI changes.
  3. Standardise our display properties. Add a dedicated secondaryTextLabel and subTypeLabel (placeholder names) properties, which have the correct values mapped when the LS constructs the items. For example, a File item might have it's relativePath value put into secondaryText, whereas a LocalGit item might have the repoName + commitId used. Then the UI can simply display secondaryText if it has it, and hide the section if not.
Edited by Elwyn Benson