quick fixes as array and refactoring

pull/3978/head
aniket-engg 1 year ago committed by Aniket
parent ee4e8d36ec
commit 913fc97043
  1. 47
      libs/remix-ui/editor/src/lib/providers/codeActionProvider.ts
  2. 16
      libs/remix-ui/editor/src/lib/providers/quickfixes.ts

@ -1,7 +1,7 @@
import { Monaco } from "@monaco-editor/react"
import monaco from "../../types/monaco"
import { EditorUIProps } from "../remix-ui-editor"
import { default as fixes } from "./quickfixes"
import { default as fixesList } from "./quickfixes"
export class RemixCodeActionProvider implements monaco.languages.CodeActionProvider {
props: EditorUIProps
@ -19,12 +19,12 @@ export class RemixCodeActionProvider implements monaco.languages.CodeActionProvi
): Promise<monaco.languages.CodeActionList> {
const actions: monaco.languages.CodeAction[] = []
for (const error of context.markers) {
let fix: Record<string, any>
let fixes: Record<string, any>[]
let msg: string
const errStrings: string[] = Object.keys(fixes)
const errStrings: string[] = Object.keys(fixesList)
const errStr:string = errStrings.find(es => error.message.includes(es))
if (errStr) {
fix = fixes[errStr]
fixes = fixesList[errStr]
const cursorPosition: number = this.props.editorAPI.getHoverPosition({lineNumber: error.startLineNumber, column: error.startColumn})
const nodeAtPosition = await this.props.plugin.call('codeParser', 'definitionAtPosition', cursorPosition)
// Check if a function is hovered
@ -33,20 +33,39 @@ export class RemixCodeActionProvider implements monaco.languages.CodeActionProvi
if (nodeAtPosition.parameters && !Array.isArray(nodeAtPosition.parameters) && Array.isArray(nodeAtPosition.parameters.parameters)) {
const paramNodes = nodeAtPosition.parameters.parameters
// If method has parameters
if (paramNodes.length) msg = await this.fixForMethodWithParams(model, paramNodes, fix, error, true)
else msg = await this.fixForMethodWithoutParams(model, nodeAtPosition, fix, error, true)
if (paramNodes.length) {
for (const fix of fixes) {
msg = await this.fixForMethodWithParams(model, paramNodes, fix, error, true)
this.addQuickFix(actions, error, model.uri, {title: fix.title, range: fix.range, text: msg})
}
} else {
for (const fix of fixes) {
msg = await this.fixForMethodWithoutParams(model, nodeAtPosition, fix, error, true)
this.addQuickFix(actions, error, model.uri, {title: fix.title, range: fix.range, text: msg})
}
}
} else {
const paramNodes = nodeAtPosition.parameters
// If method has parameters
if (paramNodes.length) msg = await this.fixForMethodWithParams(model, paramNodes, fix, error, false)
else msg = await this.fixForMethodWithoutParams(model, nodeAtPosition, fix, error, false)
if (paramNodes.length) {
for (const fix of fixes) {
msg = await this.fixForMethodWithParams(model, paramNodes, fix, error, false)
this.addQuickFix(actions, error, model.uri, {title: fix.title, range: fix.range, text: msg})
}
} else {
for (const fix of fixes) {
msg = await this.fixForMethodWithoutParams(model, nodeAtPosition, fix, error, false)
this.addQuickFix(actions, error, model.uri, {title: fix.title, range: fix.range, text: msg})
}
}
}
} else if (fix && nodeAtPosition && fix.nodeType !== nodeAtPosition.nodeType) return
if (Array.isArray(fix))
for (const element of fix)
this.addQuickFix(actions, error, model.uri, {title: element.title, range: element.range || error, text: msg || element.message})
else this.addQuickFix(actions, error, model.uri, {title: fix.title, range: fix.range || error, text: msg || fix.message})
}
} else {
for (const fix of fixes) {
if (fix && nodeAtPosition && fix.nodeType !== nodeAtPosition.nodeType) continue
else this.addQuickFix(actions, error, model.uri, {title: fix.title, range: fix.range || error, text: fix.message})
}
}
}
}
return {

@ -10,7 +10,7 @@ export default {
"title": "Add non-open-source license",
"message": "// SPDX-License-Identifier: UNLICENSED"
}],
"Warning: Source file does not specify required compiler version! Consider adding" : {
"Warning: Source file does not specify required compiler version! Consider adding" : [{
"id": 2,
"title": "Add Solidity pragma",
"message": "pragma solidity ^0.*.*;",
@ -21,23 +21,23 @@ export default {
startColumn: 1,
endColumn: 1
}
},
"SyntaxError: No visibility specified. Did you intend to add \"public\"": {
}],
"SyntaxError: No visibility specified. Did you intend to add \"public\"": [{
"id": 3,
"title": "Add visibility 'public'",
"message": "public ",
"nodeType": "FunctionDefinition"
},
"Warning: Function state mutability can be restricted to view": {
}],
"Warning: Function state mutability can be restricted to view": [{
"id": 4,
"title": "Add mutability 'view'",
"message": "view ",
"nodeType": "FunctionDefinition"
},
"Warning: Function state mutability can be restricted to pure": {
}],
"Warning: Function state mutability can be restricted to pure": [{
"id": 5,
"title": "Add mutability 'pure'",
"message": "pure ",
"nodeType": "FunctionDefinition"
}
}]
}
Loading…
Cancel
Save