- Code Suggestions features
- Set up the GitLab Workflow extension
- Configure extension settings
- Integrate with GitLab
- Create a snippet
- Related topics
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.
The GitLab Workflow extension streamlines your VS Code workflow with AI-assisted features:
- GitLab Duo Chat: Interact with an AI assistant directly in VS Code. See how to set up GitLab Duo Chat.
- GitLab Duo Code Suggestions: Suggest completions to your current line of code, or write natural-language code comments to get more substantive suggestions.
Code Suggestions features
GitLab Duo Code Suggestions provides AI-powered suggestions as you type in VS Code, helping you write code more efficiently. To interact with a suggestion on the current line:
- To accept the entire suggestion, press Tab.
- To accept the suggestion word-by-word, press Command + → (right arrow).
- To accept an entire line, right-click and select Accept Line.
GitLab Duo can also generate code based on comments in the file you’re editing in VS Code. When you write comments in a supported file type, use natural language to describe what you want the code to do. Press Enter to see suggestions from GitLab Duo inline in your current file.
To learn more, see the documentation for Code Suggestions.
Configure more languages for Code Suggestions
To add more languages to Code Suggestions:
- Find your desired language in the list of language identifiers for VS Code. You need the Identifier for a later step.
- In VS Code, open the extension settings for GitLab Workflow:
- On the top bar, go to Code > Settings > Extensions.
- Search for GitLab Workflow in the list, then select Manage () > Extension Settings.
- In your User settings, find GitLab › Duo Code Suggestions: Additional Languages and select Add Item.
- In Item, add the language identifier, and select OK.
Set up the GitLab Workflow extension
This extension requires you to create a GitLab personal access token, and assign it to the extension:
- Install the extension from the Visual Studio Marketplace and enable it. If you use an unofficial version of VS Code, install the extension from the Open VSX Registry.
- To sign in to your GitLab instance, run the command GitLab: Authenticate in VS Code.
- Open the command palette by pressing Command + Shift + P.
- In the command palette, search for GitLab: Authenticate and press Enter.
- Select your GitLab instance URL from the offered options, or enter one manually.
- When manually adding an instance to URL to GitLab instance, paste the full URL to your
GitLab instance, including the
http://
orhttps://
. Press Enter to confirm.
- When manually adding an instance to URL to GitLab instance, paste the full URL to your
GitLab instance, including the
- For
GitLab.com
, you can use the OAuth authentication method. - If you don’t use OAuth, use a personal access token to sign in.
- If you have an existing personal access token with
api
scope, select Enter an existing token to enter it. - If you don’t, select Create a token first, and the extension opens the token settings page for you. If this method fails, follow the instructions to create a personal access token.
- If you have an existing personal access token with
- Copy the token. For security reasons, this value is never displayed again, so you must copy this value now.
- Paste in your GitLab personal access token and press Enter. The token is not displayed, nor is it accessible to others.
The extension matches your Git repository remote URL with the GitLab instance URL you specified for your token. If you have multiple accounts or projects, you can choose the one you want to use. For more details, see Account management.
The extension shows information in the VS Code status bar if both:
- Your project has a pipeline for the last commit.
- Your current branch is associated with a merge request.
Configure extension settings
After you install GitLab Workflow, go to Settings > Extensions > GitLab Workflow in VS Code to configure its settings:
- GitLab Duo Chat.
- Features to display or hide.
- Self-signed certificate information.
- Code Suggestions.
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:
- In VS Code, run the
Preferences: Open Keyboard Shortcuts
command. - Find the shortcut you want to edit, and select Change keybinding ().
- Assign your preferred shortcuts to Accept Inline Suggestion, Accept Next Word Of Inline Suggestion, or Accept Next Line Of Inline Suggestion.
- Press Enter to save your changes.
Integrate with GitLab
This extension brings the GitLab features you use every day directly into your VS Code environment:
- View issues and merge requests.
- Run common commands from the Visual Studio Code command palette.
- Create and review merge requests.
- Validate your GitLab CI/CD configuration.
- View pipeline status and job outputs.
- Create and manage snippets.
- Browse repositories without cloning them.
- View security findings.
For detailed information on these features, refer to the GitLab Workflow extension documentation.
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:
- 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.
- Open the Command Palette:
- For macOS, press Command+Shift+P.
- For Windows or Linux, press Ctrl+Shift+P.
- In the command palette, run the command
GitLab: Create Snippet
. - Select the snippet’s privacy level:
- Private snippets are visible only to project members.
- Public snippets are visible to everyone.
- 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.
- On your local machine, check out the branch you want to propose changes to.
- In VS Code, edit all files you want to change. Do not commit your changes.
- Open the Command Palette, enter
GitLab: Create snippet patch
, and select it. This command runs agit diff
command and creates a GitLab snippet in your project. - Enter a Patch name and press Enter. GitLab uses this name as the
snippet title, and converts it into a filename appended with
.patch
. - 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:
- Place your cursor where you want to insert the snippet.
- Open the Command Palette:
- For macOS, press Command+Shift+P.
- For Windows or Linux, press Ctrl+Shift+P.
- Type
GitLab: Insert Snippet
and select it. - Select the project containing your snippet.
- Select the snippet to apply.
- For a multi-file snippet, select the file to apply.