diff options
Diffstat (limited to '.config/coc/extensions/node_modules/coc-go/lib/commands.js')
| -rw-r--r-- | .config/coc/extensions/node_modules/coc-go/lib/commands.js | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/.config/coc/extensions/node_modules/coc-go/lib/commands.js b/.config/coc/extensions/node_modules/coc-go/lib/commands.js new file mode 100644 index 0000000..f77d866 --- /dev/null +++ b/.config/coc/extensions/node_modules/coc-go/lib/commands.js @@ -0,0 +1,125 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.installTools = exports.installImpl = exports.installGoplay = exports.installGotests = exports.installGomodifytags = exports.checkGopls = exports.installGopls = exports.version = void 0; +const tslib_1 = require("tslib"); +const path_1 = tslib_1.__importDefault(require("path")); +const fs_1 = tslib_1.__importDefault(require("fs")); +const coc_nvim_1 = require("coc.nvim"); +const tools_1 = require("./utils/tools"); +const checktag_1 = tslib_1.__importDefault(require("./utils/checktag")); +const ui_1 = require("./utils/ui"); +const config_1 = require("./utils/config"); +const binaries_1 = require("./binaries"); +const versions_1 = require("./utils/versions"); +async function version() { + const v1 = await pkgVersion(); + const v2 = await goplsVersion() || 'unknown'; + coc_nvim_1.window.showMessage(`Version: coc-go ${v1}; gopls ${v2}`, 'more'); +} +exports.version = version; +async function installGopls(client) { + await (0, tools_1.installGoBin)(binaries_1.GOPLS, true, goplsVersion); + if (client.needsStop()) { + await client.stop(); + client.restart(); + } +} +exports.installGopls = installGopls; +const checkInterval = 24 * 60 * 60 * 1000; +async function shouldCheckGopls() { + const now = new Date().getTime(); + const last = await (0, config_1.getState)('gopls:last-check'); + if (last - (now - checkInterval) < 0) { + await (0, config_1.setState)('gopls:last-check', new Date().getTime()); + return true; + } + return false; +} +async function checkGopls(client, mode) { + try { + if (!(await shouldCheckGopls())) { + return; + } + let install = false; + await (0, ui_1.withProgress)('Checking for new gopls version', async () => { + const [current, latest] = await Promise.all([ + goplsVersion(), + (0, checktag_1.default)("golang/tools", /^gopls\//), + ]); + if (!(0, versions_1.isValidVersion)(current) || !(0, versions_1.isValidVersion)(latest)) { + coc_nvim_1.window.showMessage('checking for a new gopls version failed', 'warning'); + return; + } + switch ((0, versions_1.compareVersions)(latest, current)) { + case 0: + coc_nvim_1.window.showMessage(`[gopls] up-to-date: ${current}`, 'more'); + break; + case 1: + switch (mode) { + case 'install': + install = true; + break; + case 'ask': + install = await coc_nvim_1.window.showPrompt(`[gopls] Install update? ${current} => ${latest}`); + break; + case 'inform': + coc_nvim_1.window.showMessage(`[gopls] update available: ${current} => ${latest}`); + break; + } + break; + case -1: + coc_nvim_1.window.showMessage(`[gopls] current: ${current} | latest: ${latest}`, 'more'); + break; + } + }); + if (install) { + await installGopls(client); + } + } + catch (e) { + coc_nvim_1.window.showMessage(e.toString(), 'error'); + } +} +exports.checkGopls = checkGopls; +async function pkgVersion() { + try { + const pkgPath = path_1.default.resolve(__dirname, '..', 'package.json'); + const pkgContent = await fs_1.default.promises.readFile(pkgPath, 'utf8'); + return JSON.parse(pkgContent).version; + } + catch (err) { + console.error(err); + } + return ''; +} +async function goplsVersion() { + const [, versionOut] = await (0, tools_1.runGoTool)("gopls", ["version"]); + const m = versionOut.trim().match(/\s{4}golang\.org\/x\/tools\/gopls@(v?\d+\.\d+\.\d+) .*/); + if (m && (0, versions_1.isValidVersion)(m[1])) { + return m[1].replace(/^v/, ''); + } + return ''; +} +async function installGomodifytags() { + await (0, tools_1.installGoBin)(binaries_1.GOMODIFYTAGS, true); +} +exports.installGomodifytags = installGomodifytags; +async function installGotests() { + await (0, tools_1.installGoBin)(binaries_1.GOTESTS, true); +} +exports.installGotests = installGotests; +async function installGoplay() { + await (0, tools_1.installGoBin)(binaries_1.GOPLAY, true); +} +exports.installGoplay = installGoplay; +async function installImpl() { + await (0, tools_1.installGoBin)(binaries_1.IMPL, true); +} +exports.installImpl = installImpl; +async function installTools() { + for (const tool of binaries_1.TOOLS) { + await (0, tools_1.installGoBin)(tool, true); + } +} +exports.installTools = installTools; +//# sourceMappingURL=commands.js.map
\ No newline at end of file |
