- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2.4k
Add Gitlab Duo LSP configuration #4157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
This file contains the GitLab Duo Language Server configuration for Neovim, including setup instructions, token management, and OAuth device flow.
|  | ||
| -- Configuration | ||
| local config = { | ||
| gitlab_url = vim.env.GITLAB_URL or 'https://gitlab.com', | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just mentioning: users can provide arbitrary fields using vim.lsp.config():
vim.lsp.config('gitlab_duo', {
  gitlab_duo = {
    gitlab_url = '...',
  },
})Then in callbacks such as cmd() in this config, which are passed a config object, you can access those fields:
cmd = function(..., config)
  local foo = config.gitlab_duo
  ...
end)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@justinmk I couldn't get this working, cmd expects a table, not a function, right ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cmd can be a function. Example 
Lines 16 to 19 in cbd1e91
| cmd = function(dispatchers, config) | |
| local local_cmd = { 'lake', 'serve', '--', config.root_dir } | |
| return vim.lsp.rpc.start(local_cmd, dispatchers) | |
| end, | 
| -- Configuration | ||
| local config = { | ||
| gitlab_url = vim.env.GITLAB_URL or 'https://gitlab.com', | ||
| client_id = '5f1f9933c9bff0a3e908007703f260bf1ff87bcdb91d38279a9f0d0ddecceadf', | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe a code comment that gives a reference about where this id came from. e.g. is it a personally generated thing or part of official gitlab docs.
| This is a lot of code which is normally discouraged in this repo, but it looks pretty good and points to some common use-cases that we need to start thinking about in the stdlib. And for supporting LSP/AI providers that require sign-in, it's good to have self-contained examples (another is  So I'm fine with this. | 
Co-authored-by: Justin M. Keyes <[email protected]>
| }, | ||
| }, | ||
| settings = { | ||
| token = get_valid_token() or '', | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this only happens once, at module-load time. if the token expires what then? i think settings can be modified in an on_init handler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@justinmk We already do that on on_int by checking the /gitlab/token/check call. We use client.notify to update this value in LSP
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then just set this to '' ? It is misleading to just sprinkle a get_valid_token() call here, which again will have side effects like network calls at module-load time. It's better to do things in one place.
Co-authored-by: Justin M. Keyes <[email protected]>
| --- 2. Follow the browser prompts to authorize | ||
| --- 3. Enable inline completion in LspAttach event (see example below) | ||
| --- | ||
| --- **Inline Completion Example:** | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it wasn't clear but I was hoping that all cases would be looked at. Not just the ones I mentioned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@justinmk No, I was planning to do it with the other things including making gitlab_url and application_id configurable.
Add GitLab Duo Language Server Configuration
Summary
This PR adds native support for the GitLab Duo Language Server to the Neovim LSP configuration collection, enabling AI-powered code suggestions from GitLab Duo directly in Neovim.
Motivation
GitLab Duo provides AI-assisted code completion similar to GitHub Copilot, but requires a specific LSP setup with OAuth device flow authentication. This configuration makes it easy for Neovim users to integrate GitLab Duo into their workflow without manual LSP setup.
Features
🔐 OAuth Device Flow Authentication
🔄 Automatic Token Management
🎮 User Commands
:LspGitLabDuoSignIn- Start OAuth authentication flow:LspGitLabDuoSignOut- Sign out and remove stored token:LspGitLabDuoStatus- View authentication and token status⌨️ Standard Keybindings
Implementation Details
Authentication Flow
:LspGitLabDuoSignInToken Lifecycle
LSP Handlers
$/gitlab/token/check- Handles token validation errors$/gitlab/featureStateChange- Notifies about feature availabilityDependencies
Required:
curlmoduleRuntime:
Installation & Usage
Basic Setup
First-Time Authentication
Follow the browser prompts to authorize the application.
Testing
Manual Testing Steps
Install dependencies:
Load the configuration:
Authenticate:
Test suggestions:
.lua,.py,.js, etc.)Test token management:
Expected Behavior
Configuration Options
Users can customize the GitLab instance URL via environment variable:
Default is
https://gitlab.com.Supported Languages
Ruby, Go, JavaScript, TypeScript, React, Rust, Lua, Python, Java, C, C++, PHP, C#, Kotlin, Swift, Scala, Vue, Svelte, HTML, CSS, SCSS, JSON, YAML
Documentation
Checklist
Screenshots
Note: This configuration requires Neovim 0.12+ for native inline completion support.