Home

tailwind-ctp-intellisense @072809d9b75527cb6b86b66c9fc9e1bbad02a42e - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tailwind-ctp-intellisense / packages / tailwindcss-language-server / src / server.ts
- raw
 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
/* --------------------------------------------------------------------------------------------
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See License.txt in the project root for license information.
 * ------------------------------------------------------------------------------------------ */

import {
  createConnection,
  TextDocuments,
  ProposedFeatures,
  TextDocumentSyncKind,
  CompletionItem,
  InitializeParams,
  InitializeResult,
  CompletionParams,
  CompletionList,
} from 'vscode-languageserver'
import getTailwindState from 'tailwindcss-class-names'
import { State } from './util/state'
import {
  provideCompletions,
  resolveCompletionItem,
} from './providers/completionProvider'
import { URI } from 'vscode-uri'

let state: State = null
let connection = createConnection(ProposedFeatures.all)
let documents = new TextDocuments()
let workspaceFolder: string | null

documents.onDidOpen((event) => {
  connection.console.log(
    `[Server(${process.pid}) ${workspaceFolder}] Document opened: ${event.document.uri}`
  )
})
documents.listen(connection)

connection.onInitialize(
  async (params: InitializeParams): Promise<InitializeResult> => {
    state = await getTailwindState(
      params.rootPath || URI.parse(params.rootUri).path,
      {
        onChange: (newState: State): void => {
          state = { ...newState, editor: state.editor }
          connection.sendNotification('tailwindcss/configUpdated', [
            state.dependencies[0],
            state.config,
            state.plugins,
          ])
        },
      }
    )
    state.editor = { connection, documents }

    return {
      capabilities: {
        // textDocumentSync: {
        //   openClose: true,
        //   change: TextDocumentSyncKind.None
        // },
        textDocumentSync: documents.syncKind,
        completionProvider: {
          resolveProvider: true,
          triggerCharacters: ['"', "'", '`', ' ', '.', '[', state.separator],
        },
      },
    }
  }
)

connection.onInitialized &&
  connection.onInitialized(async () => {
    connection.sendNotification('tailwindcss/configUpdated', [
      state.dependencies[0],
      state.config,
      state.plugins,
    ])
  })

connection.onCompletion(
  (params: CompletionParams): CompletionList => {
    return provideCompletions(state, params)
  }
)

connection.onCompletionResolve(
  (item: CompletionItem): CompletionItem => {
    return resolveCompletionItem(state, item)
  }
)

connection.listen()