-
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
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.
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 couldn't find an easy way to pass this value around
You can set arbitrary properties on the client or config.
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. |
This file contains the GitLab Duo Language Server configuration for Neovim, including setup instructions, token management, and OAuth device flow.
| -- This is a oauth application created from tachyons-gitlab account with `api` scope | ||
| client_id = '00bb391f527d2e77b3467b0b6b900151cc6a28dcfb18fa1249871e43bc3e5832', |
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.
That seems kind of strange. Do users need to generate their own client_id? Is this config dependent on your account?
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 There is no need to create a client_id per user. Alternatively one of the maintainer of this repo can create a GitLab application and add the client_id here.
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.
Makes no difference to me, just trying to understand, and ensure that we document stuff and can answer questions in the future.
| --- vim.api.nvim_create_autocmd('LspAttach', { | ||
| --- callback = function(args) | ||
| --- local bufnr = args.buf | ||
| --- local client = assert(vim.lsp.get_client_by_id(args.data.client_id)) | ||
| --- | ||
| --- if vim.lsp.inline_completion and | ||
| --- client:supports_method(vim.lsp.protocol.Methods.textDocument_inlineCompletion, bufnr) then | ||
| --- vim.lsp.inline_completion.enable(true, { bufnr = bufnr }) |
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 should have asked this for Copilot too, but ... why don't we just do this when this config is enabled? Why should the user need to manually add this.
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 used copilot.lua as the reference implication, that is why I followed the same pattern
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 think we should change both imo
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