aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshadmansaleh <shadmansaleh3@gmail.com>2021-06-02 09:32:37 +0600
committershadmansaleh <shadmansaleh3@gmail.com>2021-06-11 01:01:02 +0600
commit1e6c02510afd79659519f2a69075b36784134322 (patch)
tree7fbaef25232965a5a9aa074c730ae71f981e6c74
parent687eb0b39f3bcad9566198b4c60bbd2755032991 (diff)
downloadrneovim-1e6c02510afd79659519f2a69075b36784134322.tar.gz
rneovim-1e6c02510afd79659519f2a69075b36784134322.tar.bz2
rneovim-1e6c02510afd79659519f2a69075b36784134322.zip
feat(runtime): Allow lua to be used in colorschemes
* tests(runtime): move runtime/plugin tests to functional/lua/runtime_spec
-rw-r--r--runtime/doc/syntax.txt3
-rw-r--r--src/nvim/syntax.c4
-rw-r--r--test/functional/core/startup_spec.lua48
-rw-r--r--test/functional/lua/runtime_spec.lua89
4 files changed, 95 insertions, 49 deletions
diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt
index b159f655fa..bf649b5940 100644
--- a/runtime/doc/syntax.txt
+++ b/runtime/doc/syntax.txt
@@ -4749,8 +4749,9 @@ in their own color.
feature it will output "unknown".
:colo[rscheme] {name} Load color scheme {name}. This searches 'runtimepath'
- for the file "colors/{name}.vim". The first one that
+ for the file "colors/{name}.(vim|lua)". The first one that
is found is loaded.
+ Note: "colors/{name}.vim" is tried first.
Also searches all plugins in 'packpath', first below
"start" and then under "opt".
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index ed886ab7f9..ce81f26d38 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -6438,6 +6438,10 @@ int load_colors(char_u *name)
apply_autocmds(EVENT_COLORSCHEMEPRE, name, curbuf->b_fname, false, curbuf);
snprintf((char *)buf, buflen, "colors/%s.vim", name);
retval = source_runtime(buf, DIP_START + DIP_OPT);
+ if (retval == FAIL) {
+ snprintf((char *)buf, buflen, "colors/%s.lua", name);
+ retval = source_runtime(buf, DIP_START + DIP_OPT);
+ }
xfree(buf);
apply_autocmds(EVENT_COLORSCHEME, name, curbuf->b_fname, FALSE, curbuf);
diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua
index 258fea85e4..d5f03db03a 100644
--- a/test/functional/core/startup_spec.lua
+++ b/test/functional/core/startup_spec.lua
@@ -11,7 +11,6 @@ local exec_lua = helpers.exec_lua
local feed = helpers.feed
local funcs = helpers.funcs
local mkdir = helpers.mkdir
-local mkdir_p = helpers.mkdir_p
local nvim_prog = helpers.nvim_prog
local nvim_set = helpers.nvim_set
local read_file = helpers.read_file
@@ -495,53 +494,6 @@ describe('user config init', function()
end)
end)
-describe('runtime/plugin', function()
- local xhome = 'Xhome'
- local pathsep = helpers.get_pathsep()
- local xconfig = xhome .. pathsep .. 'Xconfig'
-
- before_each(function()
- mkdir_p(xconfig .. pathsep .. 'nvim')
- end)
-
- after_each(function()
- rmdir(xhome)
- end)
-
- it('loads plugin/*.lua from XDG config home', function()
- local plugin_folder_path = table.concat({xconfig, 'nvim', 'plugin'}, pathsep)
- local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'}, pathsep)
- mkdir_p(plugin_folder_path)
- write_file(plugin_file_path, [[
- vim.g.lua_plugin = 1
- ]])
-
- clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig }}
-
- eq(1, eval('g:lua_plugin'))
- rmdir(plugin_folder_path)
- end)
-
-
- it('loads plugin/*.lua from start plugins', function()
- local plugin_path = table.concat({xconfig, 'nvim', 'pack', 'catagory',
- 'start', 'test_plugin'}, pathsep)
- local plugin_folder_path = table.concat({plugin_path, 'plugin'}, pathsep)
- local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'},
- pathsep)
- mkdir_p(plugin_folder_path)
- write_file(plugin_file_path, [[
- vim.g.lua_plugin = 2
- ]])
-
- clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig }}
-
- eq(2, eval('g:lua_plugin'))
- rmdir(plugin_path)
- end)
-
-end)
-
describe('user session', function()
local xhome = 'Xhome'
local pathsep = helpers.get_pathsep()
diff --git a/test/functional/lua/runtime_spec.lua b/test/functional/lua/runtime_spec.lua
new file mode 100644
index 0000000000..a37570e4a4
--- /dev/null
+++ b/test/functional/lua/runtime_spec.lua
@@ -0,0 +1,89 @@
+local helpers = require('test.functional.helpers')(after_each)
+
+local clear = helpers.clear
+local eq = helpers.eq
+local eval = helpers.eval
+local exec = helpers.exec
+local mkdir_p = helpers.mkdir_p
+local rmdir = helpers.rmdir
+local write_file = helpers.write_file
+
+describe('runtime:', function()
+ local xhome = 'Xhome'
+ local pathsep = helpers.get_pathsep()
+ local xconfig = xhome .. pathsep .. 'Xconfig'
+
+ before_each(function()
+ clear()
+ mkdir_p(xconfig .. pathsep .. 'nvim')
+ end)
+
+ after_each(function()
+ rmdir(xhome)
+ end)
+
+ describe('plugin', function()
+ it('loads plugin/*.lua from XDG config home', function()
+ local plugin_folder_path = table.concat({xconfig, 'nvim', 'plugin'}, pathsep)
+ local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'}, pathsep)
+ mkdir_p(plugin_folder_path)
+ write_file(plugin_file_path, [[ vim.g.lua_plugin = 1 ]])
+
+ clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig }}
+
+ eq(1, eval('g:lua_plugin'))
+ rmdir(plugin_folder_path)
+ end)
+
+
+ it('loads plugin/*.lua from start plugins', function()
+ local plugin_path = table.concat({xconfig, 'nvim', 'pack', 'catagory',
+ 'start', 'test_plugin'}, pathsep)
+ local plugin_folder_path = table.concat({plugin_path, 'plugin'}, pathsep)
+ local plugin_file_path = table.concat({plugin_folder_path, 'plugin.lua'},
+ pathsep)
+ mkdir_p(plugin_folder_path)
+ write_file(plugin_file_path, [[vim.g.lua_plugin = 2]])
+
+ clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig }}
+
+ eq(2, eval('g:lua_plugin'))
+ rmdir(plugin_path)
+ end)
+ end)
+
+ describe('colors', function()
+ it('loads lua colorscheme', function()
+ local colorscheme_folder = table.concat({xconfig, 'nvim', 'colors'},
+ pathsep)
+ local colorscheme_file = table.concat({colorscheme_folder, 'new_colorscheme.lua'},
+ pathsep)
+ mkdir_p(colorscheme_folder)
+ write_file(colorscheme_file, [[vim.g.lua_colorscheme = 1]])
+
+ clear{ args_rm={'-' }, env={ XDG_CONFIG_HOME=xconfig }}
+ exec('colorscheme new_colorscheme')
+
+ eq(1, eval('g:lua_colorscheme'))
+ rmdir(colorscheme_folder)
+ end)
+
+ it('loads vim colorscheme when both lua and vim version exist', function()
+ local colorscheme_folder = table.concat({xconfig, 'nvim', 'colors'},
+ pathsep)
+ local colorscheme_file = table.concat({colorscheme_folder, 'new_colorscheme'},
+ pathsep)
+ mkdir_p(colorscheme_folder)
+ write_file(colorscheme_file..'.vim', [[let g:colorscheme = 'vim']])
+ write_file(colorscheme_file..'.lua', [[vim.g.colorscheme = 'lua']])
+
+ clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig }}
+ exec('colorscheme new_colorscheme')
+
+ eq('vim', eval('g:colorscheme'))
+ rmdir(colorscheme_folder)
+ end)
+ end)
+
+end)
+