From 130e8ee5f5594c18683d6c38a9727093fb4e4d92 Mon Sep 17 00:00:00 2001
From: Hamadah2O2
Date: Thu, 11 Jul 2024 22:12:17 +0700
Subject: [PATCH 1/6] add find css on current working directory
---
src/completion.ts | 9 +++++++++
src/findCss.ts | 23 +++++++++++++++++++++++
2 files changed, 32 insertions(+)
create mode 100644 src/findCss.ts
diff --git a/src/completion.ts b/src/completion.ts
index d599286..963fedd 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.toString());
+ 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;
+}
From c01286eb5438c81088e71fc2bf53dc5946ce17a2 Mon Sep 17 00:00:00 2001
From: Hamadah2O2
Date: Thu, 11 Jul 2024 22:23:42 +0700
Subject: [PATCH 2/6] fix uri error
---
src/completion.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/completion.ts b/src/completion.ts
index 963fedd..6100580 100644
--- a/src/completion.ts
+++ b/src/completion.ts
@@ -160,7 +160,7 @@ export class SelectorCompletionItemProvider implements CompletionItemProvider, D
}
async findWorkspace(uri: Uri, keys: Set): Promise {
- const files = getCssByFolder(uri.toString());
+ const files = getCssByFolder(uri.fsPath);
for (const key of files) {
keys.add(await this.fetch(uri, key));
}
From 401892f5f402d48e1fa255863e60410cb9187d0b Mon Sep 17 00:00:00 2001
From: Hamadah2O2
Date: Thu, 11 Jul 2024 22:49:16 +0700
Subject: [PATCH 3/6] add init.lua, autocmd dispose html-css-support
---
lua/coc-html-css-support/init.lua | 1 +
1 file changed, 1 insertion(+)
create mode 100644 lua/coc-html-css-support/init.lua
diff --git a/lua/coc-html-css-support/init.lua b/lua/coc-html-css-support/init.lua
new file mode 100644
index 0000000..44f3ef6
--- /dev/null
+++ b/lua/coc-html-css-support/init.lua
@@ -0,0 +1 @@
+vim.cmd([[autocmd BufWritePost *.css CocCommand html-css-support.dispose]])
From 6a948098da755069a7532a2aeef9af6e109a9345 Mon Sep 17 00:00:00 2001
From: Hamadah2O2
Date: Thu, 11 Jul 2024 22:56:13 +0700
Subject: [PATCH 4/6] fix: deleted lua, not working
---
lua/coc-html-css-support/init.lua | 1 -
1 file changed, 1 deletion(-)
delete mode 100644 lua/coc-html-css-support/init.lua
diff --git a/lua/coc-html-css-support/init.lua b/lua/coc-html-css-support/init.lua
deleted file mode 100644
index 44f3ef6..0000000
--- a/lua/coc-html-css-support/init.lua
+++ /dev/null
@@ -1 +0,0 @@
-vim.cmd([[autocmd BufWritePost *.css CocCommand html-css-support.dispose]])
From 0c748901e1b6efee646827ecc7899b352279690b Mon Sep 17 00:00:00 2001
From: Hamadah2O2
Date: Fri, 12 Jul 2024 09:09:40 +0700
Subject: [PATCH 5/6] updated: package.json
---
package.json | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
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",
From 02f7e028cf7a4ad56bd5c90d0aee09d0b3fc1200 Mon Sep 17 00:00:00 2001
From: Muhammad Rozaan <119121505+Hamadah2O2@users.noreply.github.com>
Date: Fri, 12 Jul 2024 09:13:32 +0700
Subject: [PATCH 6/6] Update README.md
---
README.md | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
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
## 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