mirror of
https://github.com/linrongbin16/lsp-progress.nvim.git
synced 2024-09-16 14:24:06 +02:00
fix(LspProgress): fix data polled from lsp clients for nvim-0.10 (#137)
ci(lint): migrate typecheck to 'mrcjkb/lua-typecheck-action' (#137) ci(coverage): merge reports from multiple nvim versions (#137)
This commit is contained in:
parent
0d45f17f68
commit
d5c9c5783c
5 changed files with 63 additions and 37 deletions
29
.github/workflows/ci.yml
vendored
29
.github/workflows/ci.yml
vendored
|
@ -21,12 +21,10 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: stevearc/nvim-typecheck-action@v1
|
||||
- uses: mrcjkb/lua-typecheck-action@v0
|
||||
with:
|
||||
path: lua
|
||||
level: Information
|
||||
directories: lua
|
||||
configpath: ".luarc.json"
|
||||
neodev-version: stable
|
||||
- uses: cargo-bins/cargo-binstall@main
|
||||
- name: Selene
|
||||
run: |
|
||||
|
@ -41,6 +39,7 @@ jobs:
|
|||
if: ${{ github.ref != 'refs/heads/main' }}
|
||||
with:
|
||||
commit_message: "chore(pr): auto-commit"
|
||||
push_options: "--force"
|
||||
unit_test:
|
||||
name: Unit test
|
||||
strategy:
|
||||
|
@ -58,25 +57,6 @@ jobs:
|
|||
with:
|
||||
luaVersion: "luajit-2.1.0-beta3"
|
||||
- uses: leafo/gh-actions-luarocks@v4
|
||||
- name: Run Tests
|
||||
shell: bash
|
||||
run: |
|
||||
luarocks install vusted
|
||||
vusted --shuffle ./test
|
||||
code_coverage:
|
||||
name: Code Coverage
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: rhysd/action-setup-vim@v1
|
||||
id: vim
|
||||
with:
|
||||
neovim: true
|
||||
version: stable
|
||||
- uses: leafo/gh-actions-lua@v10
|
||||
with:
|
||||
luaVersion: "luajit-2.1.0-beta3"
|
||||
- uses: leafo/gh-actions-luarocks@v4
|
||||
- name: Run Tests
|
||||
shell: bash
|
||||
run: |
|
||||
|
@ -94,7 +74,7 @@ jobs:
|
|||
ls -l .
|
||||
echo "cat ./luacov.report.out"
|
||||
cat ./luacov.report.out
|
||||
- uses: codecov/codecov-action@v3
|
||||
- uses: codecov/codecov-action@v4
|
||||
with:
|
||||
files: luacov.report.out
|
||||
env:
|
||||
|
@ -105,7 +85,6 @@ jobs:
|
|||
needs:
|
||||
- lint
|
||||
- unit_test
|
||||
- code_coverage
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: google-github-actions/release-please-action@v3
|
||||
|
|
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -41,3 +41,9 @@ luac.out
|
|||
|
||||
# macOS
|
||||
.DS_Store
|
||||
|
||||
# logs
|
||||
stdout.txt
|
||||
stderr.txt
|
||||
service.log
|
||||
*lsp-progress.nvim_lsp-progress.nvim_lua.log
|
||||
|
|
|
@ -3,6 +3,7 @@ local defaults = require("lsp-progress.defaults")
|
|||
local event = require("lsp-progress.event")
|
||||
local Series = require("lsp-progress.series").Series
|
||||
local Client = require("lsp-progress.client").Client
|
||||
local api = require("lsp-progress.api")
|
||||
|
||||
local NVIM_VERSION_010 = vim.fn.has("nvim-0.10") > 0
|
||||
|
||||
|
@ -243,22 +244,31 @@ local function method_handler(err, msg, ctx)
|
|||
update_progress(client, msg)
|
||||
end
|
||||
|
||||
--- @param c table?
|
||||
local function _is_lsp_client_obj(c)
|
||||
return type(c) == "table" and c.id and type(c.name) == "string"
|
||||
return type(c) == "table"
|
||||
and type(c.id) == "number"
|
||||
and type(c.name) == "string"
|
||||
and type(c.progress) == "table"
|
||||
end
|
||||
|
||||
--- @param p table?
|
||||
local function _is_lsp_progress_obj(p)
|
||||
return type(p) == "table" and p.token and type(p.value) == "table"
|
||||
end
|
||||
|
||||
local function event_handler()
|
||||
local lsp_clients = vim.lsp.get_active_clients()
|
||||
for _, client in ipairs(lsp_clients) do
|
||||
if _is_lsp_client_obj(client) and type(client.progress) == "table" then
|
||||
for progress in client.progress do
|
||||
-- logger.debug("|setup| v0.10 progress:%s", vim.inspect(progress))
|
||||
if _is_lsp_progress_obj(progress) then
|
||||
update_progress(client, progress)
|
||||
local clients = api.lsp_clients()
|
||||
for _, client in ipairs(clients) do
|
||||
if _is_lsp_client_obj(client) then
|
||||
local progress = client.progress
|
||||
while true do
|
||||
local prog_obj = progress:pop()
|
||||
if prog_obj == nil then
|
||||
break
|
||||
end
|
||||
if _is_lsp_progress_obj(prog_obj) then
|
||||
update_progress(client, prog_obj)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -270,7 +280,7 @@ end
|
|||
local function progress(option)
|
||||
option = vim.tbl_deep_extend("force", vim.deepcopy(Configs), option or {})
|
||||
|
||||
local active_clients_count = #vim.lsp.get_active_clients()
|
||||
local active_clients_count = #api.lsp_clients()
|
||||
if active_clients_count <= 0 then
|
||||
return ""
|
||||
end
|
||||
|
@ -344,9 +354,6 @@ local function setup(option)
|
|||
require("lsp-progress.client").setup(Configs.client_format, Configs.spinner)
|
||||
|
||||
if NVIM_VERSION_010 then
|
||||
-- see:
|
||||
-- https://github.com/neovim/neovim/blob/582d7f47905d82f315dc852a9d2937cd5b655e55/runtime/doc/news.txt#L44
|
||||
-- https://github.com/neovim/neovim/blob/582d7f47905d82f315dc852a9d2937cd5b655e55/runtime/lua/vim/lsp/util.lua#L348
|
||||
vim.api.nvim_create_autocmd("LspProgress", { callback = event_handler })
|
||||
else
|
||||
if not Registered then
|
||||
|
|
14
lua/lsp-progress/api.lua
Normal file
14
lua/lsp-progress/api.lua
Normal file
|
@ -0,0 +1,14 @@
|
|||
---@diagnostic disable: deprecated
|
||||
local NVIM_VERSION_010 = vim.fn.has("nvim-0.10") > 0
|
||||
|
||||
local M = {}
|
||||
|
||||
M.lsp_clients = function()
|
||||
if NVIM_VERSION_010 then
|
||||
return vim.lsp.get_clients()
|
||||
else
|
||||
return vim.lsp.get_active_clients()
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
20
test/api_spec.lua
Normal file
20
test/api_spec.lua
Normal file
|
@ -0,0 +1,20 @@
|
|||
local cwd = vim.fn.getcwd()
|
||||
|
||||
describe("api", function()
|
||||
local assert_eq = assert.is_equal
|
||||
local assert_true = assert.is_true
|
||||
local assert_false = assert.is_false
|
||||
|
||||
before_each(function()
|
||||
vim.api.nvim_command("cd " .. cwd)
|
||||
end)
|
||||
|
||||
local api = require("lsp-progress.api")
|
||||
|
||||
describe("[lsp_clients]", function()
|
||||
it("counts", function()
|
||||
assert_eq(type(api.lsp_clients()), "table")
|
||||
assert_eq(type(#api.lsp_clients()), "number")
|
||||
end)
|
||||
end)
|
||||
end)
|
Loading…
Reference in a new issue