How to use @argdown/core - 10 common examples

To help you get started, we’ve selected a few @argdown/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github christianvoigt / argdown / packages / argdown-language-server / src / providers / findNodesContainingPosition.ts View on Github external
.filter(n => {
      // Indent and Dedent are pseudo tokens that mess up the search because of their location information
      return (
        isRuleNode(n) ||
        (n.tokenType!.name !== TokenNames.INDENT &&
          n.tokenType!.name !== TokenNames.DEDENT)
      );
    })
    .filter(n => {
github christianvoigt / argdown / packages / argdown-language-server / dist / providers / findNodesContainingPosition.js View on Github external
.filter(n => {
        // Indent and Dedent are pseudo tokens that mess up the search because of their location information
        return (core_1.isRuleNode(n) ||
            (n.tokenType.tokenName !== core_1.TokenNames.INDENT &&
                n.tokenType.tokenName !== core_1.TokenNames.DEDENT));
    })
        .filter(n => {
github christianvoigt / argdown / packages / argdown-language-server / dist / providers / findNodesContainingPosition.js View on Github external
// acc & val start at the same line
            if (acc.startLine === line) {
                const valCharDistance = character - val.startColumn;
                const accCharDist = character - acc.startColumn;
                return valCharDistance < accCharDist && valCharDistance >= 0
                    ? val
                    : acc;
            }
            else {
                return val.startColumn > acc.startColumn ? val : acc;
            }
        }
    }, undefined);
    if (closestNode) {
        result.push(closestNode);
        if (core_1.isRuleNode(closestNode) &&
            closestNode.children &&
            closestNode.children.length > 0) {
            result.push(...exports.findNodesContainingPosition(closestNode.children, line, character));
        }
    }
    return result;
};
//# sourceMappingURL=findNodesContainingPosition.js.map
github christianvoigt / argdown / packages / argdown-language-server / src / providers / findNodesContainingPosition.ts View on Github external
// acc & val start at the same line
        if (acc.startLine === line) {
          const valCharDistance = character - val.startColumn!;
          const accCharDist = character - acc.startColumn!;
          return valCharDistance < accCharDist && valCharDistance >= 0
            ? val
            : acc;
        } else {
          return val.startColumn! > acc.startColumn! ? val : acc;
        }
      }
    }, undefined);
  if (closestNode) {
    result.push(closestNode);
    if (
      isRuleNode(closestNode) &&
      closestNode.children &&
      closestNode.children.length > 0
    ) {
      result.push(
        ...findNodesContainingPosition(closestNode.children, line, character)
      );
    }
  }
  return result;
};
github christianvoigt / argdown / packages / argdown-language-server / src / providers / provideRenameWorkspaceEdit.ts View on Github external
const createTextEdit = (node: IAstNode, newName: string): TextEdit | null => {
  if (isTokenNode(node) && node.tokenType) {
    switch (node.tokenType.name) {
      case "ArgumentReference":
        return TextEdit.replace(createRange(node), `<${newName}>`);
      case "ArgumentDefinition":
        return TextEdit.replace(createRange(node), `<${newName}>:`);
      case "ArgumentMention":
        return TextEdit.replace(createRange(node), `@<${newName}>`);
      case "StatementReference":
        return TextEdit.replace(createRange(node), `[${newName}]`);
      case "StatementDefinition":
        return TextEdit.replace(createRange(node), `[${newName}]:`);
      case "StatementMention":
        return TextEdit.replace(createRange(node), `@[${newName}]`);
      case "Tag":
        return TextEdit.replace(createRange(node), `#(${newName})`); // we use the bracketed tag syntax, so we don't have to check the format of newName
    }
github christianvoigt / argdown / packages / argdown-language-server / dist / providers / findReferences.js View on Github external
utils_1.walkTree(response.ast, null, 0, (node) => {
            if (core_1.isTokenNode(node) &&
                node.tokenType &&
                node.tokenType.tokenName.startsWith(tokenStart)) {
                let matches = false;
                if (refersToArgument || refersToStatement) {
                    matches = node.title === nodeId;
                }
                else if (refersToTag) {
                    matches = node.tag === nodeId;
                }
                if (matches &&
                    (includeDeclaration ||
                        !node.tokenType.tokenName.endsWith("Definition"))) {
                    references.push(node);
                }
            }
            // if (
github christianvoigt / argdown / packages / argdown-language-server / dist / providers / provideDefinitions.js View on Github external
exports.provideDefinitions = (response, uri, position) => {
    const line = position.line + 1;
    const character = position.character + 1;
    const nodeAtPosition = findNodeAtPosition_1.findNodeAtPosition(response, line, character);
    if (nodeAtPosition && core_1.isTokenNode(nodeAtPosition)) {
        const tokenName = nodeAtPosition.tokenType.tokenName;
        if (tokenName.startsWith("Statement")) {
            // collect locations of all equivalenceClass members
            const equivalenceClass = response.statements[nodeAtPosition.title];
            const definitions = equivalenceClass.members.filter(m => !m.isReference).map(m => {
                return utils_1.createLocation(uri, m);
            });
            return definitions;
        }
        else if (tokenName.startsWith("Argument")) {
            // collect locations of pcs and all descriptions
            const argument = response.arguments[nodeAtPosition.title];
            const definitions = argument.members.filter(m => !m.isReference).map(m => {
                return utils_1.createLocation(uri, m);
            });
            if (argument.pcs && argument.pcs.length > 0) {
github christianvoigt / argdown / packages / argdown-language-server / src / providers / provideDefinitions.ts View on Github external
export const provideDefinitions = (
  response: IArgdownResponse,
  uri: string,
  position: Position
): Location[] => {
  const line = position.line + 1;
  const character = position.character + 1;
  const nodeAtPosition = findNodeAtPosition(response, line, character);
  if (nodeAtPosition && isTokenNode(nodeAtPosition)) {
    const tokenName = nodeAtPosition.tokenType!.name;
    if (tokenName!.startsWith("Statement")) {
      // collect locations of all equivalenceClass members
      const equivalenceClass = response.statements![nodeAtPosition.title!];
      const definitions: Location[] = equivalenceClass.members
        .filter(m => !m.isReference)
        .map(m => {
          return createLocation(uri, m);
        });
      return definitions;
    } else if (tokenName!.startsWith("Argument")) {
      // collect locations of pcs and all descriptions
      const argument = response.arguments![nodeAtPosition.title!];
      const definitions: Location[] = argument.members
        .filter(m => !m.isReference)
        .map(m => {
github christianvoigt / argdown / packages / argdown-language-server / dist / providers / provideRenameWorkspaceEdit.js View on Github external
const createTextEdit = (node, newName) => {
    if (core_1.isTokenNode(node) && node.tokenType) {
        switch (node.tokenType.tokenName) {
            case "ArgumentReference":
                return vscode_languageserver_1.TextEdit.replace(utils_1.createRange(node), `<${newName}>`);
            case "ArgumentDefinition":
                return vscode_languageserver_1.TextEdit.replace(utils_1.createRange(node), `<${newName}>:`);
            case "ArgumentMention":
                return vscode_languageserver_1.TextEdit.replace(utils_1.createRange(node), `@<${newName}>`);
            case "StatementReference":
                return vscode_languageserver_1.TextEdit.replace(utils_1.createRange(node), `[${newName}]`);
            case "StatementDefinition":
                return vscode_languageserver_1.TextEdit.replace(utils_1.createRange(node), `[${newName}]:`);
            case "StatementMention":
                return vscode_languageserver_1.TextEdit.replace(utils_1.createRange(node), `@[${newName}]`);
            case "Tag":
                return vscode_languageserver_1.TextEdit.replace(utils_1.createRange(node), `#(${newName})`); // we use the bracketed tag syntax, so we don't have to check the format of newName
        }
github christianvoigt / argdown / packages / argdown-language-server / dist / providers / findReferences.js View on Github external
exports.findReferences = (response, nodeAtPosition, includeDeclaration) => {
    const references = [];
    if (nodeAtPosition && core_1.isTokenNode(nodeAtPosition)) {
        const refersToStatement = nodeAtPosition.tokenType.tokenName.startsWith("Statement");
        const refersToArgument = nodeAtPosition.tokenType.tokenName.startsWith("Argument");
        const refersToTag = nodeAtPosition.tokenType.tokenName === core_1.TokenNames.TAG;
        // const isArgument = nodeAtPosition.tokenType.tokenName.startsWith(
        //   "Argument"
        // );
        let tokenStart;
        let nodeId;
        if (refersToStatement) {
            nodeId = nodeAtPosition.title;
            tokenStart = "Statement";
        }
        else if (refersToArgument) {
            nodeId = nodeAtPosition.title;
            tokenStart = "Argument";
        }