Skip to content

Commit 8949261

Browse files
committed
Allow the client to notify the server that files have changed
1 parent bdff890 commit 8949261

File tree

1 file changed

+35
-0
lines changed
  • packages/tailwindcss-language-server/tests/utils

1 file changed

+35
-0
lines changed

packages/tailwindcss-language-server/tests/utils/client.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ import {
66
CompletionList,
77
CompletionParams,
88
Diagnostic,
9+
DidChangeWatchedFilesNotification,
910
Disposable,
1011
DocumentLink,
1112
DocumentLinkRequest,
1213
DocumentSymbol,
1314
DocumentSymbolRequest,
15+
FileChangeType,
16+
FileEvent,
1417
Hover,
1518
NotificationHandler,
1619
ProtocolConnection,
@@ -85,6 +88,12 @@ export interface DocumentDescriptor {
8588
settings?: Settings
8689
}
8790

91+
export interface ChangedFiles {
92+
created?: string[]
93+
changed?: string[]
94+
deleted?: string[]
95+
}
96+
8897
export interface ClientDocument {
8998
/**
9099
* The URI to the document
@@ -203,6 +212,11 @@ export interface Client extends ClientWorkspace {
203212
*/
204213
onServerCapabilitiesChanged(cb: () => void): void
205214

215+
/**
216+
* Tell the server that files on disk have changed
217+
*/
218+
notifyChangedFiles(changes: ChangedFiles): Promise<void>
219+
206220
/**
207221
* Get a workspace by name
208222
*/
@@ -533,12 +547,33 @@ export async function createClient(opts: ClientOptions): Promise<Client> {
533547
await initPromise
534548
}
535549

550+
function notifyChangedFiles(changes: ChangedFiles) {
551+
let events: FileEvent[] = []
552+
553+
for (const path of changes?.created ?? []) {
554+
events.push({ uri: URI.file(path).toString(), type: FileChangeType.Created })
555+
}
556+
557+
for (const path of changes?.changed ?? []) {
558+
events.push({ uri: URI.file(path).toString(), type: FileChangeType.Changed })
559+
}
560+
561+
for (const path of changes?.deleted ?? []) {
562+
events.push({ uri: URI.file(path).toString(), type: FileChangeType.Deleted })
563+
}
564+
565+
return conn.sendNotification(DidChangeWatchedFilesNotification.type, {
566+
changes: events,
567+
})
568+
}
569+
536570
return {
537571
...clientWorkspaces[0],
538572
get serverCapabilities() {
539573
return registeredCapabilities
540574
},
541575
onServerCapabilitiesChanged,
576+
notifyChangedFiles,
542577
workspace,
543578
updateSettings,
544579
}

0 commit comments

Comments
 (0)