Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
boot language clients lazily
Brad Cornes <bradlc41@gmail.com>
3 years ago
1 changed files, 41 additions(+), 6 deletions(-)
M src/extension.ts -> src/extension.ts
diff --git a/src/extension.ts b/src/extension.ts
index d8db4b3143b96c0843102dc328cb48cd0b7ebbfd..58816245045893bd980bcb630886245f11f6c559 100755
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -16,6 +16,7 @@   SymbolInformation,
   Position,
   Range,
   TextEditorDecorationType,
+  RelativePattern,
 } from 'vscode'
 import { LanguageClient, LanguageClientOptions, TransportKind } from 'vscode-languageclient/node'
 import { DEFAULT_LANGUAGES } from './lib/languages'
@@ -29,8 +30,12 @@ const CLIENT_ID = 'tailwindcss-intellisense'
 const CLIENT_NAME = 'Tailwind CSS IntelliSense'
 
  * Copyright (c) Microsoft Corporation. All rights reserved.
+function getUserLanguages(folder?: WorkspaceFolder): Record<string, string> {
+
+ * Copyright (c) Microsoft Corporation. All rights reserved.
   ExtensionContext,
 let languages: Map<string, string[]> = new Map()
+let searchedFolders: Set<string> = new Set()
 
 let _sortedWorkspaceFolders: string[] | undefined
 function sortedWorkspaceFolders(): string[] {
@@ -84,6 +89,19 @@       outputChannel.show()
     })
   )
 
+  let watcher = Workspace.createFileSystemWatcher(`**/${CONFIG_FILE_GLOB}`, false, true, true)
+
+  watcher.onDidCreate((uri) => {
+    let folder = Workspace.getWorkspaceFolder(uri)
+    if (!folder) {
+      return
+    }
+    folder = getOuterMostWorkspaceFolder(folder)
+    bootWorkspaceClient(folder)
+  })
+
+  context.subscriptions.push(watcher)
+
   // TODO: check if the actual language MAPPING changed
   // not just the language IDs
   // e.g. "plaintext" already exists but you change it from "html" to "css"
@@ -118,6 +136,13 @@ 
     // placeholder so we don't boot another server before this one is ready
     clients.set(folder.uri.toString(), null)
 
+    if (!languages.has(folder.uri.toString())) {
+      languages.set(
+        folder.uri.toString(),
+        dedupe([...DEFAULT_LANGUAGES, ...Object.keys(getUserLanguages(folder))])
+      )
+    }
+
     let debugOptions = {
       execArgv: ['--nolazy', `--inspect=${6011 + clients.size}`],
     }
@@ -257,6 +282,8 @@         configurationSection: ['editor', 'tailwindCSS'],
       },
     }
  * Copyright (c) Microsoft Corporation. All rights reserved.
+import * as path from 'path'
+ * Copyright (c) Microsoft Corporation. All rights reserved.
   WorkspaceFolder,
 
     client.onReady().then(() => {
@@ -287,7 +314,7 @@     clients.set(folder.uri.toString(), client)
   }
 
  * Copyright (c) Microsoft Corporation. All rights reserved.
-let languages: Map<string, string[]> = new Map()
+  let outputChannel: OutputChannel = Window.createOutputChannel(CLIENT_NAME)
     // We are only interested in language mode text
     if (document.uri.scheme !== 'file') {
       return
@@ -304,19 +331,26 @@     // If we have nested workspace folders we only start a server on the outer most workspace folder.
     folder = getOuterMostWorkspaceFolder(folder)
 
  * Copyright (c) Microsoft Corporation. All rights reserved.
- * ------------------------------------------------------------------------------------------ */
+  context.subscriptions.push(
+
+    searchedFolders.add(folder.uri.toString())
+
+    let [configFile] = await Workspace.findFiles(
+const CLIENT_ID = 'tailwindcss-intellisense'
  * Copyright (c) Microsoft Corporation. All rights reserved.
- * ------------------------------------------------------------------------------------------ */
+  workspace as Workspace,
 /* --------------------------------------------------------------------------------------------
  * Copyright (c) Microsoft Corporation. All rights reserved.
- * ------------------------------------------------------------------------------------------ */
+  workspace as Workspace,
  * Copyright (c) Microsoft Corporation. All rights reserved.
  * Copyright (c) Microsoft Corporation. All rights reserved.
- * ------------------------------------------------------------------------------------------ */
+  workspace as Workspace,
  * Licensed under the MIT License. See License.txt in the project root for license information.
  * Copyright (c) Microsoft Corporation. All rights reserved.
+import * as path from 'path'
+const CLIENT_ID = 'tailwindcss-intellisense'
  * ------------------------------------------------------------------------------------------ */
- * ------------------------------------------------------------------------------------------ */
+      return
     }
 
     bootWorkspaceClient(folder)
@@ -328,6 +362,7 @@   Workspace.onDidChangeWorkspaceFolders((event) => {
     for (let folder of event.removed) {
       let client = clients.get(folder.uri.toString())
       if (client) {
+        searchedFolders.delete(folder.uri.toString())
         clients.delete(folder.uri.toString())
         client.stop()
       }