Skip to content

Commit a08976f

Browse files
authored
Merge pull request #31 from CodinGame/fix-workspace-dispose
Fix workspace disposal
2 parents 95042bc + 5de48b2 commit a08976f

File tree

5 files changed

+39
-24
lines changed

5 files changed

+39
-24
lines changed

package-lock.json

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"eslint-plugin-promise": "6.0.0",
6464
"eslint-plugin-unused-imports": "2.0.0",
6565
"jest": "^27.5.1",
66-
"monaco-languageclient": "^0.18.1",
66+
"monaco-languageclient": "^0.19.0-next.1",
6767
"proxy-polyfill": "^0.3.2",
6868
"rollup": "2.70.2",
6969
"rollup-plugin-dts": "^4.2.1",

src/services.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,22 @@ function autoSaveModels (services: CgMonacoServices): Disposable {
5555
return disposableCollection
5656
}
5757

58-
let services: CgMonacoServices | null = null
5958
let serviceDisposable: Disposable | null = null
6059
let serviceReferenceCount = 0
6160
function installServices (infrastructure: Infrastructure): Disposable {
62-
if (services == null) {
63-
// FIXME: we can't recreate services because MonacoWorkspace can't be disposed without memory leaks
64-
// fix me as soon as https://github.com/TypeFox/monaco-languageclient/pull/330/files is released
61+
if (serviceReferenceCount === 0) {
62+
const disposableCollection = new DisposableCollection()
63+
6564
const m2p = new MonacoToProtocolConverter(monaco)
6665
const p2m = new ProtocolToMonacoConverter(monaco)
67-
services = {
66+
const services = {
6867
commands: new MonacoCommands(monaco),
6968
languages: new MonacoLanguages(monaco, p2m, m2p),
7069
workspace: new CodinGameMonacoWorkspace(p2m, m2p, infrastructure.rootUri, infrastructure.workspaceFolders),
7170
window: new WatchableConsoleWindow()
7271
}
73-
}
74-
75-
if (serviceReferenceCount === 0) {
76-
const disposableCollection = new DisposableCollection()
7772

73+
disposableCollection.push(services.workspace)
7874
disposableCollection.push(installCommands(services))
7975
disposableCollection.push(Services.install(services))
8076

src/services/CodinGameMonacoWorkspace.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,11 @@ export default class CodinGameMonacoWorkspace extends MonacoWorkspace {
7272
}))
7373
}
7474
}
75+
76+
override dispose (): void {
77+
super.dispose()
78+
this.configurations.dispose()
79+
this.onWillSaveTextDocumentEmitter.dispose()
80+
this.onDidSaveTextDocumentEmitter.dispose()
81+
}
7582
}

src/services/Configuration.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
Configurations, ConfigurationChangeEvent, WorkspaceConfiguration, Event, Emitter
2+
Configurations, ConfigurationChangeEvent, WorkspaceConfiguration, Event, Emitter, Disposable, DisposableCollection
33
} from 'monaco-languageclient'
44
import * as monaco from 'monaco-editor'
55

@@ -38,8 +38,16 @@ class MemoryWorkspaceConfiguration implements WorkspaceConfiguration {
3838
}
3939

4040
const simpleConfigurationService = monaco.extra.StandaloneServices.get(monaco.extra.IConfigurationService) as monaco.extra.StandaloneConfigurationService
41-
class Configuration implements Configurations {
41+
class Configuration implements Configurations, Disposable {
4242
protected readonly onDidChangeConfigurationEmitter = new Emitter<ConfigurationChangeEvent>()
43+
private disposableCollection = new DisposableCollection()
44+
45+
constructor () {
46+
this.disposableCollection.push(this.onDidChangeConfigurationEmitter)
47+
this.disposableCollection.push(simpleConfigurationService.onDidChangeConfiguration((event) => {
48+
this.onDidChangeConfigurationEmitter.fire(event)
49+
}))
50+
}
4351

4452
getConfiguration (section?: string, resource?: string): MemoryWorkspaceConfiguration {
4553
return new MemoryWorkspaceConfiguration(this.getValue(section, resource))
@@ -56,7 +64,11 @@ class Configuration implements Configurations {
5664
}
5765

5866
get onDidChangeConfiguration (): Event<ConfigurationChangeEvent> {
59-
return simpleConfigurationService.onDidChangeConfiguration
67+
return this.onDidChangeConfigurationEmitter.event
68+
}
69+
70+
dispose (): void {
71+
this.disposableCollection.dispose()
6072
}
6173
}
6274

0 commit comments

Comments
 (0)