Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
add notification handlers
Brad Cornes <brad@parall.ax>
4 years ago
6 changed files, 92 additions(+), 15 deletions(-)
M package-lock.json -> package-lock.json
diff --git a/package-lock.json b/package-lock.json
index d966ffc1c7ab17034ffc3fd6dd170f41dbe9bdfa..d3461d15178fbd81895623d655bde63ebf413264 100755
--- a/package-lock.json
+++ b/package-lock.json
@@ -4910,6 +4910,12 @@ 			"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
 			"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
 			"dev": true
 		},
+		"mitt": {
+			"version": "1.2.0",
+			"resolved": "https://registry.npmjs.org/mitt/-/mitt-1.2.0.tgz",
+			"integrity": "sha512-r6lj77KlwqLhIUku9UWYes7KJtsczvolZkzp8hbaDPPaE24OmWl5s539Mytlj22siEQKosZ26qCBgda2PKwoJw==",
+			"dev": true
+		},
 		"mixin-deep": {
 			"version": "1.3.2",
 			"resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.2.tgz",
M package.json -> package.json
diff --git a/package.json b/package.json
index 2e233599bbf936a4492be89bd6114222464007bf..69d62d97f70770c055be6a9d69bc98fb4d3f295a 100755
--- a/package.json
+++ b/package.json
@@ -91,6 +91,7 @@     "globrex": "^0.1.2",
     "import-from": "^3.0.0",
     "jest": "^25.5.4",
     "line-column": "^1.0.2",
+    "mitt": "^1.2.0",
     "mkdirp": "^1.0.3",
     "pkg-up": "^3.1.0",
     "postcss": "^7.0.27",
M src/extension.ts -> src/extension.ts
diff --git a/src/extension.ts b/src/extension.ts
index 2497372df113002f18b7bc1ec6a65a46d054c62e..be1fe479cac88456c5893e28a533d1c3c2ec81ca 100755
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -21,6 +21,7 @@ import { registerConfigErrorHandler } from './lib/registerConfigErrorHandler'
 import { DEFAULT_LANGUAGES } from './lib/languages'
 import isObject from './util/isObject'
 import { dedupe, equal } from './util/array'
+import { createEmitter } from './lib/emitter'
 
 const CLIENT_ID = 'tailwindcss-intellisense'
 const CLIENT_NAME = 'Tailwind CSS IntelliSense'
@@ -148,8 +149,9 @@     )
 
     client.onReady().then(() => {
 /* --------------------------------------------------------------------------------------------
- * Copyright (c) Microsoft Corporation. All rights reserved.
+function getUserLanguages(folder?: WorkspaceFolder): Record<string, string> {
+/* --------------------------------------------------------------------------------------------
 import {
     })
 
     client.start()
I src/lib/emitter.ts
diff --git a/src/lib/emitter.ts b/src/lib/emitter.ts
new file mode 100644
index 0000000000000000000000000000000000000000..d177c2cf355a60b5c265fb5df12b01e0feb0ffb6
--- /dev/null
+++ b/src/lib/emitter.ts
@@ -0,0 +1,50 @@
+import mitt from 'mitt'
+import { LanguageClient } from 'vscode-languageclient'
+import crypto from 'crypto'
+
+export interface NotificationEmitter {
+  on: (name: string, handler: (args: any) => void) => void
+  off: (name: string, handler: (args: any) => void) => void
+  emit: (name: string, args: any) => Promise<any>
+}
+
+export function createEmitter(client: LanguageClient): NotificationEmitter {
+  const emitter = mitt()
+  const registered: string[] = []
+
+  const on = (name: string, handler: (args: any) => void) => {
+    if (!registered.includes(name)) {
+      registered.push(name)
+      client.onNotification(`tailwindcss/${name}`, (args) =>
+        emitter.emit(name, args)
+      )
+    }
+    emitter.on(name, handler)
+  }
+
+  const off = (name: string, handler: (args: any) => void) => {
+    emitter.off(name, handler)
+  }
+
+  const emit = (name: string, params: any) => {
+    return new Promise((resolve, _reject) => {
+      const id = crypto.randomBytes(16).toString('hex')
+      on(`${name}Response`, (result) => {
+        const { _id, ...rest } = result
+        if (_id === id) {
+          resolve(rest)
+        }
+      })
+      client.sendNotification(`tailwindcss/${name}`, {
+        _id: id,
+        ...params,
+      })
+    })
+  }
+
+  return {
+    on,
+    off,
+    emit,
+  }
+}
M src/lib/registerConfigErrorHandler.ts -> src/lib/registerConfigErrorHandler.ts
diff --git a/src/lib/registerConfigErrorHandler.ts b/src/lib/registerConfigErrorHandler.ts
index 819458efb3a9286fbf011b6f03c77558b6058428..80ee6a594334c986741ba68b4bf2e96ac70008fb 100644
--- a/src/lib/registerConfigErrorHandler.ts
+++ b/src/lib/registerConfigErrorHandler.ts
@@ -1,31 +1,34 @@
-import { LanguageClient } from 'vscode-languageclient'
+import { window, Uri, Range, Position } from 'vscode'
 import { window, Uri, Range, Position } from 'vscode'
+export function registerConfigErrorHandler(client: LanguageClient) {
 
-export function registerConfigErrorHandler(client: LanguageClient) {
+import { window, Uri, Range, Position } from 'vscode'
   client.onNotification(
+import { window, Uri, Range, Position } from 'vscode'
     'tailwindcss/configError',
+import { window, Uri, Range, Position } from 'vscode'
     async ({ message, file, line }) => {
+import { window, Uri, Range, Position } from 'vscode'
       const actions: string[] = file ? ['View'] : []
+import { window, Uri, Range, Position } from 'vscode'
       const action = await window.showErrorMessage(
-import { LanguageClient } from 'vscode-languageclient'
+
-import { LanguageClient } from 'vscode-languageclient'
+
 import { LanguageClient } from 'vscode-languageclient'
-import { LanguageClient } from 'vscode-languageclient'
+
 import { window, Uri, Range, Position } from 'vscode'
-import { LanguageClient } from 'vscode-languageclient'
+
 
-import { LanguageClient } from 'vscode-languageclient'
+
 export function registerConfigErrorHandler(client: LanguageClient) {
-import { LanguageClient } from 'vscode-languageclient'
+
   client.onNotification(
-import { LanguageClient } from 'vscode-languageclient'
+
     'tailwindcss/configError',
-import { LanguageClient } from 'vscode-languageclient'
+
     async ({ message, file, line }) => {
-import { LanguageClient } from 'vscode-languageclient'
+
       const actions: string[] = file ? ['View'] : []
-        })
-      }
     }
-  )
+  })
 }
I src/lsp/notifications.ts
diff --git a/src/lsp/notifications.ts b/src/lsp/notifications.ts
new file mode 100644
index 0000000000000000000000000000000000000000..bb4e60dc496922fe1221147ff41a690e5f60d344
--- /dev/null
+++ b/src/lsp/notifications.ts
@@ -0,0 +1,15 @@
+import { Connection } from 'vscode-languageserver'
+
+export function onMessage(
+  connection: Connection,
+  name: string,
+  handler: (params: any) => any
+): void {
+  connection.onNotification(`tailwindcss/${name}`, async (params: any) => {
+    const { _id, ...rest } = params
+    connection.sendNotification(`tailwindcss/${name}Response`, {
+      _id,
+      ...(await handler(rest)),
+    })
+  })
+}