|
7 | 7 | --- The GitLab LSP enables any editor or IDE to integrate with GitLab Duo |
8 | 8 | --- for AI-powered code suggestions via the Language Server Protocol. |
9 | 9 | --- |
10 | | ---- **Prerequisites:** |
| 10 | +--- Prerequisites: |
11 | 11 | --- - Node.js and npm installed |
12 | 12 | --- - GitLab account with Duo Pro license |
13 | 13 | --- - Internet connection for OAuth device flow |
@@ -116,16 +116,12 @@ local function save_token(token_data) |
116 | 116 | end |
117 | 117 |
|
118 | 118 | local function load_token() |
119 | | - local file = io.open(config.token_file, 'r') |
120 | | - if file then |
121 | | - local content = file:read('*all') |
122 | | - file:close() |
123 | | - local ok, token_data = pcall(vim.json.decode, content) |
124 | | - if ok then |
125 | | - return token_data |
126 | | - end |
| 119 | + if vim.fn.filereadable(config.token_file) == 0 then |
| 120 | + return nil |
127 | 121 | end |
128 | | - return nil |
| 122 | + |
| 123 | + local blob = vim.fn.readblob(config.token_file) |
| 124 | + return vim.json.decode(blob) |
129 | 125 | end |
130 | 126 |
|
131 | 127 | local function is_token_expired(token_data) |
@@ -195,11 +191,7 @@ local function device_authorization() |
195 | 191 | return nil |
196 | 192 | end |
197 | 193 |
|
198 | | - local ok, data = pcall(vim.json.decode, response.body) |
199 | | - if not ok then |
200 | | - vim.notify('Failed to parse authorization response', vim.log.levels.ERROR) |
201 | | - return nil |
202 | | - end |
| 194 | + local data = vim.json.decode(response.body) |
203 | 195 |
|
204 | 196 | return data |
205 | 197 | end |
@@ -273,32 +265,7 @@ local function sign_in(_bufnr, client) |
273 | 265 | return |
274 | 266 | end |
275 | 267 |
|
276 | | - local message = string.format( |
277 | | - 'GitLab Duo Authorization\n\n' |
278 | | - .. '1. Open: %s\n' |
279 | | - .. '2. Enter code: %s\n\n' |
280 | | - .. 'Code copied to clipboard. Waiting for authorization...', |
281 | | - auth_data.verification_uri, |
282 | | - auth_data.user_code |
283 | | - ) |
284 | | - |
285 | | - -- Copy code to clipboard |
286 | | - vim.fn.setreg('+', auth_data.user_code) |
287 | | - vim.fn.setreg('*', auth_data.user_code) |
288 | | - |
289 | | - -- Show message with option to open browser |
290 | | - local choice = vim.fn.confirm(message, '&Open Browser\n&Continue') |
291 | | - |
292 | | - if choice == 1 then |
293 | | - -- Try to open browser |
294 | | - local open_cmd = vim.fn.has('mac') == 1 and 'open' |
295 | | - or vim.fn.has('unix') == 1 and 'xdg-open' |
296 | | - or vim.fn.has('win32') == 1 and 'start' |
297 | | - |
298 | | - if open_cmd then |
299 | | - vim.fn.system(open_cmd .. ' ' .. auth_data.verification_uri) |
300 | | - end |
301 | | - end |
| 268 | + vim.ui.open(auth_data.verification_uri .. '?user_code=' .. auth_data.user_code) |
302 | 269 |
|
303 | 270 | poll_for_token(auth_data.device_code, auth_data.interval or 5, client) |
304 | 271 | end |
|
0 commit comments