Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
make diagnostics settings language-overridable
Brad Cornes <bradlc41@gmail.com>
4 years ago
9 changed files, 60 additions(+), 27 deletions(-)
M package.json -> package.json
diff --git a/package.json b/package.json
index 4b0281dc8823a7d9debcbff853c4ca088be2206f..9b33935cb0d07ddb3bcfc6dad66c97aa34babdf2 100755
--- a/package.json
+++ b/package.json
@@ -73,7 +73,8 @@         },
         "tailwindCSS.validate": {
           "type": "boolean",
           "default": true,
-          "markdownDescription": ""
+          "markdownDescription": "",
+          "scope": "language-overridable"
         },
         "tailwindCSS.lint.utilityConflicts": {
           "type": "string",
@@ -83,7 +84,8 @@             "warning",
             "error"
           ],
           "default": "warning",
-          "markdownDescription": ""
+          "markdownDescription": "",
+          "scope": "language-overridable"
         },
         "tailwindCSS.lint.unsupportedApply": {
           "type": "string",
@@ -93,7 +95,8 @@             "warning",
             "error"
           ],
           "default": "error",
-          "markdownDescription": ""
+          "markdownDescription": "",
+          "scope": "language-overridable"
         },
         "tailwindCSS.lint.unknownScreen": {
           "type": "string",
@@ -103,7 +106,8 @@             "warning",
             "error"
           ],
           "default": "error",
-          "markdownDescription": ""
+          "markdownDescription": "",
+          "scope": "language-overridable"
         },
         "tailwindCSS.lint.unknownVariant": {
           "type": "string",
@@ -113,7 +117,8 @@             "warning",
             "error"
           ],
           "default": "error",
-          "markdownDescription": ""
+          "markdownDescription": "",
+          "scope": "language-overridable"
         },
         "tailwindCSS.lint.unknownConfigKey": {
           "type": "string",
@@ -123,7 +128,8 @@             "warning",
             "error"
           ],
           "default": "error",
-          "markdownDescription": ""
+          "markdownDescription": "",
+          "scope": "language-overridable"
         },
         "tailwindCSS.lint.unsupportedTailwindDirective": {
           "type": "string",
@@ -133,7 +139,8 @@             "warning",
             "error"
           ],
           "default": "error",
-          "markdownDescription": ""
+          "markdownDescription": "",
+          "scope": "language-overridable"
         }
       }
     }
M src/extension.ts -> src/extension.ts
diff --git a/src/extension.ts b/src/extension.ts
index be1fe479cac88456c5893e28a533d1c3c2ec81ca..279ec969590ba1e30120474c179722fa450c238d 100755
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -11,6 +11,7 @@   TextDocument,
   OutputChannel,
   WorkspaceFolder,
   Uri,
