| 2012 | } |
| 2013 | |
| 2014 | class ConfigurationFeature implements DynamicFeature<DidChangeConfigurationRegistrationOptions> { |
| 2015 | |
| 2016 | private _listeners: Map<string, Disposable> = new Map<string, Disposable>(); |
| 2017 | |
| 2018 | constructor(private _client: BaseLanguageClient) { |
| 2019 | } |
| 2020 | |
| 2021 | public get messages(): RPCMessageType { |
| 2022 | return DidChangeConfigurationNotification.type; |
| 2023 | } |
| 2024 | |
| 2025 | public fillClientCapabilities(capabilities: ClientCapabilities): void { |
| 2026 | ensure(ensure(capabilities, 'workspace')!, 'didChangeConfiguration')!.dynamicRegistration = true; |
| 2027 | } |
| 2028 | |
| 2029 | public initialize(): void { |
| 2030 | let section = this._client.clientOptions.synchronize!.configurationSection; |
| 2031 | if (section !== void 0) { |
| 2032 | this.register(this.messages, { |
| 2033 | id: UUID.generateUuid(), |
| 2034 | registerOptions: { |
| 2035 | section: section |
| 2036 | } |
| 2037 | }) |
| 2038 | } |
| 2039 | } |
| 2040 | |
| 2041 | public register(_message: RPCMessageType, data: RegistrationData<DidChangeConfigurationRegistrationOptions>): void { |
| 2042 | let disposable = Workspace.onDidChangeConfiguration(() => { |
| 2043 | this.onDidChangeConfiguration(data.registerOptions.section); |
| 2044 | }); |
| 2045 | this._listeners.set(data.id, disposable); |
| 2046 | if (data.registerOptions.section !== void 0) { |
| 2047 | this.onDidChangeConfiguration(data.registerOptions.section); |
| 2048 | } |
| 2049 | } |
| 2050 | |
| 2051 | public unregister(id: string): void { |
| 2052 | let disposable = this._listeners.get(id); |
| 2053 | if (disposable) { |
| 2054 | this._listeners.delete(id); |
| 2055 | disposable.dispose(); |
| 2056 | } |
| 2057 | } |
| 2058 | |
| 2059 | public dispose(): void { |
| 2060 | for (let disposable of this._listeners.values()) { |
| 2061 | disposable.dispose(); |
| 2062 | } |
| 2063 | } |
| 2064 | |
| 2065 | private onDidChangeConfiguration(configurationSection: string | string[] | undefined): void { |
| 2066 | let sections: string[] | undefined; |
| 2067 | if (Is.string(configurationSection)) { |
| 2068 | sections = [configurationSection]; |
| 2069 | } else { |
| 2070 | sections = configurationSection; |
| 2071 | } |
nothing calls this directly
no outgoing calls
no test coverage detected