diff --git a/libs/remix-ui/editor/src/lib/providers/codeActionProvider.ts b/libs/remix-ui/editor/src/lib/providers/codeActionProvider.ts index 1c4f3e75bc..8ae1291fd4 100644 --- a/libs/remix-ui/editor/src/lib/providers/codeActionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/codeActionProvider.ts @@ -41,7 +41,10 @@ export class RemixCodeActionProvider implements monaco.languages.CodeActionProvi // Get end location of last function parameter, it returns end column of parameter name const lastParamEndLoc = location.end const lineContent = model.getLineContent(lastParamEndLoc.line + 1) - msg = lineContent.substring(0, lastParamEndLoc.column + 2) + fix.message + lineContent.substring(lastParamEndLoc.column + 1, lineContent.length) + if (fix.id === 5 && lineContent.includes(' view ')) { + msg = lineContent.replace('view', 'pure') + } else + msg = lineContent.substring(0, lastParamEndLoc.column + 2) + fix.message + lineContent.substring(lastParamEndLoc.column + 1, lineContent.length) fix.range = { startLineNumber: lastParamEndLoc.line + 1, endLineNumber: lastParamEndLoc.line + 1, @@ -53,7 +56,10 @@ export class RemixCodeActionProvider implements monaco.languages.CodeActionProvi const location = await this.props.plugin.call('codeParser', 'getLineColumnOfNode', nodeAtPosition) const lineContent = model.getLineContent(location.start.line + 1) const i = lineContent.indexOf('()') - msg = lineContent.substring(0, i + 3) + fix.message + lineContent.substring(i + 3, lineContent.length) + if (fix.id === 5 && lineContent.includes(' view ')) { + msg = lineContent.replace('view', 'pure') + } else + msg = lineContent.substring(0, i + 3) + fix.message + lineContent.substring(i + 3, lineContent.length) fix.range = { startLineNumber: location.start.line + 1, endLineNumber: location.start.line + 1, @@ -70,7 +76,10 @@ export class RemixCodeActionProvider implements monaco.languages.CodeActionProvi // Get end location of last function parameter, it returns start column of parameter name const lastParamEndLoc = lastParamNode.loc.end const lineContent = model.getLineContent(lastParamEndLoc.line) - msg = lineContent.substring(0, lastParamEndLoc.column + lastParamNode.name.length + 2) + fix.message + lineContent.substring(lastParamEndLoc.column + lastParamNode.name.length + 1, lineContent.length) + if (fix.id === 5 && lineContent.includes(' view ')) { + msg = lineContent.replace('view', 'pure') + } else + msg = lineContent.substring(0, lastParamEndLoc.column + lastParamNode.name.length + 2) + fix.message + lineContent.substring(lastParamEndLoc.column + lastParamNode.name.length + 1, lineContent.length) fix.range = { startLineNumber: lastParamEndLoc.line, endLineNumber: lastParamEndLoc.line, @@ -80,7 +89,10 @@ export class RemixCodeActionProvider implements monaco.languages.CodeActionProvi } else { const lineContent = model.getLineContent(nodeAtPosition.loc.start.line) const i = lineContent.indexOf('()') - msg = lineContent.substring(0, i + 3) + fix.message + lineContent.substring(i + 3, lineContent.length) + if (fix.id === 5 && lineContent.includes(' view ')) { + msg = lineContent.replace('view', 'pure') + } else + msg = lineContent.substring(0, i + 3) + fix.message + lineContent.substring(i + 3, lineContent.length) fix.range = { startLineNumber: nodeAtPosition.loc.start.line, endLineNumber: nodeAtPosition.loc.start.line, diff --git a/libs/remix-ui/editor/src/lib/providers/quickfixes.ts b/libs/remix-ui/editor/src/lib/providers/quickfixes.ts index 14b24a5b0b..5eb8777076 100644 --- a/libs/remix-ui/editor/src/lib/providers/quickfixes.ts +++ b/libs/remix-ui/editor/src/lib/providers/quickfixes.ts @@ -28,5 +28,11 @@ export default { "title": "Add mutability 'view'", "message": "view ", "nodeType": "FunctionDefinition" + }, + "Warning: Function state mutability can be restricted to pure": { + "id": 5, + "title": "Add mutability 'pure'", + "message": "pure ", + "nodeType": "FunctionDefinition" } } \ No newline at end of file