Fix some more luals warnings

This commit is contained in:
Mathias Fussenegger 2024-06-02 20:12:55 +02:00 committed by Mathias Fußenegger
parent edb1020bcf
commit 8f57b4430c
4 changed files with 24 additions and 19 deletions

View file

@ -27,7 +27,9 @@ function M.create_logger(filename)
---@diagnostic disable-next-line: deprecated
return table.concat(vim.tbl_flatten{...}, path_sep)
end
local logfilename = joinpath(vim.fn.stdpath('cache'), filename)
local cache_dir = vim.fn.stdpath('cache')
assert(type(cache_dir) == "string")
local logfilename = joinpath(cache_dir, filename)
local current_log_level = M.levels.INFO
@ -42,7 +44,7 @@ function M.create_logger(filename)
return logfilename
end
vim.fn.mkdir(vim.fn.stdpath('cache'), "p")
vim.fn.mkdir(cache_dir, "p")
local logfile = assert(io.open(logfilename, "a+"))
for level, levelnr in pairs(M.levels) do
logger[level:lower()] = function(...)

View file

@ -2,12 +2,10 @@ local utils = require('dap.utils')
local M = {}
-- Copied from neovim rpc.lua
---@param header string
local function parse_headers(header)
if type(header) ~= 'string' then
return nil
end
local headers = {}
for line in vim.gsplit(header, '\r\n', true) do
for line in vim.gsplit(header, '\r\n', {plain = true}) do
if line == '' then
break
end
@ -33,6 +31,12 @@ local function parse_chunk_loop()
local start, finish = buffer:find('\r\n\r\n', 1, true)
if start then
local buffer_start = buffer:find(header_start_pattern)
if not buffer_start then
error(string.format(
"Headers were expected but debug adapter sent: %s",
buffer
))
end
local headers = parse_headers(buffer:sub(buffer_start, start - 1))
local content_length = headers.content_length
local body_chunks = {buffer:sub(finish + 1)}
@ -66,9 +70,7 @@ function M.create_read_loop(handle_body, on_no_chunk)
parse_chunk()
return function (err, chunk)
if err then
vim.schedule(function()
utils.notify(err, vim.log.levels.ERROR)
end)
utils.notify(err, vim.log.levels.ERROR)
return
end
if not chunk then

View file

@ -1845,18 +1845,20 @@ function Session:_frame_delta(delta)
end
local frames = self.threads[self.stopped_thread_id].frames
assert(frames, 'Stopped thread must have frames')
local current_frame_index = index_of(frames, function(i) return i.id == self.current_frame.id end)
assert(current_frame_index, 'id of current frame must be present in frames')
local frameidx = index_of(frames, function(i)
return i.id == self.current_frame.id
end)
assert(frameidx, 'id of current frame must be present in frames')
current_frame_index = current_frame_index + delta
if current_frame_index < 1 then
current_frame_index = 1
frameidx = frameidx + delta
if frameidx < 1 then
frameidx = 1
utils.notify("Can't move past first frame", vim.log.levels.INFO)
elseif current_frame_index > #frames then
current_frame_index = #frames
elseif frameidx > #frames then
frameidx = #frames
utils.notify("Can't move past last frame", vim.log.levels.INFO)
end
self:_frame_set(frames[current_frame_index])
self:_frame_set(frames[frameidx])
end
@ -1869,7 +1871,6 @@ end
function Session.event_process()
end
function Session.event_loadedSource()
end

View file

@ -46,7 +46,7 @@ end
---@generic T
---@param items T[]
---@param predicate fun(items: T[]):boolean
---@param predicate fun(items: T):boolean
---@result integer?
function M.index_of(items, predicate)
for i, item in ipairs(items) do