fish-lsp
Version:
LSP implementation for fish/fish-shell
264 lines (263 loc) • 10.4 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FishLspHelp = exports.SourcesDict = exports.isPkgBinary = exports.getBuildTimeString = exports.PackageLspVersion = exports.PathObj = exports.PackageVersion = exports.RepoUrl = exports.smallFishLogo = exports.SubcommandEnv = void 0;
exports.accumulateStartupOptions = accumulateStartupOptions;
exports.getEnvOnlyArgs = getEnvOnlyArgs;
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");
function accumulateStartupOptions(args) {
const [_subcmd, ...options] = args;
const filteredOptions = filterStartCommandArgs(options);
const [enabled, disabled] = [[], []];
let dumpCmd = false;
let current;
filteredOptions?.forEach(arg => {
if (['--enable', '--disable'].includes(arg)) {
if (arg === '--enable') {
current = enabled;
}
if (arg === '--disable') {
current = disabled;
}
return;
}
if (['-h', '--help', 'help'].includes(arg)) {
return;
}
if (['--dump'].includes(arg)) {
logger_1.logger.logToStdout('SEEN SHOW COMMAND! dumping...');
dumpCmd = true;
return;
}
if (arg.startsWith('-')) {
return;
}
if (current) {
current?.push(arg);
}
});
return { enabled, disabled, dumpCmd };
}
var SubcommandEnv;
(function (SubcommandEnv) {
SubcommandEnv.defaultHandlerOptions = {
only: undefined,
comments: true,
global: true,
local: false,
export: true,
confd: false,
};
function getOutputType(args) {
return args.showDefault ? 'showDefault' : args.show ? 'show' : 'create';
}
SubcommandEnv.getOutputType = getOutputType;
function getOnly(args) {
if (args.only) {
const only = Array.isArray(args.only) ? args.only : [args.only];
return only.reduce((acc, value) => {
acc.push(...value.split(',').map(v => v.trim()));
return acc;
}, []);
}
return undefined;
}
SubcommandEnv.getOnly = getOnly;
function toEnvOutputOptions(args) {
const only = getOnly(args);
return {
only,
comments: args.comments ?? true,
global: args.global ?? true,
local: args.local ?? false,
export: args.export ?? true,
confd: args.confd ?? false,
};
}
SubcommandEnv.toEnvOutputOptions = toEnvOutputOptions;
})(SubcommandEnv || (exports.SubcommandEnv = SubcommandEnv = {}));
function getEnvOnlyArgs(cliEnvOnly) {
const splitOnlyValues = (v) => v.split(',').map(value => value.trim());
const isValidOnlyInput = (v) => typeof v === 'string'
|| Array.isArray(v) && v.every((value) => typeof value === 'string');
const onlyArrayBuilder = (v) => {
if (typeof v === 'string') {
return splitOnlyValues(v);
}
return v.reduce((acc, value) => {
acc.push(...splitOnlyValues(value));
return acc;
}, []);
};
if (!cliEnvOnly || !isValidOnlyInput(cliEnvOnly))
return undefined;
const only = Array.from(cliEnvOnly);
return onlyArrayBuilder(only);
}
function filterStartCommandArgs(args) {
const filteredArgs = [];
let skipNext = false;
for (const arg of args) {
if (skipNext) {
skipNext = false;
continue;
}
if (arg === '--socket' || arg === '--max-files' || arg === '--memory-limit') {
skipNext = true;
continue;
}
if (arg === '--stdio' || arg === '--node-ipc') {
continue;
}
if (arg.startsWith('--socket=') || arg.startsWith('--max-files=') || arg.startsWith('--memory-limit=')) {
continue;
}
filteredArgs.push(arg);
}
return filteredArgs;
}
function getCurrentExecutablePath() {
if (process.argv[0] && process.argv[0].includes('node')) {
return process.argv[1];
}
return process.execPath;
}
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, '..', '..'),
['execFile']: getCurrentExecutablePath(),
['manFile']: (0, path_1.resolve)(__dirname, '..', '..', 'docs', 'man', 'fish-lsp.1'),
};
exports.PackageLspVersion = package_json_1.default.dependencies['vscode-languageserver-protocol'].toString();
const getOutTime = () => {
const buildFile = (0, path_1.resolve)(__dirname, '..', '..', 'out', 'build-time.txt');
let buildTime = 'unknown';
try {
buildTime = (0, fs_1.readFileSync)(buildFile, 'utf8');
}
catch (e) {
logger_1.logger.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.SourcesDict = {
repo: 'https://github.com/ndonfris/fish-lsp',
git: 'https://github.com/ndonfris/fish-lsp',
npm: 'https://npmjs.com/fish-lsp',
homepage: 'https://fish-lsp.dev',
contributing: 'https://github.com/ndonfris/fish-lsp/blob/master/docs/CONTRIBUTING.md',
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',
clientsRepo: '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'),
};
exports.FishLspHelp = {
beforeAll: `
fish-lsp [-h | --help] [-v | --version] [--help-man] [--help-all] [--help-short]
fish-lsp start [--enable | --disable] [--dump]
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...]]`,
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 `$fish_lsp_log_file`.',
'',
' For more information, see the github repository:',
` ${exports.SourcesDict.git}`,
].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'),
};
}
function BuildCapabilityString() {
const done = '✔️ ';
const todo = '❌';
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`,
`${todo} semanticTokens`,
].join('\n');
return statusString;
}