Skip to content

Enhance gitlab platform selector for code suggestions

What does this MR do?

In !984 (merged), we removed the project dependency on code suggestions by relying on the extension's "active GitLab account" to obtain the access credentials to execute API requests. This change introduced a bug when a user has multiple GitLab accounts registered in the workflow extension. The user is prompted to choose the "active account" every time that a code suggestion is requested.

This merge request fixes this bug by choosing a preferred account without a user's intervention. An account is preferred if it has code suggestions enabled. This merge request also introduces a new configuration field that allows the user to overwrite the preferred GitLab account to obtain code suggestions.

Technical details

The code suggestions feature depends on a GitLabPlatform object to send HTTP requests to the GitLab API. The GitLabPlatform object depends on an "active project" or an "active account" to obtain the API access credentials. This Merge Request creates a GitLabPlatformManagerForCodeSuggestions class that chooses a project or an account based in the following criteria:

flowchart TD
A[Code Suggestions] -->|Get Platform| B{has active project?}
B --> |yes| C[return platform for active project]
B --> |no| D{has accounts?}
D --> |no| E[return undefined]
D --> |yes| F{has a single account}
F --> |yes| G[return account]
F --> |no| H{user has preferred account?}
H --> |yes| I[return user preferred account]
H --> |no| J[choose account with code suggestions enabled]

How to reproduce locally

  • Register multiple GitLab accounts in the VSCode Workflow extension.
  • Open a file or type text in a file.

What is the behavior before this bug fix?

The extension will show a prompt multiple times asking you to choose an "active account"

What is the behavior after this fix?

Code suggestions work as expected and the extension doesn't prompt the user to choose an account.

Related to #999 (closed).

Edited by Enrique Alcántara

Merge request reports