Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-go / lib / commands.js
1 "use strict";
2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.installTools = exports.installImpl = exports.installGoplay = exports.installGotests = exports.installGomodifytags = exports.checkGopls = exports.installGopls = exports.version = void 0;
4 const tslib_1 = require("tslib");
5 const path_1 = tslib_1.__importDefault(require("path"));
6 const fs_1 = tslib_1.__importDefault(require("fs"));
7 const coc_nvim_1 = require("coc.nvim");
8 const tools_1 = require("./utils/tools");
9 const checktag_1 = tslib_1.__importDefault(require("./utils/checktag"));
10 const binaries_1 = require("./binaries");
11 const versions_1 = require("./utils/versions");
12 async function version() {
13     const v1 = await pkgVersion();
14     const v2 = await goplsVersion() || 'unknown';
15     coc_nvim_1.workspace.showMessage(`Version: coc-go ${v1}; gopls ${v2}`, 'more');
16 }
17 exports.version = version;
18 async function installGopls(client) {
19     await tools_1.installGoBin(binaries_1.GOPLS, true);
20     if (client.needsStop()) {
21         await client.stop();
22         client.restart();
23     }
24 }
25 exports.installGopls = installGopls;
26 async function checkGopls(client, mode) {
27     const [current, latest] = await Promise.all([
28         goplsVersion(),
29         checktag_1.default("golang/tools", /^gopls\//),
30     ]);
31     try {
32         let install = false;
33         switch (versions_1.compareVersions(latest, current)) {
34             case 0:
35                 coc_nvim_1.workspace.showMessage(`[gopls] up-to-date: ${current}`, 'more');
36                 break;
37             case 1:
38                 switch (mode) {
39                     case 'install':
40                         install = true;
41                         break;
42                     case 'ask':
43                         install = await coc_nvim_1.workspace.showPrompt(`[gopls] Install update? ${current} => ${latest}`);
44                         break;
45                     case 'inform':
46                         coc_nvim_1.workspace.showMessage(`[gopls] update available: ${current} => ${latest}`);
47                         break;
48                 }
49                 break;
50             case -1:
51                 coc_nvim_1.workspace.showMessage(`[gopls] current: ${current} | latest: ${latest}`, 'more');
52                 break;
53         }
54         if (install) {
55             await installGopls(client);
56         }
57     }
58     catch (e) {
59         coc_nvim_1.workspace.showMessage(e.toString(), 'error');
60     }
61 }
62 exports.checkGopls = checkGopls;
63 async function pkgVersion() {
64     try {
65         const pkgPath = path_1.default.resolve(__dirname, '..', 'package.json');
66         const pkgContent = await fs_1.default.promises.readFile(pkgPath, 'utf8');
67         return JSON.parse(pkgContent).version;
68     }
69     catch (err) {
70         console.error(err);
71     }
72     return '';
73 }
74 async function goplsVersion() {
75     const [, versionOut] = await tools_1.runGoTool("gopls", ["version"]);
76     const m = versionOut.trim().match(/^golang\.org\/x\/tools\/gopls (v?\d+\.\d+\.\d+)/);
77     if (m && versions_1.isValidVersion(m[1])) {
78         return m[1].replace(/^v/, '');
79     }
80     return '';
81 }
82 async function installGomodifytags() {
83     await tools_1.installGoBin(binaries_1.GOMODIFYTAGS, true);
84 }
85 exports.installGomodifytags = installGomodifytags;
86 async function installGotests() {
87     await tools_1.installGoBin(binaries_1.GOTESTS, true);
88 }
89 exports.installGotests = installGotests;
90 async function installGoplay() {
91     await tools_1.installGoBin(binaries_1.GOPLAY, true);
92 }
93 exports.installGoplay = installGoplay;
94 async function installImpl() {
95     await tools_1.installGoBin(binaries_1.IMPL, true);
96 }
97 exports.installImpl = installImpl;
98 async function installTools() {
99     for (const tool of binaries_1.TOOLS) {
100         await tools_1.installGoBin(tool, true);
101     }
102 }
103 exports.installTools = installTools;
104 //# sourceMappingURL=commands.js.map