Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
}
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 (
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) {
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 => {
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
}
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";
}
[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) => {
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)