FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
flutter-tools.nvim/lua/flutter-tools/utils/init.lua at main · nvim-flutter/flutter-tools.nvim · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
nvim-flutter
/
flutter-tools.nvim
Public
Notifications
You must be signed in to change notification settings
Fork
116
Star
1.4k
Code
Issues
20
Pull requests
9
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
flutter-tools.nvim
/
lua
/
flutter-tools
/
utils
/
init.lua
Copy path
More file actions
More file actions
Latest commit
History
History
History
152 lines (135 loc) · 4.33 KB
Breadcrumbs
flutter-tools.nvim
/
lua
/
flutter-tools
/
utils
/
init.lua
Copy path
File metadata and controls
152 lines (135 loc) · 4.33 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
local
M
=
{}
local
fn
=
vim
.
fn
local
api
=
vim
.
api
local
lazy
=
require
(
"
flutter-tools.lazy
"
)
local
path
=
lazy
.
require
(
"
flutter-tools.utils.path
"
)
---
@module
"
flutter-tools.utils.path
"
---
if every item in a table is an empty value return true
function
M
.
list_is_empty
(
tbl
)
if
not
tbl
then
return
true
end
return
table.concat
(
tbl
)
==
"
"
end
function
M
.
buf_valid
(
bufnr
,
name
)
local
target
=
bufnr
or
name
if
not
target
then
return
false
end
if
bufnr
then
return
api
.
nvim_buf_is_loaded
(
bufnr
)
end
return
vim
.
fn
.
bufexists
(
target
)
>
0
and
vim
.
fn
.
buflisted
(
target
)
>
0
end
local
colorscheme_group
=
api
.
nvim_create_augroup
(
"
FlutterToolsColorscheme
"
, {
clear
=
true
})
---
Add a highlight group and an accompanying autocommand to refresh it
---
if the colorscheme changes
---
@param
name
string
---
@param
opts
table
function
M
.
highlight
(
name
,
opts
)
local
function
hl
()
api
.
nvim_set_hl
(
0
,
name
,
opts
)
end
hl
()
api
.
nvim_create_autocmd
(
"
ColorScheme
"
, {
callback
=
hl
,
group
=
colorscheme_group
})
end
---
@generic
T
,
S
---
@param
accumulator
S
---
@param
callback
fun
(
accumulator
:
S
,
item
:
T
,
index
:
number
|
string
):
S
---
@param
list
T[]
---
@return
S
function
M
.
fold
(
callback
,
list
,
accumulator
)
for
k
,
v
in
ipairs
(
list
)
do
accumulator
=
callback
(
accumulator
,
v
,
k
)
end
return
accumulator
end
---
Find an item in a list based on a compare function
---
@generic
T
---
@param
compare
fun
(
item
:
T
):
boolean
---
@param
list
T[]
---
@return
T
?
function
M
.
find
(
list
,
compare
)
for
_
,
item
in
ipairs
(
list
)
do
if
compare
(
item
)
then
return
item
end
end
end
---
Merge two table but maintain metatables
---
Priority is given to the second table
---
FIXME: this does not copy metatables
---
@param
t1
table
---
@param
t2
table
---
@param
skip
string[]
?
---
@return
table
function
M
.
merge
(
t1
,
t2
,
skip
)
for
k
,
v
in
pairs
(
t2
)
do
if
not
skip
or
not
vim
.
tbl_contains
(
skip
,
k
)
then
if
(
type
(
v
)
==
"
table
"
)
and
(
type
(
t1
[
k
]
or
false
)
==
"
table
"
)
then
M
.
merge
(
t1
[
k
],
t2
[
k
])
else
t1
[
k
]
=
v
end
end
end
return
t1
end
function
M
.
remove_newlines
(
str
)
if
not
str
or
type
(
str
)
~=
"
string
"
then
return
str
end
return
str
:
gsub
(
"
[
\n\r
]
"
,
"
"
)
end
function
M
.
executable
(
bin
)
return
fn
.
executable
(
bin
)
>
0
end
---
Get the attribute value of a specified highlight
---
@param
name
string
---
@param
attribute
string
---
@return
string
?
function
M
.
get_hl
(
name
,
attribute
)
if
api
.
nvim_get_hl
then
local
hl
=
api
.
nvim_get_hl
(
0
, {
name
=
name
})
return
hl
[
attribute
]
else
local
ok
,
hl
=
pcall
(
api
.
nvim_get_hl_by_name
,
name
,
true
)
if
not
ok
then
return
end
hl
.
foreground
=
hl
.
foreground
and
"
#
"
..
bit
.
tohex
(
hl
.
foreground
,
6
)
hl
.
background
=
hl
.
background
and
"
#
"
..
bit
.
tohex
(
hl
.
background
,
6
)
local
attr
=
({
bg
=
"
background
"
,
fg
=
"
foreground
"
})[
attribute
]
or
attribute
return
hl
[
attr
]
end
end
function
M
.
open_command
()
if
path
.
is_mac
then
return
"
open
"
, {}
end
if
path
.
is_linux
then
return
"
xdg-open
"
, {}
end
if
path
.
is_windows
then
return
"
cmd.exe
"
, {
"
/c
"
,
"
start
"
}
end
return
nil
,
nil
end
---
@param
lines
string[]
---
@return
string
function
M
.
join
(
lines
)
return
table.concat
(
lines
,
"
\n
"
)
end
---
Create an lsp handler compatible with the new handler signature
---
see: https://github.com/neovim/neovim/pull/15504/
---
@param
func
function
---
@return
function
function
M
.
lsp_handler
(
func
)
return
function
(...)
local
config_or_client_id
=
select
(
4
,
...
)
local
is_new
=
type
(
config_or_client_id
)
~=
"
number
"
if
is_new
then
func
(
...
)
else
local
err
=
select
(
1
,
...
)
local
method
=
select
(
2
,
...
)
local
result
=
select
(
3
,
...
)
local
client_id
=
select
(
4
,
...
)
local
bufnr
=
select
(
5
,
...
)
local
config
=
select
(
6
,
...
)
func
(
err
,
result
, {
method
=
method
,
client_id
=
client_id
,
bufnr
=
bufnr
},
config
)
end
end
end
---
@enum
Events
M
.
events
=
{
PROJECT_CONFIG_CHANGED
=
"
FlutterToolsProjectConfigChanged
"
,
APP_STARTED
=
"
FlutterToolsAppStarted
"
,
OUTLINE_CHANGED
=
"
FlutterToolsOutlineChanged
"
,
LSP_ANALYSIS_COMPLETED
=
"
FlutterToolsLspAnalysisCompleted
"
,
}
---
@generic
T
:
table
---
@param
event
Events
---
@param
opts
{
data
:
T
} |
nil
function
M
.
emit_event
(
event
,
opts
)
local
data
=
opts
and
opts
.
data
api
.
nvim_exec_autocmds
(
"
User
"
, {
pattern
=
event
,
data
=
data
})
end
M
.
islist
=
vim
.
islist
M
.
flatten
=
function
(
t
)
return
vim
.
iter
(
t
):
flatten
():
totable
()
end
return
M
Back
|
FazBrowse Home
|
New Git URL