forked from nvimdev/lspsaga.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(nvimdev#1482): adds the ability to set a prefix to winbar
- Loading branch information
1 parent
4ce44df
commit 9f6e198
Showing
4 changed files
with
143 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
local lsp_symbols = { | ||
pending_request = false, | ||
symbols = { | ||
{ | ||
detail = '', | ||
kind = 19, | ||
name = 'command', | ||
range = { | ||
['end'] = { | ||
character = 18, | ||
line = 0, | ||
}, | ||
start = { | ||
character = 6, | ||
line = 0, | ||
}, | ||
}, | ||
selectionRange = { | ||
['end'] = { | ||
character = 13, | ||
line = 0, | ||
}, | ||
start = { | ||
character = 6, | ||
line = 0, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
function lsp_symbols.get_symbols(_bufnr) | ||
return lsp_symbols | ||
end | ||
|
||
local lspsaga_opts = { | ||
ui = { | ||
winbar_prefix = ' ', | ||
border = 'rounded', | ||
devicon = true, | ||
foldericon = true, | ||
title = true, | ||
expand = '⊞', | ||
collapse = '⊟', | ||
code_action = ' ', | ||
lines = { '┗', '┣', '┃', '━', '┏' }, | ||
kind = nil, | ||
button = { '', '' }, | ||
imp_sign = ' ', | ||
use_nerd = true, | ||
}, | ||
symbol_in_winbar = { | ||
enable = true, | ||
separator = '|', | ||
hide_keyword = false, | ||
ignore_patterns = nil, | ||
show_file = true, | ||
folder_level = 3, | ||
color_mode = true, | ||
delay = 300, | ||
}, | ||
} | ||
local lspsaga = require('lspsaga') | ||
lspsaga.setup(lspsaga_opts) | ||
|
||
describe('winbar', function() | ||
local api = vim.api | ||
local symbols__get_buf_symbols, head__get_buf_symbols | ||
local lspsaga_symbol = require('lspsaga.symbol') | ||
local lspsaga_head = require('lspsaga.symbol.head') | ||
local lspsaga_winbar = require('lspsaga.symbol.winbar') | ||
local helper = require('test.helper') | ||
|
||
before_each(function() | ||
-- | ||
local buf = api.nvim_create_buf(false, true) | ||
api.nvim_set_current_buf(buf) | ||
api.nvim_command('vsplit') | ||
api.nvim_set_current_win(api.nvim_get_current_win()) | ||
|
||
-- | ||
symbols__get_buf_symbols = lspsaga_symbol.get_buf_symbols | ||
head__get_buf_symbols = lspsaga_symbol.get_buf_symbols | ||
|
||
-- Substitui a interação real com o LSP pelo mock | ||
lspsaga_symbol.get_buf_symbols = lsp_symbols.get_symbols | ||
lspsaga_head.get_buf_symbols = lsp_symbols.get_symbols | ||
end) | ||
|
||
after_each(function() | ||
-- Restaura a função original | ||
lspsaga_symbol.get_buf_symbols = symbols__get_buf_symbols | ||
lspsaga_head.get_buf_symbols = head__get_buf_symbols | ||
end) | ||
|
||
it('should handle width limitation in winbar', function() | ||
-- Inicialize o winbar | ||
lspsaga_winbar.init_winbar(api.nvim_get_current_buf()) | ||
|
||
-- Simula uma situação onde há muitos itens na winbar | ||
-- (Adapte conforme necessário para criar uma lista longa de símbolos) | ||
local cur_win = api.nvim_get_current_win() | ||
local max_width = math.floor(api.nvim_win_get_width(cur_win) * 0.9) | ||
api.nvim_set_option_value('winbar', string.rep('Item|', max_width), { | ||
scope = 'local', | ||
win = api.nvim_get_current_win(), | ||
}) | ||
|
||
-- Define um valor para winbar grande o suficiente para estrapolar a largura da janela | ||
local winbar_value = lspsaga_winbar.get_bar() or '' | ||
|
||
-- Exemplo de verificação dos componentes do winbar | ||
local saga_prefix = helper.extract_winbar_value(winbar_value, 'Prefix') | ||
local saga_sep = helper.extract_winbar_value(winbar_value, 'SagaSep') | ||
local saga_object = helper.extract_winbar_value(winbar_value, 'SagaObject') | ||
|
||
-- Verifique se os componentes foram extraídos corretamente | ||
assert(saga_prefix, 'Prefix not found in winbar_value') | ||
assert(saga_sep, 'Separator not found in winbar_value') | ||
assert(saga_object, 'Symbol not found in winbar_value') | ||
|
||
-- Opcionalmente, você pode verificar a presença do prefixo, separador e símbolo individualmente | ||
assert(saga_prefix == ' ', 'Prefix does not match expected value') | ||
assert(saga_sep == '|', 'Separator does not match expected value') | ||
assert(saga_object == ' command', 'Symbol does not match expected value') | ||
end) | ||
end) |