Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
Fix language server initialisation outside of VS Code (#803) * Remove buggy await call This is to resolve issue https://github.com/tailwindlabs/tailwindcss-intellisense/issues/802 * Fix unhandled method errors --------- Co-authored-by: Brad Cornes <hello@bradley.dev>
Signature
-----BEGIN PGP SIGNATURE----- wsBcBAABCAAQBQJk5JtNCRBK7hj4Ov3rIwAATYMIAHxHYaMDdKjyPSOuLFX7OP8F WxRrzzayGhX2Hf+3/O7BF1AWH9FErRVSNOq0DDQ0NgZqmViKEC3O/4IB+/RaefqO j8OX+RNWrTI0y1Zr2bErEA2UoNay+dmOnPu5nG5sfepOakO0SHEdRuSXMVsoBrcr pC9YYttjg3ofQmg+sNQ8EKUhyGDIY0xanb1UdKQHyBTy4EnU7+Ibnn8Pu0GU7jCD uCyIOpqjzckmrEvznJyM1z9YTMqNSqX+qocK7YCJanFhvE47CfRm7jI+YCkloIcH mf+9V59nEb6qu0hQi74Ff1oGGJQQtxZmTFA0I8i3LtqNGzHmsQ/aZ3ymcHR/TYQ= =R39b -----END PGP SIGNATURE-----
atgote <ifrit2004@mail.ru>
2 years ago
1 changed files, 25 additions(+), 12 deletions(-)
packages/tailwindcss-language-server/src/server.ts
M packages/tailwindcss-language-server/src/server.tspackages/tailwindcss-language-server/src/server.ts
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
diff --git a/packages/tailwindcss-language-server/src/server.ts b/packages/tailwindcss-language-server/src/server.ts
index c4a844d6c208c7dc4024607299163765f5300ef3..24a191e8c652296f238d4fd9413f05f12233e8d1 100644
--- a/packages/tailwindcss-language-server/src/server.ts
+++ b/packages/tailwindcss-language-server/src/server.ts
@@ -1611,7 +1611,7 @@     }))
 }
 
 class TW {
-  private initialized = false
+  private initPromise: Promise<void>
   private lspHandlersAdded = false
   private workspaces: Map<string, { name: string; workspaceFsPath: string }>
   private projects: Map<string, ProjectService>
@@ -1631,11 +1631,14 @@     this.projectCounter = 0
   }
 
   async init(): Promise<void> {
-    if (this.initialized) return
+    if (!this.initPromise) {
+      this.initPromise = this._init()
+    }
+    await this.initPromise
+  }
 
+  private async _init(): Promise<void> {
     clearRequireCache()
-
-    this.initialized = true
 
     let base: string
     if (this.initializeParams.rootUri) {
@@ -2131,7 +2134,7 @@       }
     }
   }
 
-  private setupLSPHandlers() {
+  setupLSPHandlers() {
     if (this.lspHandlersAdded) {
       return
     }
@@ -2147,6 +2150,10 @@     this.connection.onDocumentLinks(this.onDocumentLinks.bind(this))
   }
 
   private updateCapabilities() {
+    if (!supportsDynamicRegistration(this.initializeParams)) {
+      return
+    }
+
     if (this.registrations) {
       this.registrations.then((r) => r.dispose())
     }
@@ -2221,30 +2228,37 @@     return fallbackProject
   }
 
   async onDocumentColor(params: DocumentColorParams): Promise<ColorInformation[]> {
+    await this.init()
     return this.getProject(params.textDocument)?.onDocumentColor(params) ?? []
   }
 
   async onColorPresentation(params: ColorPresentationParams): Promise<ColorPresentation[]> {
+    await this.init()
     return this.getProject(params.textDocument)?.onColorPresentation(params) ?? []
   }
 
   async onHover(params: TextDocumentPositionParams): Promise<Hover> {
+    await this.init()
     return this.getProject(params.textDocument)?.onHover(params) ?? null
   }
 
   async onCompletion(params: CompletionParams): Promise<CompletionList> {
+    await this.init()
     return this.getProject(params.textDocument)?.onCompletion(params) ?? null
   }
 
   async onCompletionResolve(item: CompletionItem): Promise<CompletionItem> {
+    await this.init()
     return this.projects.get(item.data?._projectKey)?.onCompletionResolve(item) ?? null
   }
 
-  onCodeAction(params: CodeActionParams): Promise<CodeAction[]> {
+  async onCodeAction(params: CodeActionParams): Promise<CodeAction[]> {
+    await this.init()
     return this.getProject(params.textDocument)?.onCodeAction(params) ?? null
   }
 
-  onDocumentLinks(params: DocumentLinkParams): DocumentLink[] {
+  async onDocumentLinks(params: DocumentLinkParams): Promise<DocumentLink[]> {
+    await this.init()
     return this.getProject(params.textDocument)?.onDocumentLinks(params) ?? null
   }
 
@@ -2274,7 +2288,7 @@
   restart(): void {
     console.log('----------\nRESTARTING\n----------')
     this.dispose()
-    this.initialized = false
+    this.initPromise = undefined
     this.init()
   }
 }
@@ -2306,9 +2320,8 @@     return this.documents.onDidOpen
   }
 }
 
-function supportsDynamicRegistration(connection: Connection, params: InitializeParams): boolean {
+function supportsDynamicRegistration(params: InitializeParams): boolean {
   return (
-    connection.onInitialized &&
     params.capabilities.textDocument.hover?.dynamicRegistration &&
     params.capabilities.textDocument.colorProvider?.dynamicRegistration &&
     params.capabilities.textDocument.codeAction?.dynamicRegistration &&
@@ -2322,7 +2335,7 @@
 connection.onInitialize(async (params: InitializeParams): Promise<InitializeResult> => {
   tw.initializeParams = params
 
-  if (supportsDynamicRegistration(connection, params)) {
+  if (supportsDynamicRegistration(params)) {
     return {
       capabilities: {
         textDocumentSync: TextDocumentSyncKind.Full,
@@ -2330,7 +2343,7 @@       },
     }
   }
 
-  await tw.init()
+  tw.setupLSPHandlers()
 
   return {
     capabilities: {