@@ -323,13 +323,14 @@ function M.prepare_attach(blocking)
323
323
function handlers .evaluate (request )
324
324
local args = request .arguments
325
325
if args .context == " repl" then
326
- local frame = frames [args .frameId ]
326
+ local frame = args . frameId and frames [args .frameId ]
327
327
local a = 1
328
328
local prev
329
329
local cur = {}
330
330
local first = cur
331
331
332
332
while true do
333
+ if not frame then break end
333
334
local succ , ln , lv = pcall (debug.getlocal , frame + 1 , a )
334
335
if not succ then
335
336
break
@@ -355,31 +356,35 @@ function M.prepare_attach(blocking)
355
356
356
357
a = 1
357
358
358
- local succ , info = pcall (debug.getinfo , frame + 1 )
359
- if succ and info and info .func then
360
- local func = info .func
361
- local a = 1
362
- while true do
363
- local succ , ln , lv = pcall (debug.getupvalue , func , a )
364
- if not succ then
365
- break
366
- end
359
+ if frame then
360
+ local succ , info = pcall (debug.getinfo , frame + 1 )
361
+ if succ and info and info .func then
362
+ local func = info .func
363
+ local a = 1
364
+ while true do
365
+ local succ , ln , lv = pcall (debug.getupvalue , func , a )
366
+ if not succ then
367
+ break
368
+ end
367
369
368
- if not ln then
369
- break
370
- else
371
- -- Avoid shadowing of the globals if a local variable is nil
372
- cur [ln ] = lv or vim .NIL
373
- a = a + 1
370
+ if not ln then
371
+ break
372
+ else
373
+ -- Avoid shadowing of the globals if a local variable is nil
374
+ cur [ln ] = lv or vim .NIL
375
+ a = a + 1
376
+ end
374
377
end
375
378
end
376
379
end
377
380
378
- local succ , info = pcall (debug.getinfo , frame + 1 )
379
- if succ and info and info .func then
380
- setmetatable (cur , {
381
- __index = getfenv (info .func )
382
- })
381
+ if frame then
382
+ local succ , info = pcall (debug.getinfo , frame + 1 )
383
+ if succ and info and info .func then
384
+ setmetatable (cur , {
385
+ __index = getfenv (info .func )
386
+ })
387
+ end
383
388
end
384
389
385
390
local expr = args .expression
@@ -416,13 +421,14 @@ function M.prepare_attach(blocking)
416
421
}))
417
422
418
423
elseif args .context == " hover" then
419
- local frame = frames [args .frameId ]
424
+ local frame = args . frameId and frames [args .frameId ]
420
425
local a = 1
421
426
local prev
422
427
local cur = {}
423
428
local first = cur
424
429
425
430
while true do
431
+ if not frame then break end
426
432
local succ , ln , lv = pcall (debug.getlocal , frame + 1 , a )
427
433
if not succ then
428
434
break
@@ -448,31 +454,35 @@ function M.prepare_attach(blocking)
448
454
449
455
a = 1
450
456
451
- local succ , info = pcall (debug.getinfo , frame + 1 )
452
- if succ and info and info .func then
453
- local func = info .func
454
- local a = 1
455
- while true do
456
- local succ , ln , lv = pcall (debug.getupvalue , func , a )
457
- if not succ then
458
- break
459
- end
457
+ if frame then
458
+ local succ , info = pcall (debug.getinfo , frame + 1 )
459
+ if succ and info and info .func then
460
+ local func = info .func
461
+ local a = 1
462
+ while true do
463
+ local succ , ln , lv = pcall (debug.getupvalue , func , a )
464
+ if not succ then
465
+ break
466
+ end
460
467
461
- if not ln then
462
- break
463
- else
464
- -- Avoid shadowing of the globals if a local variable is nil
465
- cur [ln ] = lv or vim .NIL
466
- a = a + 1
468
+ if not ln then
469
+ break
470
+ else
471
+ -- Avoid shadowing of the globals if a local variable is nil
472
+ cur [ln ] = lv or vim .NIL
473
+ a = a + 1
474
+ end
467
475
end
468
476
end
469
477
end
470
478
471
- local succ , info = pcall (debug.getinfo , frame + 1 )
472
- if succ and info and info .func then
473
- setmetatable (cur , {
474
- __index = getfenv (info .func )
475
- })
479
+ if frame then
480
+ local succ , info = pcall (debug.getinfo , frame + 1 )
481
+ if succ and info and info .func then
482
+ setmetatable (cur , {
483
+ __index = getfenv (info .func )
484
+ })
485
+ end
476
486
end
477
487
478
488
local expr = args .expression
@@ -1244,6 +1254,7 @@ function M.prepare_attach(blocking)
1244
1254
local first = cur
1245
1255
1246
1256
while true do
1257
+ if not frame then break end
1247
1258
local succ , ln , lv = pcall (debug.getlocal , frame + 1 , a )
1248
1259
if not succ then
1249
1260
break
@@ -1269,31 +1280,35 @@ function M.prepare_attach(blocking)
1269
1280
1270
1281
a = 1
1271
1282
1272
- local succ , info = pcall (debug.getinfo , frame + 1 )
1273
- if succ and info and info .func then
1274
- local func = info .func
1275
- local a = 1
1276
- while true do
1277
- local succ , ln , lv = pcall (debug.getupvalue , func , a )
1278
- if not succ then
1279
- break
1280
- end
1281
-
1282
- if not ln then
1283
- break
1284
- else
1285
- -- Avoid shadowing of the globals if a local variable is nil
1286
- cur [ln ] = lv or vim .NIL
1287
- a = a + 1
1283
+ if frame then
1284
+ local succ , info = pcall (debug.getinfo , frame + 1 )
1285
+ if succ and info and info .func then
1286
+ local func = info .func
1287
+ local a = 1
1288
+ while true do
1289
+ local succ , ln , lv = pcall (debug.getupvalue , func , a )
1290
+ if not succ then
1291
+ break
1292
+ end
1293
+
1294
+ if not ln then
1295
+ break
1296
+ else
1297
+ -- Avoid shadowing of the globals if a local variable is nil
1298
+ cur [ln ] = lv or vim .NIL
1299
+ a = a + 1
1300
+ end
1288
1301
end
1289
1302
end
1290
1303
end
1291
1304
1292
- local succ , info = pcall (debug.getinfo , frame + 1 )
1293
- if succ and info and info .func then
1294
- setmetatable (cur , {
1295
- __index = getfenv (info .func )
1296
- })
1305
+ if frame then
1306
+ local succ , info = pcall (debug.getinfo , frame + 1 )
1307
+ if succ and info and info .func then
1308
+ setmetatable (cur , {
1309
+ __index = getfenv (info .func )
1310
+ })
1311
+ end
1297
1312
end
1298
1313
1299
1314
local succ , f = pcall (loadstring , " return " .. expr )
@@ -1323,6 +1338,7 @@ function M.prepare_attach(blocking)
1323
1338
local first = cur
1324
1339
1325
1340
while true do
1341
+ if not frame then break end
1326
1342
local succ , ln , lv = pcall (debug.getlocal , frame + 1 , a )
1327
1343
if not succ then
1328
1344
break
@@ -1348,31 +1364,35 @@ function M.prepare_attach(blocking)
1348
1364
1349
1365
a = 1
1350
1366
1351
- local succ , info = pcall (debug.getinfo , frame + 1 )
1352
- if succ and info and info .func then
1353
- local func = info .func
1354
- local a = 1
1355
- while true do
1356
- local succ , ln , lv = pcall (debug.getupvalue , func , a )
1357
- if not succ then
1358
- break
1359
- end
1360
-
1361
- if not ln then
1362
- break
1363
- else
1364
- -- Avoid shadowing of the globals if a local variable is nil
1365
- cur [ln ] = lv or vim .NIL
1366
- a = a + 1
1367
+ if frame then
1368
+ local succ , info = pcall (debug.getinfo , frame + 1 )
1369
+ if succ and info and info .func then
1370
+ local func = info .func
1371
+ local a = 1
1372
+ while true do
1373
+ local succ , ln , lv = pcall (debug.getupvalue , func , a )
1374
+ if not succ then
1375
+ break
1376
+ end
1377
+
1378
+ if not ln then
1379
+ break
1380
+ else
1381
+ -- Avoid shadowing of the globals if a local variable is nil
1382
+ cur [ln ] = lv or vim .NIL
1383
+ a = a + 1
1384
+ end
1367
1385
end
1368
1386
end
1369
1387
end
1370
1388
1371
- local succ , info = pcall (debug.getinfo , frame + 1 )
1372
- if succ and info and info .func then
1373
- setmetatable (cur , {
1374
- __index = getfenv (info .func )
1375
- })
1389
+ if frame then
1390
+ local succ , info = pcall (debug.getinfo , frame + 1 )
1391
+ if succ and info and info .func then
1392
+ setmetatable (cur , {
1393
+ __index = getfenv (info .func )
1394
+ })
1395
+ end
1376
1396
end
1377
1397
1378
1398
local succ , f = pcall (loadstring , " return " .. expr )
0 commit comments