Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit63e7b4c

Browse files
committed
refactor(checkhealth): move completion to Lua, and module location
- Complete functionThere was lots of unnecessary C code for the complete function,therefore moving it to Lua and use all the plumbing we have in place toretrieve the results.- Moving the moduleIt's important we keep nvim lua modules name spaced, avoids conflictwith plugins, luarocks, etc.
1 parent081eb72 commit63e7b4c

File tree

8 files changed

+87
-113
lines changed

8 files changed

+87
-113
lines changed

‎runtime/doc/pi_health.txt‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,26 @@ Commands *health-commands*
4848
:checkhealth vim*
4949
<
5050
==============================================================================
51-
Lua Functions*health-functions-lua**health-lua*
51+
Lua Functions*health-functions-lua**health-lua**vim.health*
5252

5353
The Lua "health" module can be used to create new healthchecks (see also
54-
|health-functions-vim|). To get started, simply use:>
55-
local health = require('health')
56-
<
57-
health.report_start({name})*health.report_start()*
54+
|health-functions-vim|). To get started, simply use:
55+
56+
vim.health.report_start({name})*vim.health.report_start()*
5857
Starts a new report. Most plugins should call this only once, but if
5958
you want different sections to appear in your report, call this once
6059
per section.
6160

62-
health.report_info({msg})*health.report_info()*
61+
vim.health.report_info({msg})*vim.health.report_info()*
6362
Reports an informational message.
6463

65-
health.report_ok({msg})*health.report_ok()*
64+
vim.health.report_ok({msg})*vim.health.report_ok()*
6665
Reports a "success" message.
6766

68-
health.report_warn({msg} [,{advice}])*health.report_warn()*
67+
vim.health.report_warn({msg} [,{advice}])*vim.health.report_warn()*
6968
Reports a warning.{advice} is an optional List of suggestions.
7069

71-
health.report_error({msg} [,{advice}])*health.report_error()*
70+
vim.health.report_error({msg} [,{advice}])*vim.health.report_error()*
7271
Reports an error.{advice} is an optional List of suggestions.
7372

7473
==============================================================================
@@ -98,15 +97,14 @@ Copy this sample code into `lua/foo/health/init.lua` or `lua/foo/health.lua`,
9897
replacing "foo" in the path with your plugin name:>
9998
10099
local M = {}
101-
local health = require("health")
102100
103101
M.check = function()
104-
health.report_start("my_plugin report")
102+
vim.health.report_start("my_plugin report")
105103
-- make sure setup function parameters are ok
106104
if check_setup() then
107-
health.report_ok("Setup function is correct")
105+
vim.health.report_ok("Setup function is correct")
108106
else
109-
health.report_error("Setup function is incorrect")
107+
vim.health.report_error("Setup function is incorrect")
110108
end
111109
-- do some more checking
112110
-- ...

‎runtime/lua/health.lua‎

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
1-
localM= {}
2-
3-
functionM.report_start(msg)
4-
vim.fn['health#report_start'](msg)
5-
end
6-
7-
functionM.report_info(msg)
8-
vim.fn['health#report_info'](msg)
9-
end
10-
11-
functionM.report_ok(msg)
12-
vim.fn['health#report_ok'](msg)
13-
end
14-
15-
functionM.report_warn(msg, ...)
16-
vim.fn['health#report_warn'](msg,...)
17-
end
18-
19-
functionM.report_error(msg, ...)
20-
vim.fn['health#report_error'](msg,...)
21-
end
22-
23-
returnM
1+
returnsetmetatable({}, {
2+
__index=function(_,k)
3+
vim.deprecate("require('health')",'vim.health','0.9',false)
4+
returnvim.health[k]
5+
end,
6+
})

‎runtime/lua/vim/_editor.lua‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ for k, v in pairs({
4949
diagnostic=true,
5050
keymap=true,
5151
ui=true,
52+
health=true,
5253
})do
5354
vim._submodules[k]=v
5455
end

