Skip to content

Commit ef5b287

Browse files
committed
feat(statusline): sqls connection status
1 parent 24d0487 commit ef5b287

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ as dependencies in your package manager:
3232
- [nvim.lua](https://github.com/norcalli/nvim.lua)
3333
- [nvim-web-devicons](https://github.com/kyazdani42/nvim-web-devicons)
3434
- [fidget.nvim](https://github.com/j-hui/fidget.nvim)
35+
- [sqls.nvim](https://github.com/nanotee/sqls.nvim)
3536

3637
## Installation
3738

@@ -85,6 +86,7 @@ use({
8586
"rebelot/heirline.nvim",
8687
"kyazdani42/nvim-web-devicons",
8788
"j-hui/fidget.nvim",
89+
"nanotee/sqls.nvim",
8890
},
8991
config = function()
9092
require("arshlib.quick").autocmd({"UIEnter", "*", function()

lua/arshamiser/feliniser/init.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,25 @@ table.insert(components.active[3], {
347347
})
348348
-- }}}
349349

350+
-- SQLs Info {{{
351+
table.insert(components.active[3], {
352+
provider = "sqls_status",
353+
enabled = function()
354+
return vim.bo.filetype == "sql" and pcall(require, "sqls.commands")
355+
end,
356+
truncate_hide = true,
357+
hl = right_ribbon_hl,
358+
left_sep = {
359+
str = " ",
360+
hl = {
361+
bg = "statusline_bg",
362+
fg = "mid_bg",
363+
style = "bold",
364+
},
365+
},
366+
})
367+
-- }}}
368+
350369
-- File Icon {{{
351370
table.insert(components.active[3], {
352371
priority = 7,
@@ -725,6 +744,7 @@ require("feline").setup({ -- {{{
725744
diag_hints = util.diagnostic_hints,
726745
lsp_clients = util.lsp_client_names,
727746
fold_method = util.fold_method,
747+
sqls_status = util.sqls_status,
728748
},
729749
})
730750
-- }}}

lua/arshamiser/feliniser/util.lua

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
local nvim = require("nvim")
21
local utils = require("heirline.utils")
32

43
local M = {}
@@ -439,10 +438,35 @@ function M.diagnostic_info() --{{{
439438
return diagnostics(vim.diagnostic.severity.INFO), ""
440439
end --}}}
441440

441+
local sqls_status = {
442+
subscribed = false,
443+
connection = nil,
444+
database = "default",
445+
}
442446

447+
function M.sqls_status() --{{{
448+
local ok, events = pcall(require, "sqls.events")
449+
if not ok then
450+
return ""
451+
end
452+
if not sqls_status.subscribed then
453+
events.add_subscriber("connection_choice", function(event)
454+
local items = vim.split(event.choice, " ")
455+
sqls_status.connection = items[3]
456+
local _, _, name = event.choice:find("dbname=([^ ]+)")
457+
sqls_status.database = name or "Unknown"
458+
end)
459+
events.add_subscriber("database_choice", function(event)
460+
sqls_status.database = event.choice
461+
end)
462+
sqls_status.sqls_subscribed = true
463+
end
443464

465+
if not sqls_status.connection or not sqls_status.database then
466+
return ""
444467
end
445468

469+
return sqls_status.connection .. M.separators.database .. sqls_status.database
446470
end --}}}
447471

448472
return M

lua/arshamiser/health.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ local libs = {
1010
heirline = "rebelot/heirline.nvim",
1111
["fidget.nvim"] = "j-hui/fidget.nvim",
1212
["nvim-web-devicons"] = "kyazdani42/nvim-web-devicons",
13+
["sqls.nvim"] = "nanotee/sqls.nvim",
1314
}
1415

1516
M.check = function()

0 commit comments

Comments
 (0)