diff --git a/README.md b/README.md index bfd2653..363cd17 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,26 @@ # coc-html-css-support -> fork from a [ecmel/vscode-html-css](https://github.com/ecmel/vscode-html-css) | [HTML CSS Support](https://marketplace.visualstudio.com/items?itemName=ecmel.vscode-html-css) +> fork from a [ecmel/vscode-html-css](https://github.com/ecmel/vscode-html-css) | [HTML CSS Support](https://marketplace.visualstudio.com/items?itemName=ecmel.vscode-html-css) | and the origin [yaegassy/coc-html-css-support](https://github.com/yaegassy/coc-html-css-support) -HTML id and class attribute "completion" for [coc.nvim](https://github.com/neoclide/coc.nvim). +HTML id and class attribute "completion" for [coc.nvim](https://github.com/neoclide/coc.nvim). With on workspace css finding coc-html-css-support-demo ## Install -`:CocInstall coc-html-css-support` +### Using Lazy +```lua +{ + "Hamadah2O2/coc-html-css-support", + build = "yarn install --frozen-lockfile", + config = function() + vim.cmd([[autocmd BufWritePost *.css CocCommand html-css-support.dispose]]) -- Automate dispose html-css-support on css BufWritePost + end +} +``` + +### Using CocInstall command +`:CocInstall @hamadah2o2/coc-html-css-support` ## Features @@ -17,6 +29,7 @@ HTML id and class attribute "completion" for [coc.nvim](https://github.com/neocl - Supports template inheritance. - Supports additional style sheets. - Supports other HTML like languages. +- Supports style sheets finding on current working directory. - Command to make `html.customData` built-in in `coc-html-css-support` available at the workspace level. - Require [coc-html](https://github.com/neoclide/coc-html) @@ -75,7 +88,8 @@ You can read more about customData in the following repositories. ## Thanks -- [ecmel/vscode-html-css](https://github.com/ecmel/vscode-html-css) : The origin of this repository. +- [yaegassy/coc-html-css-support](https://github.com/yaegassy/coc-html-css-support) +- [ecmel/vscode-html-css](https://github.com/ecmel/vscode-html-css) : The origin of yaegassy/coc-html-css-support repository. ## License diff --git a/package.json b/package.json index 18656bd..8447194 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { - "name": "coc-html-css-support", - "version": "0.5.3", - "description": "HTML id and class attribute completion for coc.nvim", - "author": "yaegassy ", + "name": "@hamadah2o2/coc-html-css-support", + "version": "0.5.5", + "description": "HTML id and class attribute completion for coc.nvim, with workspace css finding", + "author": "Hamadah2O2", "license": "MIT", "main": "lib/index.js", "keywords": [ @@ -27,7 +27,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/yaegassy/coc-html-css-support" + "url": "https://github.com/Hamadah2O2/coc-html-css-support" }, "scripts": { "lint": "eslint src --ext ts", diff --git a/src/completion.ts b/src/completion.ts index d599286..6100580 100644 --- a/src/completion.ts +++ b/src/completion.ts @@ -15,6 +15,7 @@ import { import { parse, walk } from 'css-tree'; import fetch from 'node-fetch'; import { basename, dirname, extname, isAbsolute, join } from 'path'; +import { getCssByFolder } from './findCss'; export type Context = { ids: Map; @@ -158,6 +159,13 @@ export class SelectorCompletionItemProvider implements CompletionItemProvider, D } } + async findWorkspace(uri: Uri, keys: Set): Promise { + const files = getCssByFolder(uri.fsPath); + for (const key of files) { + keys.add(await this.fetch(uri, key)); + } + } + async findLinks(uri: Uri, keys: Set, text: string): Promise { const findLinks = /]+)>/gi; @@ -216,6 +224,7 @@ export class SelectorCompletionItemProvider implements CompletionItemProvider, D await this.findFixed(Uri.parse(uri), keys); await this.findLinks(Uri.parse(uri), keys, text); + await this.findWorkspace(Uri.parse(workspace.cwd), keys); await this.findInherited(Uri.parse(uri), keys, text); const ids = new Map(); diff --git a/src/findCss.ts b/src/findCss.ts new file mode 100644 index 0000000..438b755 --- /dev/null +++ b/src/findCss.ts @@ -0,0 +1,23 @@ +import fs from 'fs'; +import path from 'path'; + +export function getCssByFolder(folderPath: string, currentPath: string = '') { + const files = fs.readdirSync(folderPath); + let cssFiles: string[] = []; + + files.forEach((file) => { + const filePath = path.join(folderPath, file); + const stat = fs.lstatSync(filePath); + + if (stat.isDirectory()) { + const newCurrentPath = path.join(currentPath, file); + cssFiles = cssFiles.concat(getCssByFolder(filePath, newCurrentPath)); + } else { + if (file.endsWith('.css')) { + const relativePath = path.join(currentPath, file); + cssFiles.push(`/${relativePath}`); + } + } + }); + return cssFiles; +}