How to use the @argdown/core.isTokenNode function in @argdown/core

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 / 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";
        }
github christianvoigt / argdown / packages / argdown-language-server / src / providers / DocumentSymbolPlugin.ts View on Github external
[RuleNames.ARGUMENT + "Entry"]: (_request, _response, node) => {
        if (inRelations > 0 || inPcs) {
          return;
        }
        const symbol = {} as ArgdownSymbol;
        symbol.name = `<${node.argument!.title}>`;
        symbol.range = getRange(node);
        const firstChild =
          node.children && node.children.length > 0 ? node.children[0] : null;
        if (
          firstChild &&
          isTokenNode(firstChild) &&
          (tokenMatcher(firstChild, ArgumentDefinition) ||
            tokenMatcher(firstChild, ArgumentReference))
        ) {
          symbol.selectionRange = getRange(firstChild);
        } else {
          symbol.selectionRange = symbol.range;
        }
        symbol.kind = SymbolKind.Variable;
        parentsStack.push(symbol);
      },
      [RuleNames.ARGUMENT + "Exit"]: (_request, response) => {
github christianvoigt / argdown / packages / argdown-language-server / dist / providers / provideHover.js View on Github external
exports.provideHover = (response, 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")) {
            const eqClass = response.statements[nodeAtPosition.title];
            return {
                contents: utils_1.generateMarkdownForStatement(eqClass)
            };
        }
        else if (tokenName.startsWith("Argument")) {
            const argument = response.arguments[nodeAtPosition.title];
            return {
                contents: utils_1.generateMarkdownForArgument(argument)
            };
        }
        else if (tokenName.startsWith("Tag") && nodeAtPosition.tag) {
            const tag = nodeAtPosition.tag;
            const statementsStr = Object.keys(response.statements)