| 1111 | } |
| 1112 | |
| 1113 | class FileSystemWatcherFeature implements DynamicFeature<DidChangeWatchedFilesRegistrationOptions> { |
| 1114 | |
| 1115 | private _watchers: Map<string, Disposable[]> = new Map<string, Disposable[]>(); |
| 1116 | |
| 1117 | constructor(private _client: BaseLanguageClient, private _notifyFileEvent: (event: FileEvent) => void) { |
| 1118 | } |
| 1119 | |
| 1120 | public get messages(): RPCMessageType { |
| 1121 | return DidChangeWatchedFilesNotification.type; |
| 1122 | } |
| 1123 | |
| 1124 | public fillClientCapabilities(capabilities: ClientCapabilities): void { |
| 1125 | ensure(ensure(capabilities, 'workspace')!, 'didChangeWatchedFiles')!.dynamicRegistration = true; |
| 1126 | } |
| 1127 | |
| 1128 | public initialize(_capabilities: ServerCapabilities, _documentSelector: DocumentSelector): void { |
| 1129 | } |
| 1130 | |
| 1131 | public register(_method: RPCMessageType, data: RegistrationData<DidChangeWatchedFilesRegistrationOptions>): void { |
| 1132 | if (!Array.isArray(data.registerOptions.watchers)) { |
| 1133 | return; |
| 1134 | } |
| 1135 | let disposeables: Disposable[] = []; |
| 1136 | for (let watcher of data.registerOptions.watchers) { |
| 1137 | if (!Is.string(watcher.globPattern)) { |
| 1138 | continue; |
| 1139 | } |
| 1140 | let watchCreate: boolean = true, watchChange: boolean = true, watchDelete: boolean = true; |
| 1141 | if (watcher.kind !== void 0 && watcher.kind !== null) { |
| 1142 | watchCreate = (watcher.kind & WatchKind.Create) !== 0; |
| 1143 | watchChange = (watcher.kind & WatchKind.Change) != 0; |
| 1144 | watchDelete = (watcher.kind & WatchKind.Delete) != 0; |
| 1145 | } |
| 1146 | let fileSystemWatcher: VFileSystemWatcher = Workspace.createFileSystemWatcher(watcher.globPattern, !watchCreate, !watchChange, !watchDelete); |
| 1147 | this.hookListeners(fileSystemWatcher, watchCreate, watchChange, watchDelete); |
| 1148 | disposeables.push(fileSystemWatcher); |
| 1149 | } |
| 1150 | this._watchers.set(data.id, disposeables); |
| 1151 | } |
| 1152 | |
| 1153 | public registerRaw(id: string, fileSystemWatchers: VFileSystemWatcher[]) { |
| 1154 | let disposeables: Disposable[] = []; |
| 1155 | for (let fileSystemWatcher of fileSystemWatchers) { |
| 1156 | this.hookListeners(fileSystemWatcher, true, true, true, disposeables); |
| 1157 | } |
| 1158 | this._watchers.set(id, disposeables); |
| 1159 | } |
| 1160 | |
| 1161 | private hookListeners(fileSystemWatcher: VFileSystemWatcher, watchCreate: boolean, watchChange: boolean, watchDelete: boolean, listeners?: Disposable[]): void { |
| 1162 | if (watchCreate) { |
| 1163 | fileSystemWatcher.onDidCreate((resource) => this._notifyFileEvent( |
| 1164 | { |
| 1165 | uri: this._client.code2ProtocolConverter.asUri(resource), |
| 1166 | type: FileChangeType.Created |
| 1167 | } |
| 1168 | ), null, listeners); |
| 1169 | } |
| 1170 | if (watchChange) { |
nothing calls this directly
no outgoing calls
no test coverage detected