Giter VIP home page Giter VIP logo

nvim-rename-state's Introduction

nvim-rename-state

Rename the getter and a setter of a state hook in react/solidjs at the same time using :RenameState.

// Initial code
const [anchorEl, setAnchorEl] = useState(null)

// After renaming with `:RenameState` or `:RenameState anchor`
const [anchor, setAnchor] = useState(null)

Features

  • Leverages Treesitter (requires neovim >= 0.5.0).
  • Supports Javascript and Typescript files.
  • Supports React and Solid state hooks.

Installation

lazy.nvim

{ "olrtg/nvim-rename-state" }

packer.nvim

use { "olrtg/nvim-rename-state" }

vim-plug

Plug 'olrtg/nvim-rename-state'

Usage

Put your cursor in the row of the defined useState or createSignal hook and use:

:RenameState

Or if you want to pass the new name for the hook in advance:

:RenameState <new_name>

Contributing

All contributions are welcomed! Just open a pull request or an issue.

nvim-rename-state's People

Contributors

non25 avatar olrtg avatar

Stargazers

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

Watchers

 avatar

Forkers

non25

nvim-rename-state's Issues

Node gets renamed without counterpart

Hi again. ๐Ÿ˜
I've got latest neovim built from git.
Removed all extra plugins and configuration bits.

Plugin list
call plug#begin('~/.config/nvim/plugged')

Plug 'neovim/nvim-lspconfig'
Plug 'olrtg/nvim-rename-state'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}

call plug#end()
Configuration
local lspconfig = require('lspconfig')
local util = require('lspconfig/util')
local on_attach = function(client, bufnr)
  local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
  local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end

  require'completion'.on_attach();

  buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')

  local opts = { noremap=true, silent=true }
  buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
  buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
  buf_set_keymap('n', 'ga', '<Cmd>lua vim.lsp.buf.code_action()<CR>', opts)
  buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
  buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
  buf_set_keymap('n', 'gR', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
  buf_set_keymap('n', 'gc', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
end

lspconfig.tsserver.setup{
  on_attach = on_attach;
}

require'nvim-rename-state'.setup{}

require'nvim-treesitter.configs'.setup {
  indent = {
    enable = false
  },
  highlight = {
    enable = false
  },
  incremental_selection = {
    enable = false,
    keymaps = {
      init_selection = "gnn",
      node_incremental = "grn",
      scope_incremental = "grc",
      node_decremental = "grm",
    },
  },
}

Would be cool to know how I could debug this further. ๐Ÿ˜
Thanks.

More flexible functions

I have just tried this plugin and it works nicely and I am sure I will use it a lot when using react.

I think I need some more functions to be available, such as:

:RenameStateEmpty: Renaming a state but the prompt is empty when starting to write

Or

:RenmaeState <new name>: be able to type the new variable name after the name of the command.

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.