FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
librime-lua-script/lua/component/debug_filter.lua at main · shewer/librime-lua-script · GitHub
shewer
librime-lua-script
Repository navigation
Code
Issues
4
(4)
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
librime-lua-script
/
lua
/
component
/
debug_filter.lua
Copy path
More file actions
More file actions
Latest commit
History
History
History
156 lines (130 loc) · 4.2 KB
Breadcrumbs
librime-lua-script
/
lua
/
component
/
debug_filter.lua
Copy path
File metadata and controls
156 lines (130 loc) · 4.2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!
/usr/bin/env lua
--
--
debug_filter.lua
--
Copyright (C) 2022 Shewer Lu <shewer@gmail.com>
--
--
Distributed under terms of the MIT license.
--
--[[
lua_filter@debug_filter 提供顯示 candidate 訊息和 tags
可以在 方案中 添加
name_space/output_format: # 設置 順序
- dtype # candidate type
- type # candidate.type
- start # candidate.start
- _end #
- text
- comment
- quality
- input # context.input
- ainput # active_input context.input:sub(_start +1 , _end)
- error lua component error
name_space/tags: 設置同 filter
option: _debug 開關此功能
property: :可以重設定 顯示資料和順序 以逗號分隔
<schema_name>.custom.yaml
# module_name: debug_filter name_space: debug_filter
engine/filters/@next: lua_filter@debug_filter
# item_name dtype type start _end preedit, quality input ainput comment
debug_filter/output_format: [dtype,type,start,_end,preedit,quality]
enable switch:
option_name: _debug disable / enable
candidate.comment output :
property: _debug
cand data_name: type start _end comment quality preedit , dtype
input_str: input ainput
ex:
context:set_option("_debug", true)
context:set_property("_debug", "dtype,comment,_end,start,quality")
--
--]]
local
Env
=
require
'
tools/env_api
'
local
output_fmt
=
"
dtype,type,start,_end,preedit,quality
"
local
name
=
"
_debug
"
local
List
=
require
'
tools/list
'
local
function
item_to_list
(
item
)
if
item
and
item
.
type
==
"
kList
"
then
local
cl
=
item
:
get_list
()
local
l
=
List
()
for
i
=
0
,
cl
.
size
-
1
do
l
:
push
(
cl
:
get_value_at
(
i
).
value
or
"
"
)
end
return
l
end
end
local
function
get_output_fmt
(
config
,
path
)
local
item
=
config
:
get_item
(
path
)
if
not
item
then
return
end
if
item
.
type
==
"
kList
"
then
local
l
=
item_to_list
(
item
)
return
l
and
l
:
concat
(
"
,
"
)
elseif
item
.
type
==
"
kScalar
"
then
return
item
:
get_value
().
value
:
gsub
(
"
%s
"
,
"
"
)
end
end
local
function
get_tags
(
config
,
path
)
return
Set
(
item_to_list
(
config
:
get_item
(
path
) ))
end
local
M
=
{}
function
M
.
init
(
env
)
Env
(
env
)
local
context
=
env
:
Context
()
local
config
=
env
:
Config
()
env
.
tags
=
get_tags
(
config
,
env
.
name_space
..
"
/tags
"
)
--
init option property
env
.
option
=
"
_debug
"
context
:
set_option
(
env
.
option
,
context
:
get_option
(
env
.
option
)
or
false
)
local
output_fmt
=
get_output_fmt
(
config
,
env
.
name_space
..
"
/output_format
"
)
or
output_fmt
context
:
set_property
(
env
.
option
,
output_fmt
)
end
function
M
.
fini
(
env
)
end
--
M.tags_match
local
function
tags_str
(
seg
)
local
tab
=
{}
for
k
,
_
in
next
,
seg
.
tags
do
table.insert
(
tab
,
k
)
end
return
string.format
(
"
[tags: %s]
"
,
table.concat
(
tab
,
"
"
) )
end
function
M
.
tags_match
(
seg
,
env
)
--
tags all : env.tags == nil or faile
local
context
=
env
:
Context
()
local
enable
=
context
:
get_option
(
env
.
option
)
if
enable
then
seg
.
prompt
=
seg
.
prompt
..
tags_str
(
seg
)
end
--
all: not env.tags match tags: not (seg.tags * env.tags):empty()
--
if enable then
--
if not env.tags then return true end
--
if not (seg.tags * env.tags):empty() then return true end
--
end
return
enable
and
(
not
env
.
tags
or
not
(
seg
.
tags
*
env
.
tags
):
empty
())
end
--
M.func
local
function
debug_comment
(
items
,
cand
,
tab
)
tab
=
tab
or
{ }
tab
.
ainput
=
tab
.
input
and
tab
.
input
:
sub
(
cand
.
start
+
1
,
cand
.
_end
)
or
"
"
tab
.
dtype
=
cand
:
get_dynamic_type
()
tab
.
quality
=
string.format
(
"
%6.4f
"
,
cand
.
quality
)
local
function
fn
(
elm
)
return
tab
[
elm
]
or
cand
[
elm
]
or
"
"
end
return
"
--
"
..
items
:
gsub
(
"
"
,
"
"
):
split
(
"
,
"
):
map
(
fn
):
concat
(
"
|
"
)
end
function
M
.
func
(
input
,
env
)
local
context
=
env
:
Context
()
local
items
=
context
:
get_property
(
env
.
option
)
local
ext_data
=
{
input
=
context
.
input
,
error
=
context
:
get_property
(
"
_error
"
)
}
for
cand
in
input
:
iter
()
do
if
T04
and
GD
then
GD
()
end
local
comment
=
cand
.
type
==
"
command
"
and
cand
.
comment
or
cand
.
comment
..
debug_comment
(
items
,
cand
,
ext_data
)
local
ccand
=
cand
:
get_dynamic_type
()
==
"
Shadow
"
and
cand
:
get_genuine
()
or
cand
ccand
.
comment
=
ccand
.
comment
..
comment
yield
(
cand
)
--
yield( ShadowCandidate( cand, cand.type,cand.text, comment) )
end
end
return
M
Back
|
FazBrowse Home
|
New Git URL