UNPKG

coc-als

Version:

Ada Language Server support for coc.nvim

154 lines (149 loc) 5.97 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __getOwnPropNames = Object.getOwnPropertyNames; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __markAsModule = (target) => __defProp(target, "__esModule", {value: true}); var __export = (target, all) => { for (var name in all) __defProp(target, name, {get: all[name], enumerable: true}); }; var __exportStar = (target, module2, desc) => { if (module2 && typeof module2 === "object" || typeof module2 === "function") { for (let key of __getOwnPropNames(module2)) if (!__hasOwnProp.call(target, key) && key !== "default") __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable}); } return target; }; var __toModule = (module2) => { return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2); }; // src/index.ts __markAsModule(exports); __export(exports, { activate: () => activate }); var import_coc3 = __toModule(require("coc.nvim")); var coc = __toModule(require("coc.nvim")); var fs = __toModule(require("fs")); // src/lists.ts var import_coc = __toModule(require("coc.nvim")); var ALS_ShowDependenciesKind; (function(ALS_ShowDependenciesKind2) { ALS_ShowDependenciesKind2.Show_Imported = 1; ALS_ShowDependenciesKind2.Show_Importing = 2; })(ALS_ShowDependenciesKind || (ALS_ShowDependenciesKind = {})); var requestshowDependencies = new import_coc.RequestType("textDocument/alsShowDependencies"); var DependencyList = class extends import_coc.BasicList { constructor(nvim, client, kind) { super(nvim); this.description = "Load file dependencies from ALS"; this.defaultAction = "open"; this.actions = []; if (kind === ALS_ShowDependenciesKind.Show_Importing) this.name = "importing"; else this.name = "imported"; this.client = client; this.load = this.showDependencies(kind); this.addAction("open", (item) => { import_coc.workspace.jumpTo(item.data.uri); }); } async loadItems(_context) { return await this.load(); } showDependencies(kind) { return async () => { let document = await import_coc.workspace.document; let r = await this.client.sendRequest(requestshowDependencies, { textDocument: document.textDocument, kind, showImplicit: true }); if (!r) { import_coc.window.showErrorMessage("command failed"); } return r.map((value) => { return { label: value.uri.substring(value.uri.lastIndexOf("/") + 1), data: { uri: value.uri } }; }); }; } }; // src/commands.ts var import_coc2 = __toModule(require("coc.nvim")); var executeCommandType = new import_coc2.RequestType("workspace/executeCommand"); var requestCalledBy = new import_coc2.RequestType("textDocument/alsCalledBy"); var requestCalls = new import_coc2.RequestType("textDocument/alsCalls"); var jumpToOtherFile = (client) => async () => { let document = await import_coc2.workspace.document; let file = document.uri; await client.sendRequest(executeCommandType, { command: "als-other-file", arguments: [ { uri: file } ] }); }; var makeCallRequest = (request) => (client) => { return async () => { let dc = await Promise.all([import_coc2.workspace.document, import_coc2.window.getCursorPosition()]); let document = dc[0]; let cursor = dc[1]; let r = await client.sendRequest(request, { textDocument: document.textDocument, position: cursor }); if (!r) { import_coc2.window.showErrorMessage("command failed"); return; } else if (r.length === 0) { import_coc2.window.showMessage("Nothing found"); return; } import_coc2.commands.executeCommand("editor.action.showReferences", r[0].location.uri, r[0].location.range.start, r[0].refs); }; }; var calledBy = makeCallRequest(requestCalledBy); var calls = makeCallRequest(requestCalls); // src/index.ts async function activate(context) { let options = import_coc3.workspace.getConfiguration("ada"); if (!options.get("enable", true)) { return; } let projectFile = options.get("projectFile", ""); if (projectFile != "" && !fs.existsSync(projectFile)) { import_coc3.window.showErrorMessage(`Couldn't find project file '${projectFile}'`); return; } let projectFileInCurrentDir = fs.readdirSync(".").find((element) => { element.endsWith(".gpr"); }); if (projectFileInCurrentDir !== void 0) { import_coc3.window.showMessage("Using '" + projectFileInCurrentDir + "' as project file"); } ; const serverOptions = { command: options.get("serverBin") || "ada_language_server" }; const clientOption = { documentSelector: ["ada"], synchronize: { configurationSection: "ada" } }; const client = new import_coc3.LanguageClient("coc-als", "ada_language_server", serverOptions, clientOption); const jumpToOtherFile2 = jumpToOtherFile(client); context.subscriptions.push(import_coc3.services.registLanguageClient(client), import_coc3.commands.registerCommand("ada.otherFile", jumpToOtherFile2), import_coc3.commands.registerCommand("ada.calledBy", calledBy(client)), import_coc3.commands.registerCommand("ada.calls", calls(client)), coc.listManager.registerList(new DependencyList(import_coc3.workspace.nvim, client, ALS_ShowDependenciesKind.Show_Importing)), coc.listManager.registerList(new DependencyList(import_coc3.workspace.nvim, client, ALS_ShowDependenciesKind.Show_Imported))); import_coc3.workspace.registerKeymap(["n"], "als-other-file", jumpToOtherFile2, {sync: false}); }