Skip to content

feat: Language Server listens on account changes and updates token

Tomas Vik requested to merge tv/2023-11/listen-on-account-change into main

Description

This MR has 4 commits. They should be reviewed separately.

This MR first prepares the account service to emit events upon any change to any account, then it changes the platform manager to emit the account changes, and lastly, it uses this new logic in our Language Server initialization.

Related Issues

Resolves #1054 (closed) Resolves #1060 (closed)

How has this been tested?

Set these settings in you settings.json

{
  "gitlab.aiAssistedCodeSuggestions.enabled": true,
  "gitlab.featureFlags.languageServer":true
}

Desktop extension

  • The LS still provides suggestions normally.
  • Removing account - if we remove all accounts, the LS still uses the last available account
  • Adding an account
    1. Remove all accounts
    2. Restart the extension (because otherwise, LS remembers the last account (see previous bullet point)
    3. Validate that suggestions don't work
    4. Add gitlab.com account
    5. Validate that suggestions now work
  • Token refresh
    1. In the extension code, increase the refresh interval according to this comment https://gitlab.com/gitlab-org/gitlab-vscode-extension/blob/307a75b17effb4ed502f7a22085dcfbbbe13f764/src/desktop/gitlab/token_exchange_service.ts#L23
    2. Now, when you start the extension, the token refreshes every 30s
    3. Wait for 35s and type something in a supported file (e.g. JS or TS). See suggestion (before this feature, LS would keep the rejected token, and it would stop working)

WebIDE

  • Follow the guide to set up the Workflow with WebIDE
  • In the submodule, check out this MR branch and then run yarn start:example from the WebIDE root
  • See that the WebIDE and Workflow work well.
  • The WebIDE logic didn't change almost at all, so I'm only verifying that nothing broke by getting one suggestion.

Screenshots (if appropriate):

Desktop

image

WebIDE

image

Known issue

When you open your VS Code after your OAuth token expired, the extension first initializes the LS with the expired token and then right after sends the valid refreshed token.

This now results in an error message, but once we implement state management, it will be just few millisecond lasting change in the status bar icon

image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation
  • Chore (Related to CI or Packaging to platforms)
  • Test gap
Edited by Tomas Vik

Merge request reports