+  ConfigurationScope,
 } from 'vscode'
 import {
   LanguageClient,
@@ -22,6 +23,7 @@ import { DEFAULT_LANGUAGES } from './lib/languages'
 import isObject from './util/isObject'
 import { dedupe, equal } from './util/array'
 import { createEmitter } from './lib/emitter'
+import { onMessage } from './lsp/notifications'
 
 const CLIENT_ID = 'tailwindcss-intellisense'
 const CLIENT_NAME = 'Tailwind CSS IntelliSense'
@@ -150,6 +152,9 @@ 
     client.onReady().then(() => {
       let emitter = createEmitter(client)
       registerConfigErrorHandler(emitter)
+      onMessage(client, 'getConfiguration', async (scope) => {
+        return Workspace.getConfiguration('tailwindCSS', scope)
+      })
     })
 
     client.start()
M src/lib/emitter.ts -> src/lib/emitter.ts
diff --git a/src/lib/emitter.ts b/src/lib/emitter.ts
index d177c2cf355a60b5c265fb5df12b01e0feb0ffb6..3ad6f05f010872359a4d0a2ef289456f37d74490 100644
--- a/src/lib/emitter.ts
+++ b/src/lib/emitter.ts
@@ -1,6 +1,7 @@
 import mitt from 'mitt'
 import { LanguageClient } from 'vscode-languageclient'
 import crypto from 'crypto'
+import { Connection } from 'vscode-languageserver'
 
 export interface NotificationEmitter {
   on: (name: string, handler: (args: any) => void) => void
@@ -8,7 +9,9 @@   off: (name: string, handler: (args: any) => void) => void
   emit: (name: string, args: any) => Promise<any>
 }
 
-export function createEmitter(client: LanguageClient): NotificationEmitter {
+export function createEmitter(
+  client: LanguageClient | Connection
+): NotificationEmitter {
   const emitter = mitt()
   const registered: string[] = []
 
@@ -26,7 +29,7 @@   const off = (name: string, handler: (args: any) => void) => {
     emitter.off(name, handler)
   }
 
-  const emit = (name: string, params: any) => {
+  const emit = (name: string, params: Record<string, any> = {}) => {
     return new Promise((resolve, _reject) => {
       const id = crypto.randomBytes(16).toString('hex')
       on(`${name}Response`, (result) => {
M src/lsp/notifications.ts -> src/lsp/notifications.ts
diff --git a/src/lsp/notifications.ts b/src/lsp/notifications.ts
index bb4e60dc496922fe1221147ff41a690e5f60d344..e8f4ab856ac0c1a8e4809e78761fb53640488742 100644
--- a/src/lsp/notifications.ts
+++ b/src/lsp/notifications.ts
@@ -1,9 +1,10 @@
 import { Connection } from 'vscode-languageserver'
+import { LanguageClient } from 'vscode-languageclient'
 
 export function onMessage(
-  connection: Connection,
+  connection: LanguageClient | Connection,
   name: string,
-  handler: (params: any) => any
+  handler: (params: any) => Thenable<Record<string, any>>
 ): void {
   connection.onNotification(`tailwindcss/${name}`, async (params: any) => {
     const { _id, ...rest } = params
M src/lsp/providers/completionProvider.ts -> src/lsp/providers/completionProvider.ts
diff --git a/src/lsp/providers/completionProvider.ts b/src/lsp/providers/completionProvider.ts
index 6dbb1e7a8de391c327c00dee9b74fb0b1fe08c87..ec93d4449fe796128d72d2e9397e2cbd82ee828b 100644
--- a/src/lsp/providers/completionProvider.ts
+++ b/src/lsp/providers/completionProvider.ts
@@ -618,10 +618,10 @@ async function provideEmmetCompletions(
   state: State,
   { position, textDocument }: CompletionParams
 ): Promise<CompletionList> {
-  let settings = await getDocumentSettings(state, textDocument.uri)
-  if (settings.emmetCompletions !== true) return null
-
   let doc = state.editor.documents.get(textDocument.uri)
+
+  let settings = await getDocumentSettings(state, doc)
+  if (settings.emmetCompletions !== true) return null
 
   const syntax = isHtmlContext(state, doc, position)
     ? 'html'
M src/lsp/providers/diagnosticsProvider.ts -> src/lsp/providers/diagnosticsProvider.ts
diff --git a/src/lsp/providers/diagnosticsProvider.ts b/src/lsp/providers/diagnosticsProvider.ts
index bb59ff571ca903793d4eb34a45d4775e9e9beaca..42609a0f4a0506c419604a51314e932673959235 100644
--- a/src/lsp/providers/diagnosticsProvider.ts
+++ b/src/lsp/providers/diagnosticsProvider.ts
@@ -376,7 +376,7 @@ export async function provideDiagnostics(
   state: State,
   document: TextDocument
 ): Promise<void> {
-  const settings = await getDocumentSettings(state, document.uri)
+  const settings = await getDocumentSettings(state, document)
 
   const diagnostics: Diagnostic[] = settings.validate
     ? [
M src/lsp/server.ts -> src/lsp/server.ts
diff --git a/src/lsp/server.ts b/src/lsp/server.ts
index 9c9aa35e2c0098103aae31ebbd055c516e84127b..118c5a3c73f54271448abeb53192bc994b42a1da 100644
--- a/src/lsp/server.ts
+++ b/src/lsp/server.ts
@@ -27,9 +27,10 @@ import { provideHover } from './providers/hoverProvider'
 import { URI } from 'vscode-uri'
 import { getDocumentSettings } from './util/getDocumentSettings'
 import { provideDiagnostics } from './providers/diagnosticsProvider'
+import { createEmitter } from '../lib/emitter'
 
-let state: State = { enabled: false }
 let connection = createConnection(ProposedFeatures.all)
+let state: State = { enabled: false, emitter: createEmitter(connection) }
 let documents = new TextDocuments()
 let workspaceFolder: string | null
 
@@ -50,7 +51,7 @@ let globalSettings: Settings = defaultSettings
 let documentSettings: Map<string, Settings> = new Map()
 
 documents.onDidOpen((event) => {
-  getDocumentSettings(state, event.document.uri)
+  getDocumentSettings(state, event.document)
 })
 documents.onDidClose((event) => {
   documentSettings.delete(event.document.uri)
@@ -90,14 +91,23 @@       {
         // @ts-ignore
         onChange: (newState: State): void => {
           if (newState && !newState.error) {
-            state = { ...newState, enabled: true, editor: editorState }
+            state = {
+              ...newState,
+              enabled: true,
+              emitter: state.emitter,
+              editor: editorState,
+            }
             connection.sendNotification('tailwindcss/configUpdated', [
               state.configPath,
               state.config,
               state.plugins,
             ])
           } else {
-            state = { enabled: false, editor: editorState }
+            state = {
+              enabled: false,
+              emitter: state.emitter,
+              editor: editorState,
+            }
             if (newState && newState.error) {
               const payload: {
                 message: string
@@ -120,9 +130,14 @@       }
     )
 
     if (tailwindState) {
-      state = { enabled: true, editor: editorState, ...tailwindState }
+      state = {
+        enabled: true,
+        emitter: state.emitter,
+        editor: editorState,
+        ...tailwindState,
+      }
     } else {
-      state = { enabled: false, editor: editorState }
+      state = { enabled: false, emitter: state.emitter, editor: editorState }
     }
 
     return {
M src/lsp/util/getDocumentSettings.ts -> src/lsp/util/getDocumentSettings.ts
diff --git a/src/lsp/util/getDocumentSettings.ts b/src/lsp/util/getDocumentSettings.ts
index 3ee25bd837e498fad81958abf76ff085f54325fa..2f127de4cdbe2bdc3df6778c26e283ad1771cd01 100644
--- a/src/lsp/util/getDocumentSettings.ts
+++ b/src/lsp/util/getDocumentSettings.ts
@@ -1,19 +1,19 @@
 import { State, Settings } from './state'
+import { TextDocument } from 'vscode-languageserver'
 
 export async function getDocumentSettings(
   state: State,
-  resource: string
+  document: TextDocument
 ): Promise<Settings> {
   if (!state.editor.capabilities.configuration) {
     return Promise.resolve(state.editor.globalSettings)
   }
-  let result = state.editor.documentSettings.get(resource)
+  let result = state.editor.documentSettings.get(document.uri)
   if (!result) {
-    result = await state.editor.connection.workspace.getConfiguration({
-      scopeUri: resource,
-      section: 'tailwindCSS',
+    result = await state.emitter.emit('getConfiguration', {
+      languageId: document.languageId,
     })
-    state.editor.documentSettings.set(resource, result)
+    state.editor.documentSettings.set(document.uri, result)
   }
   return result
 }
M src/lsp/util/state.ts -> src/lsp/util/state.ts
diff --git a/src/lsp/util/state.ts b/src/lsp/util/state.ts
index aa9e0f514a04fb931875f178fb6a48bdb4a2e085..5d7e4f490486aafcac67675cdb0c1794f19f0de8 100644
--- a/src/lsp/util/state.ts
+++ b/src/lsp/util/state.ts
@@ -1,4 +1,5 @@
 import { TextDocuments, Connection, Range } from 'vscode-languageserver'
+import { NotificationEmitter } from '../../lib/emitter'
 
 export type ClassNamesTree = {
   [key: string]: ClassNamesTree
@@ -43,6 +44,7 @@ }
 
 export type State = null | {
   enabled: boolean
+  emitter: NotificationEmitter
   version?: string
   configPath?: string
   config?: any