GitLab Workflow extension for VS Code

The GitLab Workflow extension for Visual Studio Code integrates GitLab Duo and other GitLab features directly into your IDE. It adds a GitLab Workflow panel to the VS Code sidebar. You can view your issues, merge requests, and pipelines, and extend your view with custom queries.

Install and configure the extension.

Features

This extension brings the GitLab features you use every day directly into your VS Code environment:

The GitLab Workflow extension also streamlines your VS Code workflow with AI-assisted features:

  • GitLab Duo Chat: Interact with an AI assistant directly in VS Code.
  • GitLab Duo Code Suggestions: Suggest completions to your current line of code, or write natural-language code comments to get more substantive suggestions.

When you view a GitLab project in VS Code, the extension shows you information about your current branch:

  • The status of the branch’s most recent CI/CD pipeline.
  • A link to the merge request for this branch.
  • If the merge request includes an issue closing pattern, a link to the issue.

Customize keyboard shortcuts

You can assign different keyboard shortcuts for Accept Inline Suggestion, Accept Next Word Of Inline Suggestion, or Accept Next Line Of Inline Suggestion:

  1. In VS Code, run the Preferences: Open Keyboard Shortcuts command.
  2. Find the shortcut you want to edit, and select Change keybinding ().
  3. Assign your preferred shortcuts to Accept Inline Suggestion, Accept Next Word Of Inline Suggestion, or Accept Next Line Of Inline Suggestion.
  4. Press Enter to save your changes.

Switch GitLab accounts in VS Code

If you use multiple GitLab accounts (such as personal and work), the extension uses your git remote URL to determine which account to use. In some cases, the extension can’t determine which account to use, and must ask you to select which project and account to use. This can happen:

  • If you have a single remote URL git@gitlab.com:gitlab-org/gitlab-vscode-extension.git, but two accounts for gitlab.com (like @sidney and @sidney_work).
  • If you have a single GitLab account (for example @sidney), but you have multiple remotes, like:
    • origin: git@gitlab.com:gitlab-org/gitlab-vscode-extension.git
    • personal-fork: git@gitlab.com:myusername/gitlab-vscode-extension.git

In these cases, the extension adds a (multiple projects) label to show you must choose an account. To select an account:

  1. On the vertical menu bar, select GitLab Workflow () to display the extension sidebar.
  2. Expand Issues and Merge Requests.
  3. Select the line containing (multiple projects) to expand the list of accounts.
  4. Select the option you want to use: select project-account combination

The Issues and Merge requests list updates with your information.

Change your selection

To change your account selection for a project:

  1. On the vertical menu bar, select GitLab Workflow () to display the extension sidebar.
  2. Expand Issues and Merge Requests to show the project list.
  3. Right-click the project’s name, and select Clear selected project.

Use slash commands

Issues and merge requests support GitLab slash commands to perform actions directly in VS Code.

Create a snippet

Create a snippet to store and share bits of code and text with other users. Snippets can be a selection or an entire file.

To create a snippet in VS Code:

  1. Choose the content for your snippet:
    • For a Snippet from file, open the file.
    • For a Snippet from selection, open the file and select the lines you want to include.
  2. Open the Command Palette:
    • For macOS, press Command+Shift+P.
    • For Windows or Linux, press Ctrl+Shift+P.
  3. In the Command Palette, run the command GitLab: Create Snippet.
  4. Select the snippet’s privacy level:
    • Private snippets are visible only to project members.
    • Public snippets are visible to everyone.
  5. Select the snippet’s scope:
    • Snippet from file uses the entire contents of the active file.
    • Snippet from selection uses the lines you selected in the active file.

GitLab opens the new snippet’s page in a new browser tab.

Create a patch file

When you review a merge request, create a snippet patch when you want to suggest multi-file changes.

  1. On your local machine, check out the branch you want to propose changes to.
  2. In VS Code, edit all files you want to change. Do not commit your changes.
  3. Open the Command Palette:
    • For macOS, press Command+Shift+P.
    • For Windows or Linux, press Ctrl+Shift+P.
  4. In the Command Palette, enter GitLab: Create snippet patch, and select it. This command runs a git diff command and creates a GitLab snippet in your project.
  5. Enter a Patch name and press Enter. GitLab uses this name as the snippet title, and converts it into a filename appended with .patch.
  6. Select the snippet’s privacy level:
    • Private snippets are visible only to project members.
    • Public snippets are visible to everyone.

VS Code opens the snippet patch in a new browser tab. The snippet patch’s description contains instructions on how to apply the patch.

Insert a snippet

To insert an existing single-file or multi-file snippet from a project you are a member of:

  1. Place your cursor where you want to insert the snippet.
  2. Open the Command Palette:
    • For macOS, press Command+Shift+P.
    • For Windows or Linux, press Ctrl+Shift+P.
  3. Type GitLab: Insert Snippet and select it.
  4. Select the project containing your snippet.
  5. Select the snippet to apply.
  6. For a multi-file snippet, select the file to apply.

