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
|
diff --git a/src/extension.ts b/src/extension.ts
index 9429c41ae405b98211d49dd9899ce3167dce8261..8f70f5fc2f01e7ab710a91d46e72b57f292ada54 100644
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -14,7 +14,8 @@ Uri,
commands,
Selection,
Position,
- Range
+ Range,
+ TextEditorRevealType
} from 'vscode'
import {
@@ -76,34 +77,13 @@ let outputChannel: OutputChannel = Window.createOutputChannel(
'lsp-multi-server-example'
)
- let files = await Workspace.findFiles(CONFIG_GLOB, '**/node_modules/**', 1)
-
- if (!files.length) return
-
- let configPath = files[0].fsPath
- delete require.cache[configPath]
-
- let refresh = createTreeView(configPath)
- commands.registerCommand('tailwindcss.goToDefinition', () => {
- // refresh()
- // Window.showInformationMessage('Hello World!')
- Workspace.openTextDocument(files[0]).then((doc: TextDocument) => {
- Window.showTextDocument(doc).then((editor: TextEditor) => {
- let start = new Position(0, 0)
- let end = new Position(0, 0)
- editor.revealRange(new Range(start, end))
- editor.selection = new Selection(start, end)
- })
- })
- })
-
- function didOpenTextDocument(document: TextDocument): void {
- if (
- document.uri.scheme !== 'file' ||
- LANGUAGES.indexOf(document.languageId) === -1
- ) {
- return
- }
+ async function didOpenTextDocument(document: TextDocument): Promise<void> {
+ // if (
+ // document.uri.scheme !== 'file' ||
+ // LANGUAGES.indexOf(document.languageId) === -1
+ // ) {
+ // return
+ // }
let uri = document.uri
let folder = Workspace.getWorkspaceFolder(uri)
@@ -112,10 +92,18 @@ // Single file languages like JSON might handle files outside the workspace folders.
if (!folder) {
return
}
+
// If we have nested workspace folders we only start a server on the outer most workspace folder.
folder = getOuterMostWorkspaceFolder(folder)
if (!clients.has(folder.uri.toString())) {
+ let files = await Workspace.findFiles(
+ CONFIG_GLOB,
+ '**/node_modules/**',
+ 1
+ )
+ if (!files.length) return
+
let debugOptions = {
execArgv: ['--nolazy', `--inspect=${6011 + clients.size}`]
}
@@ -139,6 +127,32 @@ 'LSP Multi Server Example',
serverOptions,
clientOptions
)
+
+ client.onReady().then(() => {
+ client.onNotification('tailwindcss/foundConfig', configPath => {
+ let refresh = createTreeView(configPath)
+ })
+ client.onNotification(
+ 'tailwindcss/foundDefinition',
+ (configPath, pos) => {
+ Workspace.openTextDocument(configPath).then((doc: TextDocument) => {
+ Window.showTextDocument(doc).then((editor: TextEditor) => {
+ let start = new Position(pos[0], pos[1])
+ let end = new Position(pos[2], pos[3])
+ editor.revealRange(
+ new Range(start, end),
+ TextEditorRevealType.InCenter
+ )
+ editor.selection = new Selection(start, end)
+ })
+ })
+ }
+ )
+ commands.registerCommand('tailwindcss.goToDefinition', key => {
+ client.sendNotification('tailwindcss/findDefinition', [key])
+ })
+ })
+
// client.onReady().then(() => {
// client.onNotification('tailwind/loaded', () => {
// console.log('loaded')
|