mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
feat(ui): allow to set the highlight namespace per window
- reimplement 'winhl' in terms of highlight namespaces - check for EOF in screen tests (to indicate a likely crash)
This commit is contained in:
@@ -243,7 +243,7 @@ describe("API: set highlight", function()
|
||||
|
||||
local function get_ns()
|
||||
local ns = meths.create_namespace('Test_set_hl')
|
||||
meths._set_hl_ns(ns)
|
||||
meths.set_hl_ns(ns)
|
||||
return ns
|
||||
end
|
||||
|
||||
|
||||
@@ -244,10 +244,12 @@ function module.run_session(lsession, request_cb, notification_cb, setup_cb, tim
|
||||
last_error = nil
|
||||
error(err)
|
||||
end
|
||||
|
||||
return session.eof_err
|
||||
end
|
||||
|
||||
function module.run(request_cb, notification_cb, setup_cb, timeout)
|
||||
module.run_session(session, request_cb, notification_cb, setup_cb, timeout)
|
||||
return module.run_session(session, request_cb, notification_cb, setup_cb, timeout)
|
||||
end
|
||||
|
||||
function module.stop()
|
||||
|
||||
@@ -193,7 +193,7 @@ describe('decorations providers', function()
|
||||
|
|
||||
]]}
|
||||
|
||||
meths._set_hl_ns(ns1)
|
||||
meths.set_hl_ns(ns1)
|
||||
screen:expect{grid=[[
|
||||
{10: 1 }{11:// just to see if there was an accid}|
|
||||
{10: }{11:ent} |
|
||||
@@ -219,7 +219,7 @@ describe('decorations providers', function()
|
||||
local ns2 = a.nvim_create_namespace 'ns2'
|
||||
a.nvim_set_decoration_provider (ns2, {
|
||||
on_win = function (_, win, buf)
|
||||
a.nvim__set_hl_ns(win == thewin and _G.ns1 or ns2)
|
||||
a.nvim_set_hl_ns_fast(win == thewin and _G.ns1 or ns2)
|
||||
end;
|
||||
})
|
||||
]]
|
||||
@@ -266,7 +266,7 @@ describe('decorations providers', function()
|
||||
]]}
|
||||
|
||||
meths.set_hl(ns1, 'LinkGroup', {fg = 'Blue'})
|
||||
meths._set_hl_ns(ns1)
|
||||
meths.set_hl_ns(ns1)
|
||||
|
||||
screen:expect{grid=[[
|
||||
// just to see if there was an accident |
|
||||
@@ -302,7 +302,7 @@ describe('decorations providers', function()
|
||||
]]}
|
||||
|
||||
meths.set_hl(ns1, 'LinkGroup', {fg = 'Blue', default=true})
|
||||
meths._set_hl_ns(ns1)
|
||||
meths.set_hl_ns(ns1)
|
||||
feed 'k'
|
||||
|
||||
screen:expect{grid=[[
|
||||
|
||||
@@ -3,9 +3,10 @@ local Screen = require('test.functional.ui.screen')
|
||||
local os = require('os')
|
||||
local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert
|
||||
local command, exec = helpers.command, helpers.exec
|
||||
local eval, exc_exec = helpers.eval, helpers.exc_exec
|
||||
local eval = helpers.eval
|
||||
local feed_command, eq = helpers.feed_command, helpers.eq
|
||||
local curbufmeths = helpers.curbufmeths
|
||||
local meths = helpers.meths
|
||||
|
||||
describe('colorscheme compatibility', function()
|
||||
before_each(function()
|
||||
@@ -1787,6 +1788,7 @@ describe("'winhighlight' highlight", function()
|
||||
[26] = {background = Screen.colors.Red},
|
||||
[27] = {background = Screen.colors.DarkBlue, bold = true, foreground = Screen.colors.Green1},
|
||||
[28] = {bold = true, foreground = Screen.colors.Brown},
|
||||
[29] = {foreground = Screen.colors.Blue1, background = Screen.colors.Red, bold = true};
|
||||
})
|
||||
command("hi Background1 guibg=DarkBlue")
|
||||
command("hi Background2 guibg=DarkGreen")
|
||||
@@ -1820,7 +1822,7 @@ describe("'winhighlight' highlight", function()
|
||||
]])
|
||||
end)
|
||||
|
||||
it('handles invalid values', function()
|
||||
it('handles undefined groups', function()
|
||||
command("set winhl=Normal:Background1")
|
||||
screen:expect([[
|
||||
{1:^ }|
|
||||
@@ -1833,19 +1835,44 @@ describe("'winhighlight' highlight", function()
|
||||
|
|
||||
]])
|
||||
|
||||
eq('Vim(set):E474: Invalid argument: winhl=xxx:yyy',
|
||||
exc_exec("set winhl=xxx:yyy"))
|
||||
eq('Normal:Background1', eval('&winhl'))
|
||||
command("set winhl=xxx:yyy")
|
||||
eq('xxx:yyy', eval('&winhl'))
|
||||
screen:expect{grid=[[
|
||||
{1:^ }|
|
||||
{2:~ }|
|
||||
{2:~ }|
|
||||
{2:~ }|
|
||||
{2:~ }|
|
||||
{2:~ }|
|
||||
{2:~ }|
|
||||
^ |
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
|
|
||||
]], unchanged=true}
|
||||
]]}
|
||||
end)
|
||||
|
||||
it('can be changed to define different groups', function()
|
||||
command("set winhl=EndOfBuffer:Background1")
|
||||
screen:expect{grid=[[
|
||||
^ |
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
|
|
||||
]]}
|
||||
|
||||
command("set winhl=Normal:ErrorMsg")
|
||||
screen:expect{grid=[[
|
||||
{15:^ }|
|
||||
{29:~ }|
|
||||
{29:~ }|
|
||||
{29:~ }|
|
||||
{29:~ }|
|
||||
{29:~ }|
|
||||
{29:~ }|
|
||||
|
|
||||
]]}
|
||||
end)
|
||||
|
||||
it('works local to the window', function()
|
||||
@@ -2270,4 +2297,145 @@ describe("'winhighlight' highlight", function()
|
||||
|
|
||||
]])
|
||||
end)
|
||||
|
||||
|
||||
it("can override syntax groups", function()
|
||||
command('syntax on')
|
||||
command('syntax keyword Foobar foobar')
|
||||
command('syntax keyword Article the')
|
||||
command('hi Foobar guibg=#FF0000')
|
||||
command('hi Article guifg=#00FF00 gui=bold')
|
||||
insert('the foobar was foobar')
|
||||
screen:expect([[
|
||||
{25:the} {26:foobar} was {26:fooba}|
|
||||
{26:^r} |
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
|
|
||||
]])
|
||||
|
||||
command('split')
|
||||
command('set winhl=Foobar:Background1,Article:ErrorMsg')
|
||||
screen:expect{grid=[[
|
||||
{15:the} {1:foobar} was {1:fooba}|
|
||||
{1:^r} |
|
||||
{0:~ }|
|
||||
{3:[No Name] [+] }|
|
||||
{25:the} {26:foobar} was {26:fooba}|
|
||||
{26:r} |
|
||||
{4:[No Name] [+] }|
|
||||
|
|
||||
]]}
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('highlight namespaces', function()
|
||||
local screen
|
||||
local ns1, ns2
|
||||
|
||||
before_each(function()
|
||||
clear()
|
||||
screen = Screen.new(25,10)
|
||||
screen:attach()
|
||||
screen:set_default_attr_ids {
|
||||
[1] = {foreground = Screen.colors.Blue, bold = true};
|
||||
[2] = {background = Screen.colors.DarkGrey};
|
||||
[3] = {italic = true, foreground = Screen.colors.DarkCyan, background = Screen.colors.DarkOrange4};
|
||||
[4] = {background = Screen.colors.Magenta4};
|
||||
[5] = {background = Screen.colors.Magenta4, foreground = Screen.colors.Crimson};
|
||||
[6] = {bold = true, reverse = true};
|
||||
[7] = {reverse = true};
|
||||
}
|
||||
|
||||
ns1 = meths.create_namespace 'grungy'
|
||||
ns2 = meths.create_namespace 'ultrared'
|
||||
|
||||
meths.set_hl(ns1, 'Normal', {bg='DarkGrey'})
|
||||
meths.set_hl(ns1, 'NonText', {bg='DarkOrange4', fg='DarkCyan', italic=true})
|
||||
meths.set_hl(ns2, 'Normal', {bg='DarkMagenta'})
|
||||
meths.set_hl(ns2, 'NonText', {fg='Crimson'})
|
||||
end)
|
||||
|
||||
it('can be used globally', function()
|
||||
screen:expect{grid=[[
|
||||
^ |
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
|
|
||||
]]}
|
||||
|
||||
meths.set_hl_ns(ns1)
|
||||
screen:expect{grid=[[
|
||||
{2:^ }|
|
||||
{3:~ }|
|
||||
{3:~ }|
|
||||
{3:~ }|
|
||||
{3:~ }|
|
||||
{3:~ }|
|
||||
{3:~ }|
|
||||
{3:~ }|
|
||||
{3:~ }|
|
||||
|
|
||||
]]}
|
||||
|
||||
meths.set_hl_ns(ns2)
|
||||
screen:expect{grid=[[
|
||||
{4:^ }|
|
||||
{5:~ }|
|
||||
{5:~ }|
|
||||
{5:~ }|
|
||||
{5:~ }|
|
||||
{5:~ }|
|
||||
{5:~ }|
|
||||
{5:~ }|
|
||||
{5:~ }|
|
||||
|
|
||||
]]}
|
||||
|
||||
meths.set_hl_ns(0)
|
||||
screen:expect{grid=[[
|
||||
^ |
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
|
|
||||
]]}
|
||||
end)
|
||||
|
||||
it('can be used per window', function()
|
||||
local win1 = meths.get_current_win()
|
||||
command 'split'
|
||||
local win2 = meths.get_current_win()
|
||||
command 'split'
|
||||
|
||||
meths.win_set_hl_ns(win1, ns1)
|
||||
meths.win_set_hl_ns(win2, ns2)
|
||||
|
||||
screen:expect{grid=[[
|
||||
^ |
|
||||
{1:~ }|
|
||||
{6:[No Name] }|
|
||||
{4: }|
|
||||
{5:~ }|
|
||||
{7:[No Name] }|
|
||||
{2: }|
|
||||
{3:~ }|
|
||||
{7:[No Name] }|
|
||||
|
|
||||
]]}
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -119,13 +119,15 @@ describe('ext_hlstate detailed highlights', function()
|
||||
[3] = {{bold = true, reverse = true}, {{hi_name = "StatusLine", ui_name = "StatusLine", kind = "ui"}}},
|
||||
[4] = {{reverse = true}, {{hi_name = "StatusLineNC", ui_name = "StatusLineNC", kind = "ui"}}},
|
||||
[5] = {{background = Screen.colors.Red, foreground = Screen.colors.Grey100}, {{hi_name = "ErrorMsg", ui_name = "LineNr", kind = "ui"}}},
|
||||
[6] = {{bold = true, reverse = true}, {{hi_name = "MsgSeparator", ui_name = "Normal", kind = "ui"}}},
|
||||
[6] = {{bold = true, reverse = true}, {{hi_name = "Normal", ui_name = "Normal", kind = "ui"}}},
|
||||
[7] = {{foreground = Screen.colors.Brown, bold = true, reverse = true}, {6, 1}},
|
||||
[8] = {{foreground = Screen.colors.Blue1, bold = true, reverse = true}, {6, 2}},
|
||||
[9] = {{bold = true, foreground = Screen.colors.Brown}, {{hi_name = "Statement", ui_name = "NormalNC", kind = "ui"}}},
|
||||
[8] = {{foreground = Screen.colors.Blue1, bold = true, reverse = true}, {6, 14}},
|
||||
[9] = {{bold = true, foreground = Screen.colors.Brown}, {{hi_name = "NormalNC", ui_name = "NormalNC", kind = "ui"}}},
|
||||
[10] = {{bold = true, foreground = Screen.colors.Brown}, {9, 1}},
|
||||
[11] = {{bold = true, foreground = Screen.colors.Blue1}, {9, 2}},
|
||||
[11] = {{bold = true, foreground = Screen.colors.Blue1}, {9, 14}},
|
||||
[12] = {{}, {{hi_name = "MsgArea", ui_name = "MsgArea", kind = "ui"}}},
|
||||
[13] = {{background = Screen.colors.Red1, foreground = Screen.colors.Gray100}, {{ui_name = "LineNr", kind = "ui", hi_name = "LineNr"}}};
|
||||
[14] = {{bold = true, foreground = Screen.colors.Blue}, {{ui_name = "EndOfBuffer", kind = "ui", hi_name = "EndOfBuffer"}}};
|
||||
})
|
||||
|
||||
command("set number")
|
||||
@@ -143,16 +145,16 @@ describe('ext_hlstate detailed highlights', function()
|
||||
]])
|
||||
|
||||
command("set winhl=LineNr:ErrorMsg")
|
||||
screen:expect([[
|
||||
{5: 1 }^ |
|
||||
{2:~ }|
|
||||
{2:~ }|
|
||||
screen:expect{grid=[[
|
||||
{13: 1 }^ |
|
||||
{14:~ }|
|
||||
{14:~ }|
|
||||
{3:[No Name] }|
|
||||
{1: 1 } |
|
||||
{2:~ }|
|
||||
{4:[No Name] }|
|
||||
{12: }|
|
||||
]])
|
||||
]]}
|
||||
|
||||
command("set winhl=Normal:MsgSeparator,NormalNC:Statement")
|
||||
screen:expect([[
|
||||
|
||||
@@ -546,7 +546,7 @@ function Screen:_wait(check, flags)
|
||||
|
||||
return true
|
||||
end
|
||||
run_session(self._session, flags.request_cb, notification_cb, nil, minimal_timeout)
|
||||
local eof = run_session(self._session, flags.request_cb, notification_cb, nil, minimal_timeout)
|
||||
if not did_flush then
|
||||
err = "no flush received"
|
||||
elseif not checked then
|
||||
@@ -557,9 +557,9 @@ function Screen:_wait(check, flags)
|
||||
end
|
||||
end
|
||||
|
||||
if not success_seen then
|
||||
if not success_seen and not eof then
|
||||
did_miminal_timeout = true
|
||||
run_session(self._session, flags.request_cb, notification_cb, nil, timeout-minimal_timeout)
|
||||
eof = run_session(self._session, flags.request_cb, notification_cb, nil, timeout-minimal_timeout)
|
||||
end
|
||||
|
||||
local did_warn = false
|
||||
@@ -600,8 +600,10 @@ between asynchronous (feed(), nvim_input()) and synchronous API calls.
|
||||
|
||||
|
||||
if err then
|
||||
if eof then err = err..'\n\n'..eof[2] end
|
||||
busted.fail(err, 3)
|
||||
elseif did_warn then
|
||||
if eof then print(eof[2]) end
|
||||
local tb = debug.traceback()
|
||||
local index = string.find(tb, '\n%s*%[C]')
|
||||
print(string.sub(tb,1,index))
|
||||
|
||||
Reference in New Issue
Block a user