Giter Club home page Giter Club logo

coc-react-refactor's Introduction

coc-react-refactor

React refactor extension for coc.nvim, forked from vscode-react-refactor.

This extension is sponsored by @James Zhang for developing, thank you.

coc-react-refactor

Install

:CocInstall coc-react-refactor

Usage

xmap <leader>a  <Plug>(coc-codeaction-selected)
nmap <leader>a  <Plug>(coc-codeaction-selected)

Configuration

  • react-refactor.produceClass: Create a class-based component, will create a function component when disabled, only works for Extract to file, default true

License

MIT


This extension is created by create-coc-extension

coc-react-refactor's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar fannheyward avatar lgtm-com[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

coc-react-refactor's Issues

Both "extract to function" and "extract to file" failed

I can't get any of the aforementioned functions to work, here's my CocInfo log:

## versions

vim version: NVIM v0.5.0-710-gb9ceac465
node version: v14.12.0
coc.nvim version: 0.0.79-be822b546f
coc.nvim directory: /home/user/.config/nvim/plug.vim/coc.nvim
term: xterm-kitty
platform: linux

## Log of coc.nvim

2020-11-09T09:33:33.113 ERROR (pid:962707) [extension:coc-react-refactor] - Extract JSX to function: TypeError: coc_nvim_1.workspace.requestInput is not a function
    at Object.exports.askForName (/home/user/.config/coc/extensions/node_modules/coc-react-refactor/lib/index.js:75232:45)
    at exports.extractToFunction (/home/user/.config/coc/extensions/node_modules/coc-react-refactor/lib/index.js:69634:36)
    at CommandItem.execute (/home/user/.config/nvim/plug.vim/coc.nvim/build/index.js:24057:21)
    at CommandManager.executeCommand (/home/user/.config/nvim/plug.vim/coc.nvim/build/index.js:24395:44)
    at CommandManager.execute (/home/user/.config/nvim/plug.vim/coc.nvim/build/index.js:24335:29)
    at Handler.applyCodeAction (/home/user/.config/nvim/plug.vim/coc.nvim/build/index.js:89637:36)
    at Handler.doCodeAction (/home/user/.config/nvim/plug.vim/coc.nvim/build/index.js:89599:24)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Plugin.cocAction (/home/user/.config/nvim/plug.vim/coc.nvim/build/index.js:24009:16)
    at async NeovimClient.<anonymous> (/home/user/.config/nvim/plug.vim/coc.nvim/build/index.js:11597:21)
2020-11-09T09:33:43.847 INFO (pid:962707) [completion-complete] - Results from: around,snippets
2020-11-09T09:33:49.677 ERROR (pid:962707) [extension:coc-react-refactor] - Extract to file: TypeError: coc_nvim_1.workspace.requestInput is not a function
    at Object.exports.askForName (/home/user/.config/coc/extensions/node_modules/coc-react-refactor/lib/index.js:75232:45)
    at exports.extractToFile (/home/user/.config/coc/extensions/node_modules/coc-react-refactor/lib/index.js:69674:36)
    at CommandItem.execute (/home/user/.config/nvim/plug.vim/coc.nvim/build/index.js:24057:21)
    at CommandManager.executeCommand (/home/user/.config/nvim/plug.vim/coc.nvim/build/index.js:24395:44)
    at CommandManager.execute (/home/user/.config/nvim/plug.vim/coc.nvim/build/index.js:24335:29)
    at Handler.applyCodeAction (/home/user/.config/nvim/plug.vim/coc.nvim/build/index.js:89637:36)
    at Handler.doCodeAction (/home/user/.config/nvim/plug.vim/coc.nvim/build/index.js:89599:24)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Plugin.cocAction (/home/user/.config/nvim/plug.vim/coc.nvim/build/index.js:24009:16)
    at async NeovimClient.<anonymous> (/home/user/.config/nvim/plug.vim/coc.nvim/build/index.js:11597:21)

feat: `productClass` setting

Would be great if produceClass could be a configurable setting so something like "Extract to file" can create a function component instead of class-based component.

Doesn't work with external browserslist definition

I got a project where in package.json we have a "browserslist": "extends @someorg/browserslist-config" definition.

coc-react-refactor dies with Error: Cannot find module '@someorg/browserslist-config'. I assume this has to do with the bundling strategy of using webpack for the package.

Encountered a similar issue with Next.js, this is how it was solved there: vercel/next.js#33890

Error: babel.config.js: Error while loading config - Cannot find module

2020-09-06T18:23:14.054 ERROR (pid:849114) [extension:coc-react-refactor] - Extract JSX to function: Error: /home/hoschi/repos/eg/boilerplate/babel.config.js: Error while loading config - Cannot find module '/home/hoschi/repos/eg/boilerplate/babel.config.js'
    at webpackEmptyContext (/home/hoschi/.config/coc/extensions/node_modules/coc-react-refactor/lib/index.js:60138:10)
    at loadCjsDefault (/home/hoschi/.config/coc/extensions/node_modules/coc-react-refactor/lib/index.js:60072:42)
    at loadCjsOrMjsDefault (/home/hoschi/.config/coc/extensions/node_modules/coc-react-refactor/lib/index.js:60044:16)
    at loadCjsOrMjsDefault.next (<anonymous>)
    at readConfigJS (/home/hoschi/.config/coc/extensions/node_modules/coc-react-refactor/lib/index.js:58367:47)
    at readConfigJS.next (<anonymous>)
    at Function.<anonymous> (/home/hoschi/.config/coc/extensions/node_modules/coc-react-refactor/lib/index.js:58005:3)
    at Generator.next (<anonymous>)
    at evaluateSync (/home/hoschi/.config/coc/extensions/node_modules/coc-react-refactor/lib/index.js:57850:28)
    at Function.sync (/home/hoschi/.config/coc/extensions/node_modules/coc-react-refactor/lib/index.js:57690:14) {
  code: 'MODULE_NOT_FOUND'
}

I get this on the easiest refactorings. My babel.config.js:

module.exports = {
    presets: ["babel-preset-react-app"],
    plugins: [
        [
            "react-intl",
            {
                extractFromFormatMessageCall: true,
                idInterpolationPattern: "[sha512:contenthash:base64:6]",
            },
        ],
    ],
    env: {
        test: {
            plugins: ["mockable-imports"],
        },
        production: {
            plugins: [
                [
                    "babel-plugin-import",
                    {
                        libraryName: "@material-ui/core",
                        libraryDirectory: "esm",
                        camel2DashComponentName: false,
                    },
                    "core",
                ],
                [
                    "babel-plugin-import",
                    {
                        libraryName: "@material-ui/icons",
                        libraryDirectory: "esm",
                        camel2DashComponentName: false,
                    },
                    "icons",
                ],
                [
                    "babel-plugin-import",
                    {
                        libraryName: "ramda",
                        libraryDirectory: "es",
                        camel2DashComponentName: false,
                    },
                    "ramda",
                ],
            ],
        },
    },
}

"extract to function" and "extract to file" failed

related to #37 / #38 .
I'm using NeoVim v0.4.4

I'm trying to use this extension, but I keep getting same issue.
I'm using latest version coc.nvim and coc-react-refactor.
I have tried both release branch and master branch of coc.nvim.
I also tried this configuration.

"coc.preferences.promptInput": false

but, it's still not working.
Is there any solutions?

Extract to file failed

Thank you for this extension!

I'm trying to use it, but I keep getting Extract to file failed. Any idea why that might be? I have also seen E21 cannot make changes modifiable is off I turned it on with :set ma but that didn't seem to do the trick.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.