blob: d60955c8e764bc58d9d6e6fa9f036870dd433595 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setState = exports.getState = exports.configDir = exports.setStoragePath = exports.getConfig = void 0;
const tslib_1 = require("tslib");
const path_1 = tslib_1.__importDefault(require("path"));
const os_1 = tslib_1.__importDefault(require("os"));
const fs_1 = tslib_1.__importDefault(require("fs"));
const coc_nvim_1 = require("coc.nvim");
const fs_2 = require("./fs");
const state = {};
function getConfig() {
return coc_nvim_1.workspace.getConfiguration().get("go");
}
exports.getConfig = getConfig;
function setStoragePath(dir) {
state.storagePath = dir;
}
exports.setStoragePath = setStoragePath;
async function configDir(...names) {
const storage = state.storagePath || path_1.default.join(os_1.default.homedir(), ".config", "coc", "go");
const dir = path_1.default.join(storage, ...names);
return new Promise((resolve) => {
(0, fs_2.createDir)(dir);
resolve(dir);
});
}
exports.configDir = configDir;
async function stateFile() {
return path_1.default.join(await configDir(), 'state.json');
}
async function getStateData() {
try {
const f = await stateFile();
const d = JSON.parse(await fs_1.default.promises.readFile(f, 'utf-8'));
return d || {};
}
catch (err) { /* mute */ }
return {};
}
async function setStateData(data) {
try {
await fs_1.default.promises.writeFile(await stateFile(), JSON.stringify(data, null, ' '));
}
catch (err) { /* mute */ }
}
async function getState(key) {
const d = await getStateData();
return d[key] || '';
}
exports.getState = getState;
async function setState(key, value) {
const d = await getStateData();
d[key] = value;
await setStateData(d);
}
exports.setState = setState;
//# sourceMappingURL=config.js.map
|