GithubHelp home page GithubHelp logo

jcha0713 / cmp-tw2css Goto Github PK

View Code? Open in Web Editor NEW
54.0 2.0 1.0 2.22 MB

A source for nvim-cmp to convert tailwindcss classes to pure css codes

License: MIT License

Lua 100.00%
neovim neovim-plugin nvim nvim-cmp

cmp-tw2css's Introduction

cmp-tw2css

A source for nvim-cmp to convert tailwindcss classes to pure css codes. It uses treesitter to find out whether any css code block exists in the code and loads the completion source.

Setup

Prerequisites:

cmp-tw2css uses nvim-cmp to provide the code. You first need to have nvim-cmp installed in your neovim. To install nvim-cmp, please visit the nvim-cmp Github repo.

Since version 1.0.0, cmp-tw2css uses css parser to detect if the cursor is inside the css code block. To fully use this feature, you need to install the css parser through nvim-treesitter. For more information, please refer to nvim-treesitter.

Installation

To install cmp-tw2css, I recommend using packer.nvim.

use({
  "hrsh7th/nvim-cmp",
  requires = {
    "jcha0713/cmp-tw2css",
  },
})

And to add source, go to nvim-cmp configuration and add the following

require('cmp').setup {
  -- ...
  sources = {
    { name = 'cmp-tw2css' },
    -- other sources ...
  },
  -- ...
}

Usage

Using cmp-tw2css is simple. Open any file that contains css code blocks and start typing tailwindcss classes that you want to convert into css codes.

Example

demo

  • *.css:
body {
  /* flex -> display: flex; */
  /* p-6 -> padding: 1.5rem; */
  /* ... */
}
  • *.html:
<!DOCTYPE html>
<html lang="en">
  <head>
    <style>
      body {
        /* m-2 -> margin: 0.5rem; */
      }
    </style>
  </head>
  <body>
    <!-- body -->
  </body>
</html>

Configuration

require('cmp-tw2css').setup({ ... })

fallback

type: boolean default: true

{
  fallback = true
}

Determines whether to load the completion items when there is no treesitter parser. If this is set to true, you are allowing cmp-tw2css to load the completion items regardless of your cursor position. If it is set to false, then it simply does not load anything when there is no css parser.

Limitation

There are a number of limitations to cmp-tw2css. First, the source of this plugin is a result of web scraping. This means that you might find some items are missing while using. If this happens to you, please let me know by submitting an issue so that I can update the source accordingly. Another downside is that it can't be dynamically generated and only provides the code from the official website.

Currently cmp-tw2css does not automatically add tabs for the additional lines when the insert text is more than one line. And also when there are more than one colon(:) in a line, cmp-tw2css cannot properly load its completion source.

Roadmap

  • Load the source only when the cursor is inside the code block
  • Provide ways to configure with treesitter
  • Show documentation when selecting an item
  • Provide the completion source using LSP functionality

Credit

cmp-tw2css's People

Contributors

akianonymus avatar jcha0713 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

Watchers

 avatar  avatar

Forkers

akianonymus

cmp-tw2css's Issues

Trying to use inside ts/js files.

Hey, I'm trying to modify this plugin for my personal use, for work with styled, I've already changed for work in typescript files, but I don't know where I need to change, to stop recognizes only inside CSS elements, like body {}, it's possible to do that?

If you can help me with that, if not, it's okay! :)

treesitter error in typescriptreact filetype

I'm not sure if this is a treesitter issue, but I was able to realize that this plugin was causing the error

image

Error detected while processing TextChangedI Autocommands for "<buffer=10>":                                                                                                                                                                  
Error executing lua callback: ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:94: no parser for 'typescriptreact' language, see :help treesitter-parsers                                                                          
stack traceback:                                                                                                                                                                                                                              
        [C]: in function 'error'                                                                                                                                                                                                              
        ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:94: in function 'add'                                                                                                                                                     
        ...l/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:98: in function 'new'                                                                                                                                                     
        /usr/local/share/nvim/runtime/lua/vim/treesitter.lua:61: in function '_create_parser'                                                                                                                                                 
        /usr/local/share/nvim/runtime/lua/vim/treesitter.lua:131: in function 'get_parser'                                                                                                                                                    
        /usr/local/share/nvim/runtime/lua/vim/treesitter.lua:398: in function 'get_cusor_node'                                                                                                                                                
        ...start/template-string.nvim/lua/template-string/utils.lua:21: in function 'get_string_node'                                                                                                                                         
        ...ate-string.nvim/lua/template-string/langs/javascript.lua:110: in function 'on_type'                                                                                                                                                
        .../start/template-string.nvim/lua/template-string/init.lua:14: in function <.../start/template-string.nvim/lua/template-string/init.lua:8>

I tried :setfiletype typescript, and the error was gone, this is as far as I could go.

Update the source

TailwindCSS had a recent update to v3.2.
The completion source needs to be updated accordingly.

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.