diff options
| author | Jozef Grajciar <jozef.grajciar@gmail.com> | 2021-02-26 20:41:05 +0100 |
|---|---|---|
| committer | Stephan Seitz <stephan.lauf@yahoo.de> | 2021-03-04 19:58:58 +0100 |
| commit | c7422dd25787f84dd1c8d7e7947664d4ab0fe2e6 (patch) | |
| tree | 0baa41cc03abf920b7b507ab5d1484cd0ef43495 | |
| parent | Highlight Julia symbol expressions as TSSymbol (diff) | |
| download | nvim-treesitter-c7422dd25787f84dd1c8d7e7947664d4ab0fe2e6.tar nvim-treesitter-c7422dd25787f84dd1c8d7e7947664d4ab0fe2e6.tar.gz nvim-treesitter-c7422dd25787f84dd1c8d7e7947664d4ab0fe2e6.tar.bz2 nvim-treesitter-c7422dd25787f84dd1c8d7e7947664d4ab0fe2e6.tar.lz nvim-treesitter-c7422dd25787f84dd1c8d7e7947664d4ab0fe2e6.tar.xz nvim-treesitter-c7422dd25787f84dd1c8d7e7947664d4ab0fe2e6.tar.zst nvim-treesitter-c7422dd25787f84dd1c8d7e7947664d4ab0fe2e6.zip | |
Add Windows support for cl.exe
Co-authored-by: Stephan Seitz <stephan.seitz@fau.de>
| -rw-r--r-- | lua/nvim-treesitter/install.lua | 20 | ||||
| -rw-r--r-- | lua/nvim-treesitter/shell_command_selectors.lua | 45 |
2 files changed, 41 insertions, 24 deletions
diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index 2bf35e7cf..bb03b13f6 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -11,7 +11,7 @@ local shell = require'nvim-treesitter.shell_command_selectors' local M = {} local lockfile = {} -M.compilers = { vim.fn.getenv('CC'), "cc", "gcc", "clang" } +M.compilers = { vim.fn.getenv('CC'), "cc", "gcc", "clang", "cl" } local started_commands = 0 local finished_commands = 0 @@ -93,13 +93,6 @@ function M.iter_cmd(cmd_list, i, lang, success_message) end local function get_command(cmd) - local ret = '' - if cmd.opts and cmd.opts.cwd then - ret = string.format('cd %s;\n', cmd.opts.cwd) - end - - ret = string.format('%s%s ', ret, cmd.cmd) - local options = "" if cmd.opts and cmd.opts.args then for _, opt in ipairs(cmd.opts.args) do @@ -107,7 +100,11 @@ local function get_command(cmd) end end - return string.format('%s%s', ret, options) + local final = string.format('%s %s', cmd.cmd, options) + if cmd.opts and cmd.opts.cwd then + final = shell.make_directory_change_for_command(cmd.opts.cwd, final) + end + return final end local function iter_cmd_sync(cmd_list) @@ -151,7 +148,8 @@ local function run_install(cache_folder, install_folder, lang, repo, with_sync, if from_local_path then compile_location = repo.url else - compile_location = cache_folder..path_sep..(repo.location or project_name) + local repo_location = string.gsub(repo.location or project_name, '/', path_sep) + compile_location = cache_folder..path_sep..repo_location end local parser_lib_name = install_folder..path_sep..lang..".so" @@ -192,7 +190,7 @@ local function run_install(cache_folder, install_folder, lang, repo, with_sync, info = 'Compiling...', err = 'Error during compilation', opts = { - args = vim.tbl_flatten(shell.select_compiler_args(repo)), + args = vim.tbl_flatten(shell.select_compiler_args(repo, cc)), cwd = compile_location } }, diff --git a/lua/nvim-treesitter/shell_command_selectors.lua b/lua/nvim-treesitter/shell_command_selectors.lua index 65d266fb3..013169fba 100644 --- a/lua/nvim-treesitter/shell_command_selectors.lua +++ b/lua/nvim-treesitter/shell_command_selectors.lua @@ -53,20 +53,31 @@ function M.select_executable(executables) return vim.tbl_filter(function(c) return c ~= vim.NIL and fn.executable(c) == 1 end, executables)[1] end -function M.select_compiler_args(repo) - local args = { - '-o', - 'parser.so', - '-I./src', - repo.files, - '-shared', - '-Os', - '-lstdc++', - } - if fn.has('win32') == 0 then - table.insert(args, '-fPIC') +function M.select_compiler_args(repo, compiler) + if (string.match(compiler, 'cl$') or string.match(compiler, 'cl.exe$')) then + return { + '/Fe:', + 'parser.so', + '/Isrc', + repo.files, + '-Os', + '/LD', + } + else + local args = { + '-o', + 'parser.so', + '-I./src', + repo.files, + '-shared', + '-Os', + '-lstdc++', + } + if fn.has('win32') == 0 then + table.insert(args, '-fPIC') + end + return args end - return args end function M.select_install_rm_cmd(cache_folder, project_name) @@ -179,4 +190,12 @@ function M.select_download_commands(repo, project_name, cache_folder, revision) end end +function M.make_directory_change_for_command(dir, command) + if fn.has('win32') == 1 then + return string.format("pushd %s & %s & popd", dir, command) + else + return string.format("cd %s;\n %s", dir, command) + end +end + return M |