‎runtime/lua/vim/health.lua‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
localM= {}
2+
3+
functionM.report_start(msg)
4+
vim.fn['health#report_start'](msg)
5+
end
6+
7+
functionM.report_info(msg)
8+
vim.fn['health#report_info'](msg)
9+
end
10+
11+
functionM.report_ok(msg)
12+
vim.fn['health#report_ok'](msg)
13+
end
14+
15+
functionM.report_warn(msg, ...)
16+
vim.fn['health#report_warn'](msg,...)
17+
end
18+
19+
functionM.report_error(msg, ...)
20+
vim.fn['health#report_error'](msg,...)
21+
end
22+
23+
localpath2name=function(path)
24+
ifpath:match('%.lua$')then
25+
-- Lua: transform "../lua/vim/lsp/health.lua" into "vim.lsp"
26+
returnpath:gsub('.-lua[%\\%/]','',1):gsub('[%\\%/]','.'):gsub('%.health.-$','')
27+
else
28+
-- Vim: transform "../autoload/health/provider.vim" into "provider"
29+
returnvim.fn.fnamemodify(path,':t:r')
30+
end
31+
end
32+
33+
localPATTERNS= {'/autoload/health/*.vim','/lua/**/**/health.lua','/lua/**/**/health/init.lua'}
34+
-- :checkhealth completion function used by ex_getln.c get_healthcheck_names()
35+
M._complete=function()
36+
localnames=vim.tbl_flatten(vim.tbl_map(function(pattern)
37+
returnvim.tbl_map(path2name,vim.api.nvim_get_runtime_file(pattern,true))
38+
end,PATTERNS))
39+
-- Remove duplicates
40+
localunique= {}
41+
vim.tbl_map(function(f)
42+
unique[f]=true
43+
end,names)
44+
returnvim.tbl_keys(unique)
45+
end
46+
47+
returnM

‎src/nvim/ex_getln.c‎

Lines changed: 14 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -230,23 +230,6 @@ static int compl_match_arraysize;
230230
staticintcompl_startcol;
231231
staticintcompl_selected;
232232

