UNPKG

fish-lsp

Version:

LSP implementation for fish/fish-shell

190 lines (189 loc) 8.22 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SourcesDict = exports.FishLspHelp = exports.isPkgBinary = exports.getBuildTimeString = exports.PackageLspVersion = exports.PathObj = exports.PackageVersion = exports.RepoUrl = exports.smallFishLogo = void 0; exports.accumulateStartupOptions = accumulateStartupOptions; exports.FishLspManPage = FishLspManPage; exports.BuildCapabilityString = BuildCapabilityString; const fs_1 = require("fs"); const path_1 = require("path"); const package_json_1 = __importDefault(require("../../package.json")); const logger_1 = require("../logger"); /** * Accumulate the arguments into two arrays, '--enable' and '--disable' * More than one enable/disable flag can be used, but the output will be * the stored across two resulting arrays (if both flags have values as input). * Handles some of the default commands, such as '--help', and '-s, --show' * from the command line args. */ function accumulateStartupOptions(args) { const [_subcmd, ...options] = args; const [enabled, disabled] = [[], []]; let dumpCmd = false; let current; options?.forEach(arg => { if (['--enable', '--disable'].includes(arg)) { if (arg === '--enable') { current = enabled; } if (arg === '--disable') { current = disabled; } return; } if (['-h', '--help', 'help'].includes(arg)) { // commandBin.commands.find(command => command.name() === subcmd)!.outputHelp(); // process.exit(0); return; } if (['--dump'].includes(arg)) { (0, logger_1.logToStdout)('SEEN SHOW COMMAND! dumping...'); dumpCmd = true; return; } if (current) { current?.push(arg); } }); return { enabled, disabled, dumpCmd }; } /// HELPERS const smallFishLogo = () => '><(((°> FISH LSP'; exports.smallFishLogo = smallFishLogo; exports.RepoUrl = package_json_1.default.repository?.url.slice(0, -4); exports.PackageVersion = package_json_1.default.version; exports.PathObj = { ['bin']: (0, path_1.resolve)(__dirname.toString(), '..', '..', 'bin', 'fish-lsp'), ['root']: (0, path_1.resolve)(__dirname, '..', '..'), ['repo']: (0, path_1.resolve)(__dirname, '..', '..'), ['manFile']: (0, path_1.resolve)(__dirname, '..', '..', 'docs', 'man', 'fish-lsp.1'), }; exports.PackageLspVersion = package_json_1.default.dependencies['vscode-languageserver-protocol'].toString(); /** * shows last compile bundle time in server cli executable */ const getOutTime = () => { // @ts-ignore const buildFile = (0, path_1.resolve)(__dirname, '..', '..', 'out', 'build-time.txt'); let buildTime = 'unknown'; try { buildTime = (0, fs_1.readFileSync)(buildFile, 'utf8'); } catch (e) { (0, logger_1.logToStdout)('Error reading ./out/build-time.txt'); } return buildTime.trim(); }; const getBuildTimeString = () => { return getOutTime(); }; exports.getBuildTimeString = getBuildTimeString; const isPkgBinary = () => { return (0, path_1.resolve)(__dirname).startsWith('/snapshot/'); }; exports.isPkgBinary = isPkgBinary; exports.FishLspHelp = { beforeAll: ` fish-lsp [-h | --help] [-v | --version] [--help-man] [--help-all] [--help-short] fish-lsp start [--enable | --disable] [--dump] fish-lsp logger [-s | --show] [-d | --date] [-c | --clear] [-q | --quiet] [--config] fish-lsp info [--bare] [--repo] [--time] [--env] fish-lsp url [--repo] [--discussions] [--homepage] [--npm] [--contributions] [--wiki] [--issues] [--client-repo] [--sources] fish-lsp env [-c | --create] [-s | --show] [--no-comments] fish-lsp complete`, usage: `fish-lsp [OPTION] fish-lsp [COMMAND [OPTION...]]`, // fish-lsp [start | logger | info | url | complete] [options] // fish-lsp [-h | --help] [-v | --version] [--help-man] [--help-all] [--help-short] description: [ ' A language server for the `fish-shell`, written in typescript. Currently supports', ` the following feature set from '${exports.PackageLspVersion}' of the language server protocol.`, ' More documentation is available for any command or subcommand via \'-h/--help\'.', '', ' The current language server protocol, reserves stdin/stdout for communication between the ', ' client and server. This means that when the server is started, it will listen for messages on', ' stdin/stdout. Command communication will be visible in `logs.txt`.', '', ' For more information, see the github repository:', ` ${exports.RepoUrl}`, ].join('\n'), after: [ '', 'Examples:', ' # Default setup, with all options enabled', ' > fish-lsp start ', '', ' # Generate and store completions file:', ' > fish-lsp complete > ~/.config/fish/completions/fish-lsp.fish', ].join('\n'), }; function FishLspManPage() { const manFile = exports.PathObj.manFile; const content = (0, fs_1.readFileSync)(manFile, 'utf8'); return { path: (0, path_1.resolve)(exports.PathObj.root, exports.PathObj.manFile), content: content.split('\n'), }; } exports.SourcesDict = { repo: 'https://github.com/ndonfris/fish-lsp', git: 'https://github.com/ndonfris/fish-lsp', npm: 'https://npmjs.io/ndonfris/fish-lsp', homepage: 'https://fish-lsp.dev', contributions: 'https://github.com/ndonfris/fish-lsp/issues?q=', issues: 'https://github.com/ndonfris/fish-lsp/issues?q=', report: 'https://github.com/ndonfris/fish-lsp/issues?q=', wiki: 'https://github.com/ndonfris/fish-lsp/wiki', discussions: 'https://github.com/ndonfris/fish-lsp/discussions', clientsRepos: 'https://github.com/ndonfris/fish-lsp-language-clients/', sources: [ 'https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#headerPart', 'https://github.com/microsoft/vscode-extension-samples/tree/main', 'https://tree-sitter.github.io/tree-sitter/', 'https://github.com/ram02z/tree-sitter-fish', 'https://github.com/microsoft/vscode-languageserver-node/tree/main/testbed', 'https://github.com/Beaglefoot/awk-language-server/tree/master/server', 'https://github.com/bash-lsp/bash-language-server/tree/main/server/src', 'https://github.com/oncomouse/coc-fish', 'https://github.com/typescript-language-server/typescript-language-server#running-the-language-server', 'https://github.com/neoclide/coc-tsserver', 'https://www.npmjs.com/package/vscode-jsonrpc', 'https://github.com/Microsoft/vscode-languageserver-node', 'https://github.com/Microsoft/vscode-languageserver-node', 'https://github.com/microsoft/vscode-languageserver-node/blob/main/client/src/common', 'https://github.com/microsoft/vscode-languageserver-node/tree/main/server/src/common', ].join('\n'), }; function BuildCapabilityString() { const done = '✔️ '; // const done: string = '✅' const todo = '❌'; // const todo: string = '❌' const statusString = [ `${done} complete`, `${done} hover`, `${done} rename`, `${done} definition`, `${done} references`, `${done} diagnostics`, `${done} signatureHelp`, `${done} codeAction`, `${todo} codeLens`, `${done} documentLink`, `${done} formatting`, `${done} rangeFormatting`, `${done} refactoring`, `${done} executeCommand`, `${done} workspaceSymbol`, `${done} documentSymbol`, `${done} foldingRange`, `${done} fold`, `${done} onType`, `${done} onDocumentSaveFormat`, `${done} onDocumentSave`, `${done} onDocumentOpen`, `${done} onDocumentChange`, ].join('\n'); return statusString; }