@@ -14,7 +14,8 @@ import {
14
14
commands ,
15
15
Selection ,
16
16
Position ,
17
- Range
17
+ Range ,
18
+ TextEditorRevealType
18
19
} from 'vscode'
19
20
20
21
import {
@@ -76,34 +77,13 @@ export async function activate(context: ExtensionContext) {
76
77
'lsp-multi-server-example'
77
78
)
78
79
79
- let files = await Workspace . findFiles ( CONFIG_GLOB , '**/node_modules/**' , 1 )
80
-
81
- if ( ! files . length ) return
82
-
83
- let configPath = files [ 0 ] . fsPath
84
- delete require . cache [ configPath ]
85
-
86
- let refresh = createTreeView ( configPath )
87
- commands . registerCommand ( 'tailwindcss.goToDefinition' , ( ) => {
88
- // refresh()
89
- // Window.showInformationMessage('Hello World!')
90
- Workspace . openTextDocument ( files [ 0 ] ) . then ( ( doc : TextDocument ) => {
91
- Window . showTextDocument ( doc ) . then ( ( editor : TextEditor ) => {
92
- let start = new Position ( 0 , 0 )
93
- let end = new Position ( 0 , 0 )
94
- editor . revealRange ( new Range ( start , end ) )
95
- editor . selection = new Selection ( start , end )
96
- } )
97
- } )
98
- } )
99
-
100
- function didOpenTextDocument ( document : TextDocument ) : void {
101
- if (
102
- document . uri . scheme !== 'file' ||
103
- LANGUAGES . indexOf ( document . languageId ) === - 1
104
- ) {
105
- return
106
- }
80
+ async function didOpenTextDocument ( document : TextDocument ) : Promise < void > {
81
+ // if (
82
+ // document.uri.scheme !== 'file' ||
83
+ // LANGUAGES.indexOf(document.languageId) === -1
84
+ // ) {
85
+ // return
86
+ // }
107
87
108
88
let uri = document . uri
109
89
let folder = Workspace . getWorkspaceFolder ( uri )
@@ -112,10 +92,18 @@ export async function activate(context: ExtensionContext) {
112
92
if ( ! folder ) {
113
93
return
114
94
}
95
+
115
96
// If we have nested workspace folders we only start a server on the outer most workspace folder.
116
97
folder = getOuterMostWorkspaceFolder ( folder )
117
98
118
99
if ( ! clients . has ( folder . uri . toString ( ) ) ) {
100
+ let files = await Workspace . findFiles (
101
+ CONFIG_GLOB ,
102
+ '**/node_modules/**' ,
103
+ 1
104
+ )
105
+ if ( ! files . length ) return
106
+
119
107
let debugOptions = {
120
108
execArgv : [ '--nolazy' , `--inspect=${ 6011 + clients . size } ` ]
121
109
}
@@ -139,6 +127,32 @@ export async function activate(context: ExtensionContext) {
139
127
serverOptions ,
140
128
clientOptions
141
129
)
130
+
131
+ client . onReady ( ) . then ( ( ) => {
132
+ client . onNotification ( 'tailwindcss/foundConfig' , configPath => {
133
+ let refresh = createTreeView ( configPath )
134
+ } )
135
+ client . onNotification (
136
+ 'tailwindcss/foundDefinition' ,
137
+ ( configPath , pos ) => {
138
+ Workspace . openTextDocument ( configPath ) . then ( ( doc : TextDocument ) => {
139
+ Window . showTextDocument ( doc ) . then ( ( editor : TextEditor ) => {
140
+ let start = new Position ( pos [ 0 ] , pos [ 1 ] )
141
+ let end = new Position ( pos [ 2 ] , pos [ 3 ] )
142
+ editor . revealRange (
143
+ new Range ( start , end ) ,
144
+ TextEditorRevealType . InCenter
145
+ )
146
+ editor . selection = new Selection ( start , end )
147
+ } )
148
+ } )
149
+ }
150
+ )
151
+ commands . registerCommand ( 'tailwindcss.goToDefinition' , key => {
152
+ client . sendNotification ( 'tailwindcss/findDefinition' , [ key ] )
153
+ } )
154
+ } )
155
+
142
156
// client.onReady().then(() => {
143
157
// client.onNotification('tailwind/loaded', () => {
144
158
// console.log('loaded')
0 commit comments