Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-go / lib / utils / impl.js
1 "use strict";
2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.generateImplStubs = void 0;
4 const coc_nvim_1 = require("coc.nvim");
5 const binaries_1 = require("../binaries");
6 const tools_1 = require("./tools");
7 const interfaceRegex = /^(\w+ \*?\w+ )?([\w./]+)$/;
8 async function generateImplStubs(document) {
9     try {
10         const implInput = await coc_nvim_1.workspace.requestInput("Enter receiver and interface [f *File io.Closer]");
11         if (implInput == null) {
12             coc_nvim_1.workspace.showMessage("No input detected! Aborting.", "warning");
13             return;
14         }
15         const matches = implInput.match(interfaceRegex);
16         if (!matches) {
17             throw Error(`Cannot parse input: ${implInput}`);
18         }
19         const edit = await runGoImpl(document, [matches[1], matches[2]]);
20         await coc_nvim_1.workspace.applyEdit({ changes: { [document.uri]: [edit] } });
21     }
22     catch (error) {
23         coc_nvim_1.workspace.showMessage(error, "error");
24     }
25 }
26 exports.generateImplStubs = generateImplStubs;
27 async function runGoImpl(document, args) {
28     const stdout = await tools_1.execTool(binaries_1.IMPL, args);
29     const { line } = await coc_nvim_1.workspace.getCursorPosition();
30     const insertPos = { line: line + 1, character: 0 };
31     const lineText = await coc_nvim_1.workspace.getLine(document.uri, line);
32     const newText = lineText.trim() === ''
33         ? stdout
34         : `\n${stdout}`;
35     return {
36         range: {
37             start: insertPos,
38             end: insertPos
39         },
40         newText
41     };
42 }
43 //# sourceMappingURL=impl.js.map