UNPKG

fish-lsp

Version:

LSP implementation for fish/fish-shell

122 lines (121 loc) 5.47 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PrebuiltDocumentationMap = void 0; exports.getPrebuiltDocUrlByName = getPrebuiltDocUrlByName; exports.getPrebuiltDocUrl = getPrebuiltDocUrl; // import pagerHighlightVariablesJson from '../../snippets/pager_colors.json' const helperCommands_json_1 = __importDefault(require("../snippets/helperCommands.json")); const syntaxHighlightingVariables_json_1 = __importDefault(require("../snippets/syntaxHighlightingVariables.json")); const statusNumbers_json_1 = __importDefault(require("../snippets/statusNumbers.json")); const envVariables_json_1 = __importDefault(require("../snippets/envVariables.json")); const localeVariables_json_1 = __importDefault(require("../snippets/localeVariables.json")); const specialFishVariables_json_1 = __importDefault(require("../snippets/specialFishVariables.json")); const pipesAndRedirects_json_1 = __importDefault(require("../snippets/pipesAndRedirects.json")); const fishlspEnvVariables_json_1 = __importDefault(require("../snippets/fishlspEnvVariables.json")); var ExtendedBaseJson; (function (ExtendedBaseJson) { function create(o, type, specialType) { return { ...o, type, specialType, // otherTypes: [type], }; } ExtendedBaseJson.create = create; })(ExtendedBaseJson || (ExtendedBaseJson = {})); class DocumentationMap { map = new Map(); typeMap = new Map(); constructor(data) { data.forEach(item => { const curr = this.map.get(item.name) || []; // if (this.map.has(item.name)) return curr.push(item); this.map.set(item.name, curr); if (!this.typeMap.has(item.type)) this.typeMap.set(item.type, []); this.typeMap.get(item.type).push(item); }); } getByName(name) { return name.startsWith('$') ? this.map.get(name.slice(1)) || [] : this.map.get(name) || []; } getByType(type, specialType) { const allOfType = this.typeMap.get(type) || []; return specialType !== undefined ? allOfType.filter(v => v?.specialType === specialType) : allOfType; } add(item) { const curr = this.map.get(item.name) || []; curr?.push(item); this.map.set(item.name, curr); if (!this.typeMap.has(item.type)) this.typeMap.set(item.type, []); this.typeMap.get(item.type).push(item); } findMatchingNames(query, ...types) { const results = []; this.map.forEach(items => { if (items.filter(item => item.name.startsWith(query) && (types.length === 0 || types.includes(item.type || item.specialType)))) { results.push(...items); } }); return results; } } const allData = [ ...helperCommands_json_1.default.map((item) => ExtendedBaseJson.create(item, 'command')), ...pipesAndRedirects_json_1.default.map((item) => ExtendedBaseJson.create(item, 'pipe')), ...statusNumbers_json_1.default.map((item) => ExtendedBaseJson.create(item, 'status')), ...syntaxHighlightingVariables_json_1.default.map((item) => ExtendedBaseJson.create(item, 'variable', 'theme')), ...fishlspEnvVariables_json_1.default.map((item) => ExtendedBaseJson.create(item, 'variable', 'fishlsp')), ...envVariables_json_1.default.map((item) => ExtendedBaseJson.create(item, 'variable', 'env')), ...localeVariables_json_1.default.map((item) => ExtendedBaseJson.create(item, 'variable', 'locale')), ...specialFishVariables_json_1.default.map((item) => ExtendedBaseJson.create(item, 'variable', 'special')), ]; exports.PrebuiltDocumentationMap = new DocumentationMap(allData); function getPrebuiltDocUrlByName(name) { const objs = exports.PrebuiltDocumentationMap.getByName(name); const res = []; objs.forEach((obj, _index) => { // const linkStr = objs.length > 1 ? new String(index + 1) : '' res.push(` - ${getPrebuiltDocUrl(obj)}`); }); return res.join('\n').trim(); } function getPrebuiltDocUrl(obj) { switch (obj.type) { case 'command': return `https://fishshell.com/docs/current/cmds/${obj.name}.html`; case 'pipe': return 'https://fishshell.com/docs/current/language.html#input-output-redirection'; case 'status': return 'https://fishshell.com/docs/current/language.html#variables-status'; case 'variable': default: break; } // variable links switch (obj.specialType) { // case 'fishlsp' case 'env': return `https://fishshell.com/docs/current/language.html#envvar-${obj.name}`; case 'locale': return `https://fishshell.com/docs/current/language.html#locale-variables-${obj.name}`; case 'theme': // return 'https://fishshell.com/docs/current/interactive.html#variables-color' return `https://fishshell.com/docs/current/language.html#envvar-${obj.name}`; case 'special': return `https://fishshell.com/docs/current/language.html#envvar-${obj.name}`; // return 'https://fishshell.com/docs/current/language.html#special-variables' default: return ''; } }