View issues and merge requests

To view issues and merge requests for a specific project:

  1. On the menu bar, select GitLab Workflow () to display the extension sidebar.
  2. On the sidebar, expand Issues and merge requests.
  3. Select your desired project to expand it.
  4. Choose one of the following result types:
    • Issues assigned to me
    • Issues created by me
    • Merge requests assigned to me
    • Merge requests I’m reviewing
    • Merge requests created by me
    • All project merge requests
    • Your custom queries

Select an issue or merge request to open it in a new VS Code tab.

Review a merge request

Use this extension to review, comment on, and approve merge requests without leaving VS Code:

  1. While viewing issues and merge requests in VS Code, select the merge request you want to review. Its sidebar entry expands with more information.
  2. Under the merge request’s number and title, select Description to read more about the merge request.
  3. To review the proposed changes to a file, select the file from the list to show it in a VS Code tab. Diff comments are shown inline in the tab. In the list, deleted files are marked in red:

    An alphabetical list of files changed in this merge request, including the type of changes.

Use the diff to:

  • Review and create discussions.
  • Resolve and unresolve these discussions.
  • Delete and edit individual comments.

Compare with default branch

To compare your branch with your project’s default branch, without creating a merge request:

  1. Open the Command Palette:
    • For macOS, press Command+Shift+P.
    • For Windows or Linux, press Ctrl+Shift+P.
  2. In the Command Palette, search for GitLab: Compare current branch with master and press Enter.

The extension opens a new browser tab. It shows a diff between the most recent commit on your branch, and the most recent commit on your project’s default branch.

Open current file in GitLab UI

To open a file from your current GitLab project in the GitLab UI, with specific lines highlighted:

  1. Open your desired file in VS Code.
  2. Select the lines you want to highlight.
  3. Open the Command Palette:
    • For macOS, press Command+Shift+P.
    • For Windows or Linux, press Ctrl+Shift+P.
  4. In the Command Palette, search for GitLab: Open active file on GitLab and press Enter.

View security findings

Tier: Ultimate Offering: GitLab.com, Self-managed, GitLab Dedicated

Prerequisites:

  • You’re using GitLab Workflow version 3.74.0 or later.
  • Your project includes Security Risk Management features, such as Static Application Security Testing (SAST), Dynamic Application Security Testing (DAST), Container Scanning, or Dependency Scanning.
  • You configured the Security Risk Management features.

To view security findings:

  1. On the vertical menu bar, select GitLab Workflow () to display the extension sidebar.
  2. On the sidebar, expand Security scanning.
  3. Select either New findings or Fixed findings.
  4. Select a desired severity level.
  5. Select a finding to open it in a VS Code tab.

Search issues and merge requests

To search your project’s issues and merge requests directly from VS Code, use filtered search or Advanced Search. With filtered search, you use predefined tokens to refine your search results. Advanced Search provides faster, more efficient search across the entire GitLab instance.

Prerequisites:

To search the titles and description fields in your project:

  1. In VS Code, open the Command Palette:
    • For macOS, press Command+Shift+P.
    • For Windows or Linux, press Ctrl+Shift+P.
  2. Select your desired search type: GitLab: Search project merge requests or GitLab: Search project issues.
  3. Enter your text, using filter tokens as needed.
  4. To confirm your search text, press Enter. To cancel, press Escape.

GitLab opens the results in a browser tab.

Filter searches with tokens

Searches in large projects return better results when you add filters. The extension supports these tokens for filtering merge requests and issues:

Token Example Description
assignee assignee: timzallmann Username of the assignee, without @.
author author: fatihacet Username of the author, without @.
label label: frontend or label:frontend label: Discussion A single label. Usable more than once, and can be used in the same query as labels.
labels labels: frontend, Discussion, performance Multiple labels in a comma-separated list. Can be used in the same query as label.
milestone milestone: 18.1 Milestone title without %.
scope scope: created-by-me or scope: assigned-to-me or scope: all. Issues and merge requests matching the given scope. Values: created-by-me (default), assigned-to-me or all.
title title: discussions refactor Issues and merge requests with title or description matching these words. Don’t add quotation marks around phrases.

Token syntax and guidelines:

  • Each token name requires a colon (:) after it, like label:.
    • A leading space for the colon (label :) is invalid and returns a parse error.
    • A space after the token name is optional. Both label: frontend and label:frontend are valid.
  • You can use the label and labels tokens multiple times and together. These queries return the same results:
    • labels: frontend discussion label: performance
    • label: frontend label: discussion label: performance
    • labels: frontend discussion performance (the resulting, combined query)

You can combine multiple tokens in a single search query. For example:

title: new merge request widget author: fatihacet assignee: jschatz1 labels: frontend, performance milestone: 17.5

This search query looks for:

  • Title: new merge request widget
  • Author: fatihacet
  • Assignee: jschatz1
  • Labels: frontend and performance
  • Milestone: 17.5