UNPKG

@yaegassy/coc-csharp-ls

Version:

csharp-language-server (csharp-ls) extension for coc.nvim

367 lines (360 loc) 13.1 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __commonJS = (cb, mod) => function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // node_modules/isexe/dist/cjs/posix.js var require_posix = __commonJS({ "node_modules/isexe/dist/cjs/posix.js"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sync = exports.isexe = void 0; var fs_1 = require("fs"); var promises_1 = require("fs/promises"); var isexe = async (path, options = {}) => { const { ignoreErrors = false } = options; try { return checkStat(await (0, promises_1.stat)(path), options); } catch (e) { const er = e; if (ignoreErrors || er.code === "EACCES") return false; throw er; } }; exports.isexe = isexe; var sync = (path, options = {}) => { const { ignoreErrors = false } = options; try { return checkStat((0, fs_1.statSync)(path), options); } catch (e) { const er = e; if (ignoreErrors || er.code === "EACCES") return false; throw er; } }; exports.sync = sync; var checkStat = (stat, options) => stat.isFile() && checkMode(stat, options); var checkMode = (stat, options) => { var _a, _b, _c, _d, _e, _f, _g, _h; const myUid = (_b = options.uid) != null ? _b : (_a = process.getuid) == null ? void 0 : _a.call(process); const myGroups = (_e = (_d = options.groups) != null ? _d : (_c = process.getgroups) == null ? void 0 : _c.call(process)) != null ? _e : []; const myGid = (_h = (_g = options.gid) != null ? _g : (_f = process.getgid) == null ? void 0 : _f.call(process)) != null ? _h : myGroups[0]; if (myUid === void 0 || myGid === void 0) { throw new Error("cannot get uid or gid"); } const groups = /* @__PURE__ */ new Set([myGid, ...myGroups]); const mod = stat.mode; const uid = stat.uid; const gid = stat.gid; const u = parseInt("100", 8); const g = parseInt("010", 8); const o = parseInt("001", 8); const ug = u | g; return !!(mod & o || mod & g && groups.has(gid) || mod & u && uid === myUid || mod & ug && myUid === 0); }; } }); // node_modules/isexe/dist/cjs/win32.js var require_win32 = __commonJS({ "node_modules/isexe/dist/cjs/win32.js"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sync = exports.isexe = void 0; var fs_1 = require("fs"); var promises_1 = require("fs/promises"); var isexe = async (path, options = {}) => { const { ignoreErrors = false } = options; try { return checkStat(await (0, promises_1.stat)(path), path, options); } catch (e) { const er = e; if (ignoreErrors || er.code === "EACCES") return false; throw er; } }; exports.isexe = isexe; var sync = (path, options = {}) => { const { ignoreErrors = false } = options; try { return checkStat((0, fs_1.statSync)(path), path, options); } catch (e) { const er = e; if (ignoreErrors || er.code === "EACCES") return false; throw er; } }; exports.sync = sync; var checkPathExt = (path, options) => { const { pathExt = process.env.PATHEXT || "" } = options; const peSplit = pathExt.split(";"); if (peSplit.indexOf("") !== -1) { return true; } for (let i = 0; i < peSplit.length; i++) { const p = peSplit[i].toLowerCase(); const ext = path.substring(path.length - p.length).toLowerCase(); if (p && ext === p) { return true; } } return false; }; var checkStat = (stat, path, options) => stat.isFile() && checkPathExt(path, options); } }); // node_modules/isexe/dist/cjs/options.js var require_options = __commonJS({ "node_modules/isexe/dist/cjs/options.js"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); } }); // node_modules/isexe/dist/cjs/index.js var require_cjs = __commonJS({ "node_modules/isexe/dist/cjs/index.js"(exports) { "use strict"; var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) { if (k2 === void 0) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); } : function(o, m, k, k2) { if (k2 === void 0) k2 = k; o[k2] = m[k]; }); var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); } : function(o, v) { o["default"] = v; }); var __importStar = exports && exports.__importStar || function(mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) { for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); } __setModuleDefault(result, mod); return result; }; var __exportStar = exports && exports.__exportStar || function(m, exports2) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p)) __createBinding(exports2, m, p); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.sync = exports.isexe = exports.posix = exports.win32 = void 0; var posix = __importStar(require_posix()); exports.posix = posix; var win32 = __importStar(require_win32()); exports.win32 = win32; __exportStar(require_options(), exports); var platform = process.env._ISEXE_TEST_PLATFORM_ || process.platform; var impl = platform === "win32" ? win32 : posix; exports.isexe = impl.isexe; exports.sync = impl.sync; } }); // node_modules/which/lib/index.js var require_lib = __commonJS({ "node_modules/which/lib/index.js"(exports, module2) { var { isexe, sync: isexeSync } = require_cjs(); var { join, delimiter, sep, posix } = require("path"); var isWindows = process.platform === "win32"; var rSlash = new RegExp(`[${posix.sep}${sep === posix.sep ? "" : sep}]`.replace(/(\\)/g, "\\$1")); var rRel = new RegExp(`^\\.${rSlash.source}`); var getNotFoundError = (cmd) => Object.assign(new Error(`not found: ${cmd}`), { code: "ENOENT" }); var getPathInfo = (cmd, { path: optPath = process.env.PATH, pathExt: optPathExt = process.env.PATHEXT, delimiter: optDelimiter = delimiter }) => { const pathEnv = cmd.match(rSlash) ? [""] : [ // windows always checks the cwd first ...isWindows ? [process.cwd()] : [], ...(optPath || /* istanbul ignore next: very unusual */ "").split(optDelimiter) ]; if (isWindows) { const pathExtExe = optPathExt || [".EXE", ".CMD", ".BAT", ".COM"].join(optDelimiter); const pathExt = pathExtExe.split(optDelimiter).flatMap((item) => [item, item.toLowerCase()]); if (cmd.includes(".") && pathExt[0] !== "") { pathExt.unshift(""); } return { pathEnv, pathExt, pathExtExe }; } return { pathEnv, pathExt: [""] }; }; var getPathPart = (raw, cmd) => { const pathPart = /^".*"$/.test(raw) ? raw.slice(1, -1) : raw; const prefix = !pathPart && rRel.test(cmd) ? cmd.slice(0, 2) : ""; return prefix + join(pathPart, cmd); }; var which2 = async (cmd, opt = {}) => { const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt); const found = []; for (const envPart of pathEnv) { const p = getPathPart(envPart, cmd); for (const ext of pathExt) { const withExt = p + ext; const is = await isexe(withExt, { pathExt: pathExtExe, ignoreErrors: true }); if (is) { if (!opt.all) { return withExt; } found.push(withExt); } } } if (opt.all && found.length) { return found; } if (opt.nothrow) { return null; } throw getNotFoundError(cmd); }; var whichSync = (cmd, opt = {}) => { const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt); const found = []; for (const pathEnvPart of pathEnv) { const p = getPathPart(pathEnvPart, cmd); for (const ext of pathExt) { const withExt = p + ext; const is = isexeSync(withExt, { pathExt: pathExtExe, ignoreErrors: true }); if (is) { if (!opt.all) { return withExt; } found.push(withExt); } } } if (opt.all && found.length) { return found; } if (opt.nothrow) { return null; } throw getNotFoundError(cmd); }; module2.exports = which2; which2.sync = whichSync; } }); // src/index.ts var src_exports = {}; __export(src_exports, { activate: () => activate, deactivate: () => deactivate, getCsharpLsBinaryPath: () => getCsharpLsBinaryPath }); module.exports = __toCommonJS(src_exports); var import_coc = require("coc.nvim"); var import_which = __toESM(require_lib()); var client = void 0; async function activate(_context) { if (!import_coc.workspace.getConfiguration("csharp-ls").get("enable")) return; const outputChannel = import_coc.window.createOutputChannel("csharp-ls"); const csharpLsBinaryPath = await getCsharpLsBinaryPath(); if (!csharpLsBinaryPath) { import_coc.window.showErrorMessage('"csharp-ls" command was not found.'); return; } const csharpLsArgs = import_coc.workspace.getConfiguration("csharp-ls").get("args", []); const csharpLsExecutable = { command: csharpLsBinaryPath, args: csharpLsArgs, options: { shell: true } }; const serverOptions = { run: csharpLsExecutable, debug: csharpLsExecutable }; const documentSelector = ["cs", "csharp"]; const clientOptions = { documentSelector, synchronize: { fileEvents: import_coc.workspace.createFileSystemWatcher("**/.{cs,csproj}") }, outputChannel, progressOnInitialization: true }; client = new import_coc.LanguageClient("csharp-ls", "csharp-ls", serverOptions, clientOptions); registerTextDocumentContentProviders(); import_coc.services.registerLanguageClient(client); } function deactivate() { if (!client) { return void 0; } return client.stop(); } function registerTextDocumentContentProviders() { const csharpMetadataProvider = new class { async provideTextDocumentContent(uri) { var _a; const response = await (client == null ? void 0 : client.sendRequest("csharp/metadata", { textDocument: { uri: uri.toString() } })); return (_a = response == null ? void 0 : response.source) != null ? _a : ""; } }(); import_coc.workspace.registerTextDocumentContentProvider("csharp", csharpMetadataProvider); } async function getCsharpLsBinaryPath() { let binaryPath = import_coc.workspace.getConfiguration("csharp-ls").get("path", ""); if (!binaryPath) { binaryPath = import_which.default.sync("csharp-ls", { nothrow: true }) || ""; } return binaryPath; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { activate, deactivate, getCsharpLsBinaryPath });