-
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
ba27093 to
e63b9ca
Compare
lsp/gitlab_duo.lua
Outdated
|
|
||
| -- 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, |
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 Thanks, cmd does not requires gitlab_uri, it is required in the workspace/didChangeConfiguration call. I couldn't find an easy way to pass this value around, we also need to make client_id configurable for self managed GitLab instances as the client_id will also be different. So I thought doing it in a separate iteration.
lsp/gitlab_duo.lua
Outdated
| -- 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. |
| }, | ||
| }, | ||
| 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.
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 Thanks, I dropped method call from settings
lsp/gitlab_duo.lua
Outdated
| --- 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.
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 configuration support working properly with config block, So I dropped support for self managed instances from this iteration. Could you review rest of the changes ?
This file contains the GitLab Duo Language Server configuration for Neovim, including setup instructions, token management, and OAuth device flow.
Add GitLab Duo Language Server configuration
Summary
This PR adds support for the GitLab Duo Language Server, enabling AI-powered code suggestions through the Language Server Protocol.
What is GitLab Duo?
GitLab Duo is GitLab's AI-powered coding assistant that provides intelligent code completion and suggestions directly in your editor. The LSP implementation allows any LSP-compatible editor to integrate with GitLab Duo.
Key Features
:LspGitLabDuoSignIn- Authenticate with GitLab:LspGitLabDuoSignOut- Sign out and remove tokens:LspGitLabDuoStatus- View authentication statusPrerequisites
Current Limitations
This initial implementation only supports GitLab.com. Support for self-managed GitLab instances will be added in a future iteration. The configuration is structured to make this addition straightforward when the OAuth application setup is documented for self-managed instances.
Usage
Basic Setup
Enable Inline Completion
Add this to your config to enable inline completions with Tab acceptance:
Authentication Flow
:LspGitLabDuoSignInin any buffer with the LSP attachedTokens are stored locally and refreshed automatically.
Implementation Details
npxto run the GitLab LSP package from GitLab's npm registryTesting
Tested on:
Future Enhancements
Related Links