UNPKG

fish-lsp

Version:

LSP implementation for fish/fish-shell

70 lines (69 loc) 3.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isEmittedEventDefinitionName = isEmittedEventDefinitionName; exports.isGenericFunctionEventHandlerDefinitionName = isGenericFunctionEventHandlerDefinitionName; exports.processEmitEventCommandName = processEmitEventCommandName; const node_types_1 = require("../utils/node-types"); const symbol_1 = require("./symbol"); const definition_scope_1 = require("../utils/definition-scope"); const tree_sitter_1 = require("../utils/tree-sitter"); const markdown_builder_1 = require("../utils/markdown-builder"); const symbol_detail_1 = require("./symbol-detail"); const function_1 = require("./function"); function isEmittedEventDefinitionName(node) { if (!node.parent || !node.isNamed) return false; if (!(0, node_types_1.isCommandWithName)(node.parent, 'emit')) { return false; } return !!(node.parent.namedChild(1) && node.parent.namedChild(1)?.equals(node)); } function findEmittedEventDefinitionName(node) { if (!(0, node_types_1.isCommandWithName)(node, 'emit')) return undefined; if (node.namedChild(1)) return node.namedChild(1) || undefined; return undefined; } function isGenericFunctionEventHandlerDefinitionName(node) { if (!node.parent || !node.isNamed) return false; if (!(0, node_types_1.isFunctionDefinition)(node.parent)) return false; const { eventNodes } = (0, function_1.findFunctionOptionNamedArguments)(node.parent); return eventNodes.some(eventNode => eventNode.equals(node)); } function processEmitEventCommandName(document, node, children = []) { const emittedEventNode = findEmittedEventDefinitionName(node); if (!emittedEventNode) return []; const eventName = emittedEventNode.text; const parentCommand = node; const scopeTag = document.isAutoloaded() ? 'global' : 'local'; return [ new symbol_1.FishSymbol({ name: eventName, fishKind: 'EVENT', node: parentCommand, children, document: document, scope: definition_scope_1.DefinitionScope.create(node, scopeTag), focusedNode: emittedEventNode, range: (0, tree_sitter_1.getRange)(parentCommand), detail: [ `(${markdown_builder_1.md.bold('event')}) ${markdown_builder_1.md.inlineCode(eventName)}`, markdown_builder_1.md.separator(), markdown_builder_1.md.codeBlock('fish', [ '### emit/fire a generic event', (0, symbol_detail_1.unindentNestedSyntaxNode)(parentCommand), ].join('\n')), markdown_builder_1.md.separator(), markdown_builder_1.md.boldItalic('SEE ALSO:'), ' • Emit Events: https://fishshell.com/docs/current/cmds/emit.html', ' • Event Handling: https://fishshell.com/docs/current/language.html#event', ].join(markdown_builder_1.md.newline()), }), ]; }