UNPKG

coc-omnisharp

Version:

OmniSharp integration, supports C# and VisualBasic.

108 lines 5.82 kB
/* -------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. * ------------------------------------------------------------------------------------------ */ 'use strict'; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const coc_nvim_1 = require("coc.nvim"); const coc_utils_1 = require("coc-utils"); const logger = coc_nvim_1.workspace.createOutputChannel("coc-omnisharp"); const omnisharpLogger = coc_nvim_1.workspace.createOutputChannel("omnisharp"); const omnisharpVersion = coc_nvim_1.workspace.getConfiguration('omnisharp').get('version').toLowerCase(); const omnisharpRepo = { kind: "github", repo: "omnisharp/omnisharp-roslyn", channel: omnisharpVersion === "latest" ? omnisharpVersion : `tags/${omnisharpVersion}` }; const omnisharpPacks = { "win-x64": { platformPath: "omnisharp-win-x64.zip", executable: "Omnisharp.exe" }, "linux-x64": { platformPath: "omnisharp-linux-x64.zip", executable: "run" }, "osx-x64": { platformPath: "omnisharp-osx.zip", executable: "run" }, }; function activate(context) { return __awaiter(this, void 0, void 0, function* () { logger.appendLine("coc-omnisharp activated."); logger.appendLine(`workspace root=${coc_nvim_1.workspace.rootPath}`); // Options to control the language client let clientOptions = { // Register the server for C#/VB documents documentSelector: [{ scheme: 'file', language: 'cs' }, { scheme: 'file', language: 'vb' }], synchronize: { configurationSection: 'omnisharp', fileEvents: [ coc_nvim_1.workspace.createFileSystemWatcher('**/*.cs'), coc_nvim_1.workspace.createFileSystemWatcher('**/*.csx'), coc_nvim_1.workspace.createFileSystemWatcher('**/*.cake'), coc_nvim_1.workspace.createFileSystemWatcher('**/*.vb') ] }, outputChannel: omnisharpLogger, }; const config = coc_nvim_1.workspace.getConfiguration('omnisharp'); const omnisharpCustomPath = config.get('path'); const loglevel = config.get('trace.server'); const debug = config.get('debug.server'); const useCustomPath = omnisharpCustomPath.length > 0; const omnisharpProvider = new coc_utils_1.LanguageServerProvider(context, "OmniSharp", omnisharpPacks, omnisharpRepo); const omnisharpExe = useCustomPath ? omnisharpCustomPath : yield omnisharpProvider.getLanguageServer(); // find the solution file let sln = fs_1.default.readdirSync(coc_nvim_1.workspace.rootPath) .map(x => path_1.default.join(coc_nvim_1.workspace.rootPath, x)) .find(x => x.endsWith(".sln") && fs_1.default.statSync(x).isFile()); logger.appendLine(`Solution file is: ${sln}`); let args = ["-lsp"]; if (sln !== undefined) { args.push("-s"); args.push(sln); } if (loglevel === "verbose") { args.push("-v"); logger.appendLine("omnisharp verbose logging activated"); } if (debug) { args.push("--debug"); logger.appendLine("omnisharp debug mode activated"); } let serverOptions = { command: omnisharpExe, args: args, options: { cwd: coc_nvim_1.workspace.rootPath } }; // Create the language client and start the client. let client = new coc_nvim_1.LanguageClient('cs', 'OmniSharp Language Server', serverOptions, clientOptions); let client_dispose = client.start(); // Push the disposable to the context's subscriptions so that the // client can be deactivated on extension deactivation context.subscriptions.push(client_dispose); let cmd_updateomnisharp = coc_nvim_1.commands.registerCommand('omnisharp.downloadLanguageServer', () => __awaiter(this, void 0, void 0, function* () { if (client.started) { yield client.stop(); client_dispose.dispose(); yield coc_utils_1.sleep(1000); } yield omnisharpProvider.downloadLanguageServer(); if (useCustomPath) { coc_nvim_1.workspace.showMessage(`coc-omnisharp: Using custom executable (${omnisharpCustomPath}) so the downloaded bundle will have no effect`, 'warning'); } client_dispose = client.start(); context.subscriptions.push(client_dispose); })); context.subscriptions.push(cmd_updateomnisharp); }); } exports.activate = activate; //# sourceMappingURL=extension.js.map