UNPKG

fish-lsp

Version:

LSP implementation for fish/fish-shell

146 lines (145 loc) 3.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GlobalVariableList = exports.AbbrList = exports.EventNamesList = exports.FunctionNamesList = exports.BuiltInList = void 0; exports.isBuiltin = isBuiltin; exports.isReservedKeyword = isReservedKeyword; exports.findShell = findShell; exports.isFunction = isFunction; exports.isEvent = isEvent; const child_process_1 = require("child_process"); exports.BuiltInList = [ '[', '_', 'abbr', 'and', 'argparse', 'begin', 'bg', 'bind', 'block', 'break', 'breakpoint', 'builtin', 'case', 'cd', 'command', 'commandline', 'complete', 'contains', 'continue', 'count', 'disown', 'echo', 'else', 'emit', 'end', 'eval', 'exec', 'exit', 'false', 'fg', 'for', 'function', 'functions', 'history', 'if', 'jobs', 'math', 'not', 'or', 'path', 'printf', 'pwd', 'random', 'read', 'realpath', 'return', 'set', 'set_color', 'source', 'status', 'string', 'switch', 'test', 'time', 'true', 'type', 'ulimit', 'wait', 'while', ]; const BuiltInSET = new Set(exports.BuiltInList); function isBuiltin(word) { return BuiltInSET.has(word); } const reservedKeywords = [ '[', '_', 'and', 'argparse', 'begin', 'break', 'builtin', 'case', 'command', 'continue', 'else', 'end', 'eval', 'exec', 'for', 'function', 'if', 'not', 'or', 'read', 'return', 'set', 'status', 'string', 'switch', 'test', 'time', 'and', 'while', ]; const ReservedKeywordSet = new Set(reservedKeywords); function isReservedKeyword(word) { return ReservedKeywordSet.has(word); } function findShell() { const result = (0, child_process_1.spawnSync)('which fish', { shell: true, stdio: ['ignore', 'pipe', 'inherit'], encoding: 'utf-8' }); return result.stdout.toString().trim(); } const fishShell = findShell(); const spawnOpts = { shell: fishShell, stdio: ['ignore', 'pipe', 'inherit'], encoding: 'utf-8', }; function createFunctionNamesList() { const result = (0, child_process_1.spawnSync)('functions --names | string split -n \'\\n\'', spawnOpts); return result.stdout.toString().split('\n'); } exports.FunctionNamesList = createFunctionNamesList(); function isFunction(word) { return exports.FunctionNamesList.includes(word); } function createFunctionEventsList() { const result = (0, child_process_1.spawnSync)('functions --handlers | string match -vr \'^Event \\w+\' | string split -n \'\\n\'', spawnOpts); return result.stdout.toString().split('\n'); } exports.EventNamesList = createFunctionEventsList(); function isEvent(word) { return exports.EventNamesList.includes(word); } function createAbbrList() { const { stdout } = (0, child_process_1.spawnSync)('abbr --show', spawnOpts); return stdout.toString().split('\n'); } exports.AbbrList = createAbbrList(); function createGlobalVariableList() { const { stdout } = (0, child_process_1.spawnSync)('set -n', spawnOpts); return stdout.toString().split('\n'); } exports.GlobalVariableList = createGlobalVariableList();