Skip to content

Commit

Permalink
wip: rplugin draft
Browse files Browse the repository at this point in the history
  • Loading branch information
luckasRanarison committed Aug 3, 2024
1 parent f96222d commit 13f3742
Show file tree
Hide file tree
Showing 4 changed files with 357 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
293 changes: 293 additions & 0 deletions rplugin/node/tailwind-tools/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions rplugin/node/tailwind-tools/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "tailwind-tools",
"version": "1.0.0",
"description": "tailwind-tools.nvim NodeJS remote plugin",
"keywords": [
"tailwindcss",
"neovim"
],
"license": "MIT",
"author": "LIOKA Ranarison Fiderana",
"repository": {
"type": "git",
"url": "git+https://github.com/luckasRanarison/tailwind-tools.nvim.git"
},
"bugs": {
"url": "https://github.com/luckasRanarison/tailwind-tools.nvim/issues"
},
"homepage": "https://github.com/luckasRanarison/tailwind-tools.nvim#readme",
"main": "src/index.js",
"dependencies": {
"neovim": "^5.1.0"
}
}
40 changes: 40 additions & 0 deletions rplugin/node/tailwind-tools/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const fs = require("fs");
const path = require("path");

class Plugin {
/**
* @param {import("neovim").NvimPlugin} plugin
*/
constructor(plugin) {
this.nvim = plugin.nvim;

// TODO: Register VimL functions for:
// - Returning the processed config entries
// - Expanding the classname to css

plugin.registerFunction("GetTailwindConfig", this.getRawConfig.bind(this), {
sync: true,
});
}

async getRawConfig() {
const cwd = await this.nvim.call("getcwd");
const tailwindPath = path.join(cwd, "node_modules/tailwindcss");

if (!fs.existsSync(tailwindPath)) return;

const resolveFnPath = path.join(tailwindPath, "resolveConfig");
const resolveConfig = require(resolveFnPath);
const projectConfigPath = path.join(cwd, "tailwind.config.js");

let projectConfig = {};

if (fs.existsSync(projectConfigPath)) {
projectConfig = await import(projectConfigPath);
}

return resolveConfig(projectConfig.default ?? projectConfig);
}
}

module.exports = Plugin;

0 comments on commit 13f3742

Please sign in to comment.