Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/components/Arguments/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ const Arguments: React.FC<ArgumentsProps> = (props) => {

// Language server throws "input is not literal" without quotes
if (type === `String`) {
console.log({ value });
value = `\"${value.replace(/"/g, '\\"')}\"`;
}

Expand Down
9 changes: 4 additions & 5 deletions src/components/CadenceEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import React from 'react';
import styled from '@emotion/styled';
import { keyframes } from '@emotion/core';
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
const { MonacoServices } = require('monaco-languageclient/lib/monaco-services');
import { extractSigners } from "util/parser";


import configureCadence, { CADENCE_LANGUAGE_ID } from 'util/cadence';
import {
Expand Down Expand Up @@ -357,10 +360,6 @@ class CadenceEditor extends React.Component<
return [];
}

extractSigners(code: string): number {
return this.extract(code, 'prepare').filter((item) => !!item).length;
}

hover(highlight: Highlight): void {
const { startLine, startColumn, endLine, endColumn, color } = highlight;
const model = this.editor.getModel();
Expand Down Expand Up @@ -426,7 +425,7 @@ class CadenceEditor extends React.Component<
const list = args[activeId] || [];

/// Extract number of signers from code
const signers = this.extractSigners(code);
const signers = extractSigners(code).length
const problemsList: ProblemsList = problems[activeId] || {
error: [],
warning: [],
Expand Down
Empty file removed src/util/parse-contract-name.ts
Empty file.
35 changes: 35 additions & 0 deletions src/util/parser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export const collapseSpaces = (input: string) => input.replace(/\s+/g, " ");
export const stripNewLines = (input: string) => input.replace(/\r\n|\n|\r/g, " ");

export const generateSchema = (argsDefinition: string) =>
argsDefinition
.split(",")
.map((item) => item.replace(/\s*/g, ""))
.filter((item) => item !== "");

export const stripComments = (code: string) => {
const commentsRegExp = /(\/\*[\s\S]*?\*\/)|(\/\/.*)/g;
return code.replace(commentsRegExp, "");
};

export const extract = (code: string, keyWord: string) => {
const noComments = stripComments(code);
const target = collapseSpaces(noComments.replace(/[\n\r]/g, ""));

if (target) {
const regexp = new RegExp(keyWord, "g");
const match = regexp.exec(target);

if (match) {
if (match[1] === "") {
return [];
}
return generateSchema(match[1]);
}
}
return [];
};

export const extractSigners = (code: string) => {
return extract(code, `(?:prepare\\s*\\(\\s*)([^\\)]*)(?:\\))`);
};