diff options
| author | William Boman <william@redwill.se> | 2021-10-16 23:49:17 +0200 |
|---|---|---|
| committer | William Boman <william@redwill.se> | 2021-10-16 23:49:42 +0200 |
| commit | 116b47e9301ead9638aa6d417984f76ea6baa1ab (patch) | |
| tree | 4ca039158dc85b39f92f1b9373afc8234fdc8279 /lua | |
| parent | Fix typo in neovim/nvim-lspconfig repo name (#161) (diff) | |
| download | mason-116b47e9301ead9638aa6d417984f76ea6baa1ab.tar mason-116b47e9301ead9638aa6d417984f76ea6baa1ab.tar.gz mason-116b47e9301ead9638aa6d417984f76ea6baa1ab.tar.bz2 mason-116b47e9301ead9638aa6d417984f76ea6baa1ab.tar.lz mason-116b47e9301ead9638aa6d417984f76ea6baa1ab.tar.xz mason-116b47e9301ead9638aa6d417984f76ea6baa1ab.tar.zst mason-116b47e9301ead9638aa6d417984f76ea6baa1ab.zip | |
installers/npm: don't read version from context on npm.install()
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-lsp-installer/installers/npm.lua | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/lua/nvim-lsp-installer/installers/npm.lua b/lua/nvim-lsp-installer/installers/npm.lua index 88e8fafc..b165d5f1 100644 --- a/lua/nvim-lsp-installer/installers/npm.lua +++ b/lua/nvim-lsp-installer/installers/npm.lua @@ -23,33 +23,35 @@ local function ensure_npm(installer) } end -function M.packages(packages) - return ensure_npm(function(server, callback, context) - local pkgs = Data.list_copy(packages or {}) - local c = process.chain { - cwd = server.root_dir, - stdio_sink = context.stdio_sink, - } - -- stylua: ignore start - if not (fs.dir_exists(path.concat { server.root_dir, "node_modules" }) or - fs.file_exists(path.concat { server.root_dir, "package.json" })) - then - c.run(npm, { "init", "--yes", "--scope=lsp-installer" }) - end +local function create_installer(read_version_from_context) + return function(packages) + return ensure_npm(function(server, callback, context) + local pkgs = Data.list_copy(packages or {}) + local c = process.chain { + cwd = server.root_dir, + stdio_sink = context.stdio_sink, + } + -- stylua: ignore start + if not (fs.dir_exists(path.concat { server.root_dir, "node_modules" }) or + fs.file_exists(path.concat { server.root_dir, "package.json" })) + then + c.run(npm, { "init", "--yes", "--scope=lsp-installer" }) + end - if context.requested_server_version and #pkgs > 0 then - -- The "head" package is the recipient for the requested version. It's.. by design... don't ask. - pkgs[1] = ("%s@%s"):format(pkgs[1], context.requested_server_version) - end + if read_version_from_context and context.requested_server_version and #pkgs > 0 then + -- The "head" package is the recipient for the requested version. It's.. by design... don't ask. + pkgs[1] = ("%s@%s"):format(pkgs[1], context.requested_server_version) + end - -- stylua: ignore end - c.run(npm, vim.list_extend({ "install" }, pkgs)) - c.spawn(callback) - end) + -- stylua: ignore end + c.run(npm, vim.list_extend({ "install" }, pkgs)) + c.spawn(callback) + end) + end end --- @alias for packages -M.install = M.packages +M.packages = create_installer(true) +M.install = create_installer(false) function M.exec(executable, args) return function(server, callback, context) |