233-
/// |:checkhealth| completion items
234-
///
235-
/// Regenerates on every new command line prompt, to accommodate changes on the
236-
/// runtime files.
237-
typedefstruct {
238-
garray_Tnames;// healthcheck names
239-
unsignedlast_gen;// last_prompt_id where names were generated
240-
}CheckhealthComp;
241-
242-
/// Cookie used when converting filepath to name
243-
structhealthchecks_cookie {
244-
garray_T*names;// global healthchecks
245-
boolis_lua;// true if the current entry is a Lua healthcheck
246-
};
247-
248-
staticCheckhealthComphealthchecks= {GA_INIT(sizeof(char_u*),10),0 };
249-
250233
#ifdefINCLUDE_GENERATED_DECLARATIONS
251234
# include"ex_getln.c.generated.h"
252235
#endif
@@ -295,59 +278,23 @@ static void init_incsearch_state(incsearch_state_T *s)
295278
/// @param[in] xp Not used.
296279
staticchar*get_healthcheck_names(expand_T*xp,intidx)
297280
{
298-
// Generate the first time or on new prompt.
299-
if (healthchecks.last_gen==0||healthchecks.last_gen!=last_prompt_id) {
300-
ga_clear_strings(&healthchecks.names);
301-
char*patterns[3]= {"autoload/health/**.vim","lua/**/**/health/init.lua",// NOLINT
302-
"lua/**/**/health.lua" };// NOLINT
303-
for (inti=0;i<3;i++) {
304-
structhealthchecks_cookiehcookie= { .names=&healthchecks.names, .is_lua=i!=0 };
305-
do_in_runtimepath(patterns[i],DIP_ALL,get_healthcheck_cb,&hcookie);
306-
307-
if (healthchecks.names.ga_len>0) {
308-
ga_remove_duplicate_strings(&healthchecks.names);
309-
}
310-
}
311-
// Tracked to regenerate items on next prompt.
312-
healthchecks.last_gen=last_prompt_id;
313-
}
314-
returnidx<healthchecks.names.ga_len
315-
? ((char**)(healthchecks.names.ga_data))[idx] :NULL;
316-
}
317-
318-
/// Transform healthcheck file path into it's name.
319-
///
320-
/// Used as a callback for do_in_runtimepath
321-
/// @param[in] path Expanded path to a possible healthcheck.
322-
/// @param[out] cookie Array where names will be inserted.
323-
staticvoidget_healthcheck_cb(char*path,void*cookie)
324-
{
325-
if (path!=NULL) {
326-
structhealthchecks_cookie*hcookie= (structhealthchecks_cookie*)cookie;
327-
char*pattern;
328-
char*sub="\\1";
329-
char*res;
330-
331-
if (hcookie->is_lua) {
332-
// Lua: transform "../lua/vim/lsp/health.lua" into "vim.lsp"
333-
pattern=".*lua[\\/]\\(.\\{-}\\)[\\/]health\\([\\/]init\\)\\?\\.lua$";
334-
}else {
335-
// Vim: transform "../autoload/health/provider.vim" into "provider"
336-
pattern=".*[\\/]\\([^\\/]*\\)\\.vim$";
337-
}
281+
staticObjectnames=OBJECT_INIT;
282+
staticunsignedlast_gen=0;
338283

339-
res=do_string_sub(path,pattern,sub,NULL,"g");
340-
if (hcookie->is_lua&&res!=NULL) {
341-
// Replace slashes with dots as represented by the healthcheck plugin.
342-
char*ares=do_string_sub(res,"[\\/]",".",NULL,"g");
343-
xfree(res);
344-
res=ares;
345-
}
284+
if (last_gen!=last_prompt_id||last_gen==0) {
285+
Arraya=ARRAY_DICT_INIT;
286+
Errorerr=ERROR_INIT;
287+
Objectres=nlua_exec(STATIC_CSTR_AS_STRING("return vim.health._complete()"),a,&err);
288+
api_clear_error(&err);
289+
api_free_object(names);
290+
names=res;
291+
last_gen=last_prompt_id;
292+
}
346293

347-
if (res!=NULL) {
348-
GA_APPEND(char*,hcookie->names,res);
349-
}
294+
if (names.type==kObjectTypeArray&&idx< (int)names.data.array.size) {
295+
returnnames.data.array.items[idx].data.string.data;
350296
}
297+
returnNULL;
351298
}
352299

353300
// Return true when 'incsearch' highlighting is to be done.
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
localM= {}
2-
localhealth=require("health")
32

43
M.check=function()
5-
health.report_start("report 1")
6-
health.report_ok("everything is fine")
7-
health.report_start("report 2")
8-
health.report_ok("nothing to see here")
4+
vim.health.report_start("report 1")
5+
vim.health.report_ok("everything is fine")
6+
vim.health.report_start("report 2")
7+
vim.health.report_ok("nothing to see here")
98
end
109

1110
returnM

‎test/functional/fixtures/lua/test_plug/submodule/health.lua‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
localM= {}
2-
localhealth=require("health")
2+
localhealth=require("health")-- change to use vim.health on 0.9
33

44
M.check=function()
55
health.report_start("report 1")

‎test/functional/fixtures/lua/test_plug/submodule_failed/health.lua‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
localM= {}
2-
localhealth=require("health")
32

43
M.check=function()
5-
health.report_start("report 1")
6-
health.report_ok("everything is fine")
7-
health.report_warn("About to add a number to nil")
4+
vim.health.report_start("report 1")
5+
vim.health.report_ok("everything is fine")
6+
vim.health.report_warn("About to add a number to nil")
87
locala=nil+2
98
returna
109
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp