Skip to content

Commit fe73e29

Browse files
committed
feat: divide dependencies into normal, build, dev sections
1 parent 2195749 commit fe73e29

File tree

7 files changed

+253
-26
lines changed

7 files changed

+253
-26
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ require('crates').setup {
228228
feature = " %s",
229229
enabled = " %s",
230230
transitive = " %s",
231+
normal_dependencies_title = " Dependencies",
232+
build_dependencies_title = " Build dependencies",
233+
dev_dependencies_title = " Dev dependencies",
231234
dependency = " %s",
232235
optional = " %s",
233236
dependency_version = " %s",
@@ -261,6 +264,9 @@ require('crates').setup {
261264
feature = "CratesNvimPopupFeature",
262265
enabled = "CratesNvimPopupEnabled",
263266
transitive = "CratesNvimPopupTransitive",
267+
normal_dependencies_title = "CratesNvimPopupNormalDependenciesTitle",
268+
build_dependencies_title = "CratesNvimPopupBuildDependenciesTitle",
269+
dev_dependencies_title = "CratesNvimPopupDevDependenciesTitle",
264270
dependency = "CratesNvimPopupDependency",
265271
optional = "CratesNvimPopupOptional",
266272
dependency_version = "CratesNvimPopupDependencyVersion",

doc/crates.txt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ For more information about individual config options see |crates-config|.
136136
feature = " %s",
137137
enabled = " %s",
138138
transitive = " %s",
139+
normal_dependencies_title = " Dependencies",
140+
build_dependencies_title = " Build dependencies",
141+
dev_dependencies_title = " Dev dependencies",
139142
dependency = " %s",
140143
optional = " %s",
141144
dependency_version = " %s",
@@ -169,6 +172,9 @@ For more information about individual config options see |crates-config|.
169172
feature = "CratesNvimPopupFeature",
170173
enabled = "CratesNvimPopupEnabled",
171174
transitive = "CratesNvimPopupTransitive",
175+
normal_dependencies_title = "CratesNvimPopupNormalDependenciesTitle",
176+
build_dependencies_title = "CratesNvimPopupBuildDependenciesTitle",
177+
dev_dependencies_title = "CratesNvimPopupDevDependenciesTitle",
172178
dependency = "CratesNvimPopupDependency",
173179
optional = "CratesNvimPopupOptional",
174180
dependency_version = "CratesNvimPopupDependencyVersion",
@@ -831,6 +837,27 @@ popup.text.transitive *crates-config-popup-text-transitive*
831837
Format string used for transitively enabled features.
832838

833839

840+
*crates-config-popup-text-normal_dependencies_title*
841+
popup.text.normal_dependencies_title
842+
Type: `string`, Default: `" Dependencies"`
843+
844+
Format string used for the title of the normal dependencies section.
845+
846+
847+
*crates-config-popup-text-build_dependencies_title*
848+
popup.text.build_dependencies_title
849+
Type: `string`, Default: `" Build dependencies"`
850+
851+
Format string used for the title of the build dependencies section.
852+
853+
854+
*crates-config-popup-text-dev_dependencies_title*
855+
popup.text.dev_dependencies_title
856+
Type: `string`, Default: `" Dev dependencies"`
857+
858+
Format string used for the title of the dev dependencies section.
859+
860+
834861
popup.text.dependency *crates-config-popup-text-dependency*
835862
Type: `string`, Default: `" %s"`
836863

@@ -1033,6 +1060,27 @@ popup.highlight.transitive *crates-config-popup-highlight-transitive*
10331060
Highlight group used for transitively enabled features inside the popup.
10341061

10351062

1063+
*crates-config-popup-highlight-normal_dependencies_title*
1064+
popup.highlight.normal_dependencies_title
1065+
Type: `string`, Default: `"CratesNvimPopupNormalDependenciesTitle"`
1066+
1067+
Highlight group used for the title of the normal dependencies section.
1068+
1069+
1070+
*crates-config-popup-highlight-build_dependencies_title*
1071+
popup.highlight.build_dependencies_title
1072+
Type: `string`, Default: `"CratesNvimPopupBuildDependenciesTitle"`
1073+
1074+
Highlight group used for the title of the build dependencies section.
1075+
1076+
1077+
*crates-config-popup-highlight-dev_dependencies_title*
1078+
popup.highlight.dev_dependencies_title
1079+
Type: `string`, Default: `"CratesNvimPopupDevDependenciesTitle"`
1080+
1081+
Highlight group used for the title of the dev dependencies section.
1082+
1083+
10361084
popup.highlight.dependency *crates-config-popup-highlight-dependency*
10371085
Type: `string`, Default: `"CratesNvimPopupDependency"`
10381086

@@ -1276,6 +1324,18 @@ CratesNvimPopupEnabled *crates-hl-CratesNvimPopupEnabled*
12761324
CratesNvimPopupTransitive *crates-hl-CratesNvimPopupTransitive*
12771325
Default: `ctermfg=4 guifg=#238bb9`
12781326

1327+
*crates-hl-CratesNvimPopupNormalDependenciesTitle*
1328+
CratesNvimPopupNormalDependenciesTitle
1329+
Default: links to |Statement|
1330+
1331+
*crates-hl-CratesNvimPopupBuildDependenciesTitle*
1332+
CratesNvimPopupBuildDependenciesTitle
1333+
Default: links to |Statement|
1334+
1335+
*crates-hl-CratesNvimPopupDevDependenciesTitle*
1336+
CratesNvimPopupDevDependenciesTitle
1337+
Default: links to |Statement|
1338+
12791339
CratesNvimPopupDependency *crates-hl-CratesNvimPopupDependency*
12801340
Default: links to |None|
12811341

lua/crates/config.lua

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ local M = {Config = {TextConfig = {}, HighlightConfig = {}, DiagnosticConfig = {
200200

201201

202202

203+
204+
205+
206+
207+
208+
203209

204210

205211

@@ -808,6 +814,27 @@ entry(schema_popup_text, "transitive", {
808814
]],
809815
})
810816

817+
entry(schema_popup_text, "normal_dependencies_title", {
818+
type = "string",
819+
default = " Dependencies",
820+
description = [[
821+
Format string used for the title of the normal dependencies section.
822+
]],
823+
})
824+
entry(schema_popup_text, "build_dependencies_title", {
825+
type = "string",
826+
default = " Build dependencies",
827+
description = [[
828+
Format string used for the title of the build dependencies section.
829+
]],
830+
})
831+
entry(schema_popup_text, "dev_dependencies_title", {
832+
type = "string",
833+
default = " Dev dependencies",
834+
description = [[
835+
Format string used for the title of the dev dependencies section.
836+
]],
837+
})
811838
entry(schema_popup_text, "dependency", {
812839
type = "string",
813840
default = " %s",
@@ -1046,6 +1073,27 @@ entry(schema_popup_hi, "transitive", {
10461073
]],
10471074
})
10481075

1076+
entry(schema_popup_hi, "normal_dependencies_title", {
1077+
type = "string",
1078+
default = "CratesNvimPopupNormalDependenciesTitle",
1079+
description = [[
1080+
Highlight group used for the title of the normal dependencies section.
1081+
]],
1082+
})
1083+
entry(schema_popup_hi, "build_dependencies_title", {
1084+
type = "string",
1085+
default = "CratesNvimPopupBuildDependenciesTitle",
1086+
description = [[
1087+
Highlight group used for the title of the build dependencies section.
1088+
]],
1089+
})
1090+
entry(schema_popup_hi, "dev_dependencies_title", {
1091+
type = "string",
1092+
default = "CratesNvimPopupDevDependenciesTitle",
1093+
description = [[
1094+
Highlight group used for the title of the dev dependencies section.
1095+
]],
1096+
})
10491097
entry(schema_popup_hi, "dependency", {
10501098
type = "string",
10511099
default = "CratesNvimPopupDependency",

lua/crates/popup/dependencies.lua

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ function M.open_deps(ctx, crate_name, version, opts)
153153

154154
local title = string.format(state.cfg.popup.text.title, crate_name .. " " .. version.num)
155155
local deps_width = 0
156-
local deps_text = {}
156+
local deps_text_index = {}
157+
local normal_deps_text = {}
158+
local build_deps_text = {}
159+
local dev_deps_text = {}
157160

158161
for _, d in ipairs(deps) do
159162
local t = {}
@@ -165,13 +168,21 @@ function M.open_deps(ctx, crate_name, version, opts)
165168
t.hl = state.cfg.popup.highlight.dependency
166169
end
167170

168-
table.insert(deps_text, { t })
171+
local line = { t }
172+
if d.kind == "normal" then
173+
table.insert(normal_deps_text, line)
174+
elseif d.kind == "build" then
175+
table.insert(build_deps_text, line)
176+
elseif d.kind == "dev" then
177+
table.insert(dev_deps_text, line)
178+
end
179+
table.insert(deps_text_index, line)
169180
deps_width = math.max(vim.fn.strdisplaywidth(t.text), deps_width)
170181
end
171182

172183
local vers_width = 0
173184
if state.cfg.popup.show_dependency_version then
174-
for i, line in ipairs(deps_text) do
185+
for i, line in ipairs(deps_text_index) do
175186
local dep_text = line[1]
176187
local diff = deps_width - vim.fn.strdisplaywidth(dep_text.text)
177188
local vers = deps[i].vers.text
@@ -187,8 +198,28 @@ function M.open_deps(ctx, crate_name, version, opts)
187198
end
188199
end
189200

201+
local deps_text = {}
202+
if #normal_deps_text > 0 then
203+
table.insert(deps_text, { { text = state.cfg.popup.text.normal_dependencies_title, hl = state.cfg.popup.highlight.normal_dependencies_title } })
204+
vim.list_extend(deps_text, normal_deps_text)
205+
end
206+
if #build_deps_text > 0 then
207+
if #deps_text > 0 then
208+
table.insert(deps_text, {})
209+
end
210+
table.insert(deps_text, { { text = state.cfg.popup.text.build_dependencies_title, hl = state.cfg.popup.highlight.build_dependencies_title } })
211+
vim.list_extend(deps_text, build_deps_text)
212+
end
213+
if #dev_deps_text > 0 then
214+
if #deps_text > 0 then
215+
table.insert(deps_text, {})
216+
end
217+
table.insert(deps_text, { { text = state.cfg.popup.text.dev_dependencies_title, hl = state.cfg.popup.highlight.dev_dependencies_title } })
218+
vim.list_extend(deps_text, dev_deps_text)
219+
end
220+
190221
local width = popup.win_width(title, deps_width + vers_width)
191-
local height = popup.win_height(deps)
222+
local height = popup.win_height(deps_text)
192223

193224
if opts.update then
194225
popup.update_win(width, height, title, deps_text, opts)

plugin/crates.vim

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,24 @@ highlight default link CratesNvimNoMatch DiagnosticVirtualTextError
66
highlight default link CratesNvimUpgrade DiagnosticVirtualTextWarn
77
highlight default link CratesNvimError DiagnosticVirtualTextError
88

9-
highlight default link CratesNvimPopupTitle Title
10-
highlight default CratesNvimPopupPillText ctermfg=15 ctermbg=242 guifg=#e0e0e0 guibg=#3a3a3a
11-
highlight default CratesNvimPopupPillBorder ctermfg=242 guifg=#3a3a3a
12-
highlight default link CratesNvimPopupDescription Comment
13-
highlight default link CratesNvimPopupLabel Identifier
14-
highlight default link CratesNvimPopupValue String
15-
highlight default link CratesNvimPopupUrl Underlined
16-
highlight default link CratesNvimPopupVersion None
17-
highlight default link CratesNvimPopupPreRelease DiagnosticVirtualTextWarn
18-
highlight default link CratesNvimPopupYanked DiagnosticVirtualTextError
19-
highlight default link CratesNvimPopupVersionDate Comment
20-
highlight default link CratesNvimPopupFeature None
21-
highlight default CratesNvimPopupEnabled ctermfg=2 guifg=#23ab49
22-
highlight default CratesNvimPopupTransitive ctermfg=4 guifg=#238bb9
23-
highlight default link CratesNvimPopupDependency None
24-
highlight default link CratesNvimPopupOptional Comment
25-
highlight default link CratesNvimPopupDependencyVersion String
26-
highlight default link CratesNvimPopupLoading Special
9+
highlight default link CratesNvimPopupTitle Title
10+
highlight default CratesNvimPopupPillText ctermfg=15 ctermbg=242 guifg=#e0e0e0 guibg=#3a3a3a
11+
highlight default CratesNvimPopupPillBorder ctermfg=242 guifg=#3a3a3a
12+
highlight default link CratesNvimPopupDescription Comment
13+
highlight default link CratesNvimPopupLabel Identifier
14+
highlight default link CratesNvimPopupValue String
15+
highlight default link CratesNvimPopupUrl Underlined
16+
highlight default link CratesNvimPopupVersion None
17+
highlight default link CratesNvimPopupPreRelease DiagnosticVirtualTextWarn
18+
highlight default link CratesNvimPopupYanked DiagnosticVirtualTextError
19+
highlight default link CratesNvimPopupVersionDate Comment
20+
highlight default link CratesNvimPopupFeature None
21+
highlight default CratesNvimPopupEnabled ctermfg=2 guifg=#23ab49
22+
highlight default CratesNvimPopupTransitive ctermfg=4 guifg=#238bb9
23+
highlight default link CratesNvimPopupNormalDependenciesTitle Statement
24+
highlight default link CratesNvimPopupBuildDependenciesTitle Statement
25+
highlight default link CratesNvimPopupDevDependenciesTitle Statement
26+
highlight default link CratesNvimPopupDependency None
27+
highlight default link CratesNvimPopupOptional Comment
28+
highlight default link CratesNvimPopupDependencyVersion String
29+
highlight default link CratesNvimPopupLoading Special

teal/crates/config.tl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ local record M
104104
enabled: string
105105
transitive: string
106106

107+
normal_dependencies_title: string
108+
build_dependencies_title: string
109+
dev_dependencies_title: string
107110
dependency: string
108111
optional: string
109112
dependency_version: string
@@ -142,6 +145,9 @@ local record M
142145
enabled: string
143146
transitive: string
144147

148+
normal_dependencies_title: string
149+
build_dependencies_title: string
150+
dev_dependencies_title: string
145151
dependency: string
146152
optional: string
147153
dependency_version: string
@@ -808,6 +814,27 @@ entry(schema_popup_text, "transitive", {
808814
]],
809815
})
810816
-- dependencies
817+
entry(schema_popup_text, "normal_dependencies_title", {
818+
type = "string",
819+
default = " Dependencies",
820+
description = [[
821+
Format string used for the title of the normal dependencies section.
822+
]],
823+
})
824+
entry(schema_popup_text, "build_dependencies_title", {
825+
type = "string",
826+
default = " Build dependencies",
827+
description = [[
828+
Format string used for the title of the build dependencies section.
829+
]],
830+
})
831+
entry(schema_popup_text, "dev_dependencies_title", {
832+
type = "string",
833+
default = " Dev dependencies",
834+
description = [[
835+
Format string used for the title of the dev dependencies section.
836+
]],
837+
})
811838
entry(schema_popup_text, "dependency", {
812839
type = "string",
813840
default = " %s",
@@ -1046,6 +1073,27 @@ entry(schema_popup_hi, "transitive", {
10461073
]],
10471074
})
10481075
-- dependencies
1076+
entry(schema_popup_hi, "normal_dependencies_title", {
1077+
type = "string",
1078+
default = "CratesNvimPopupNormalDependenciesTitle",
1079+
description = [[
1080+
Highlight group used for the title of the normal dependencies section.
1081+
]],
1082+
})
1083+
entry(schema_popup_hi, "build_dependencies_title", {
1084+
type = "string",
1085+
default = "CratesNvimPopupBuildDependenciesTitle",
1086+
description = [[
1087+
Highlight group used for the title of the build dependencies section.
1088+
]],
1089+
})
1090+
entry(schema_popup_hi, "dev_dependencies_title", {
1091+
type = "string",
1092+
default = "CratesNvimPopupDevDependenciesTitle",
1093+
description = [[
1094+
Highlight group used for the title of the dev dependencies section.
1095+
]],
1096+
})
10491097
entry(schema_popup_hi, "dependency", {
10501098
type = "string",
10511099
default = "CratesNvimPopupDependency",

0 commit comments

Comments
 (0)