Skip to content

Commit 1a55d17

Browse files
committed
fix: display/column option not applicable issue
1 parent 4dc39fa commit 1a55d17

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

lua/sqlflick/init.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ end
174174

175175
-- Setup function that will be called by users
176176
function M.setup(opts)
177-
-- Set up configuration
178177
config.setup(opts)
179178

180179
-- Check and install dependencies
@@ -185,12 +184,12 @@ function M.setup(opts)
185184
end
186185
end
187186

188-
-- Ensure backend is installed
189187
install.ensure_installed()
190188

191-
-- Set up custom highlights
192189
highlights.setup()
193190

191+
query.setup(config.opts)
192+
194193
-- Create display commands
195194
vim.api.nvim_create_user_command("SQLFlickDebug", function()
196195
print("SQLFlick Debug Info:")

lua/sqlflick/query.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ local M = {}
33
-- Store table data for manipulation (word wrapping, etc.)
44
M.table_data = nil
55

6-
local config = require("sqlflick.config")
6+
M.MAX_COLUMN_WIDTH = 200 -- Maximum width for any column
7+
M.MIN_COLUMN_WIDTH = 0 -- Minimum width for readability
78

8-
-- Configuration
9-
local MAX_COLUMN_WIDTH = math.max(config.opts.display.column.max_width, 200) -- Maximum width for any column
10-
local MIN_COLUMN_WIDTH = math.min(config.opts.display.column.min_width, 0) -- Minimum width for readability
9+
function M.setup(opts)
10+
M.MAX_COLUMN_WIDTH = math.min(opts.display.column.max_width, M.MAX_COLUMN_WIDTH)
11+
M.MIN_COLUMN_WIDTH = math.max(opts.display.column.min_width, M.MIN_COLUMN_WIDTH)
12+
end
1113

1214
-- Helper function to truncate text and add ellipsis if needed
1315
local function truncate_text(text, max_width)
@@ -108,7 +110,7 @@ function M.format_query_results(result)
108110
end
109111

110112
local ideal_width = math.max(header_width, max_data_width)
111-
col_widths[i] = math.max(MIN_COLUMN_WIDTH, math.min(MAX_COLUMN_WIDTH, ideal_width))
113+
col_widths[i] = math.max(M.MIN_COLUMN_WIDTH, math.min(M.MAX_COLUMN_WIDTH, ideal_width))
112114
end
113115

114116
for i, width in ipairs(col_widths) do
@@ -315,7 +317,7 @@ function M.format_query_results_with_wrapping(result)
315317
end
316318

317319
local ideal_width = math.max(header_width, max_data_width)
318-
col_widths[i] = math.max(MIN_COLUMN_WIDTH, math.min(MAX_COLUMN_WIDTH, ideal_width)) + 2
320+
col_widths[i] = math.max(M.MIN_COLUMN_WIDTH, math.min(M.MAX_COLUMN_WIDTH, ideal_width)) + 2
319321
end
320322

321323
-- Format header and borders

test/sql/mysql.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ WHERE USERNAME LIKE '%long%'
7373
OR PASSWORD LIKE '%long%'
7474
ORDER BY CREATED_ON DESC;
7575

76+
SELECT USERNAME as "Very Long Column Header That Should Test Word Wrap",
77+
PASSWORD as "Another Extremely Long Column Header For Testing Display",
78+
EMAIL as "Yet Another Long Column Header To Verify Word Wrap Functionality",
79+
CREATED_ON as "Creation Timestamp With Long Header",
80+
LAST_LOGIN as "Last Login Time With Extended Header Name"
81+
FROM ACCOUNT_TEST
82+
ORDER BY CREATED_ON DESC;
83+
7684
-- Create table with varied column widths for word wrap testing
7785
DROP TABLE IF EXISTS WORDWRAP_TEST;
7886
CREATE TABLE WORDWRAP_TEST (

test/test.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ sqlflick.setup({
9494

9595
display = {
9696
column = {
97-
max_width = 200,
97+
-- max_width = 10,
9898
},
9999
},
100100

0 commit comments

Comments
 (0)