11import {
2- MonacoWorkspace , TextDocument , TextDocumentSaveReason ,
3- ProtocolToMonacoConverter , MonacoToProtocolConverter , Emitter , Event , TextDocumentWillSaveEvent , Disposable , DisposableCollection
2+ Disposable , DisposableCollection
43} from 'monaco-languageclient'
54import * as monaco from 'monaco-editor'
6- import type * as vscode from 'vscode'
5+ import * as vscode from 'vscode'
6+ import { Workspace } from 'vscode/services'
7+ import { Event , Emitter , TextDocumentSaveReason } from 'vscode-languageserver-protocol'
78import Configuration from './Configuration'
89
910export interface ITextModelContentSaveHandler {
10- saveTextContent ( document : TextDocument , reason : TextDocumentSaveReason ) : Promise < void >
11+ saveTextContent ( document : vscode . TextDocument , reason : TextDocumentSaveReason ) : Promise < void >
1112}
1213
13- export default class CodinGameMonacoWorkspace extends MonacoWorkspace {
14- protected readonly onWillSaveTextDocumentEmitter = new Emitter < TextDocumentWillSaveEvent > ( )
14+ export default class CodinGameMonacoWorkspace implements Workspace {
15+ protected readonly onWillSaveTextDocumentEmitter = new Emitter < vscode . TextDocumentWillSaveEvent > ( )
1516 private readonly savehandlers : ITextModelContentSaveHandler [ ] = [ ]
16- protected readonly onDidSaveTextDocumentEmitter = new Emitter < TextDocument > ( )
17+ protected readonly onDidSaveTextDocumentEmitter = new Emitter < vscode . TextDocument > ( )
1718
18- configurations = new Configuration ( )
19+ private configuration = new Configuration ( )
20+
21+ getConfiguration = ( section ?: string | undefined ) : vscode . WorkspaceConfiguration => {
22+ return this . configuration . getConfiguration ( section )
23+ }
24+
25+ onDidChangeConfiguration = this . configuration . onDidChangeConfiguration
1926
2027 private autoSaveModelDisposable : Disposable | undefined
2128
2229 public workspaceFolders : typeof vscode . workspace . workspaceFolders
2330
2431 constructor (
25- p2m : ProtocolToMonacoConverter ,
26- m2p : MonacoToProtocolConverter ,
27- rootUri : string | null = null
32+ public readonly rootUri : string | null = null
2833 ) {
29- super ( monaco , p2m , m2p , rootUri )
3034 }
3135
3236 public initialize (
3337 rootUri : string | null = null ,
3438 workspaceFolders : typeof vscode . workspace . workspaceFolders ,
3539 autoSaveModels : boolean
3640 ) : void {
37- this . _rootUri = rootUri
3841 if ( workspaceFolders != null ) {
3942 this . workspaceFolders = workspaceFolders
4043 } else if ( rootUri != null ) {
@@ -53,11 +56,11 @@ export default class CodinGameMonacoWorkspace extends MonacoWorkspace {
5356 }
5457 }
5558
56- get onWillSaveTextDocument ( ) : Event < TextDocumentWillSaveEvent > {
59+ get onWillSaveTextDocument ( ) : Event < vscode . TextDocumentWillSaveEvent > {
5760 return this . onWillSaveTextDocumentEmitter . event
5861 }
5962
60- get onDidSaveTextDocument ( ) : Event < TextDocument > {
63+ get onDidSaveTextDocument ( ) : Event < vscode . TextDocument > {
6164 return this . onDidSaveTextDocumentEmitter . event
6265 }
6366
@@ -71,10 +74,13 @@ export default class CodinGameMonacoWorkspace extends MonacoWorkspace {
7174 } )
7275 }
7376
74- async saveDocument ( document : TextDocument , reason : TextDocumentSaveReason ) : Promise < void > {
77+ async saveDocument ( document : vscode . TextDocument , reason : TextDocumentSaveReason ) : Promise < void > {
7578 this . onWillSaveTextDocumentEmitter . fire ( {
76- textDocument : document ,
77- reason
79+ document,
80+ reason,
81+ waitUntil ( ) {
82+ // Ignored
83+ }
7884 } )
7985
8086 try {
@@ -93,16 +99,17 @@ export default class CodinGameMonacoWorkspace extends MonacoWorkspace {
9399 private autoSaveModels ( ) : Disposable {
94100 const disposableCollection = new DisposableCollection ( )
95101 const timeoutMap = new Map < string , number > ( )
96- disposableCollection . push ( this . onDidChangeTextDocument ( e => {
97- const timeout = timeoutMap . get ( e . textDocument . uri )
102+ disposableCollection . push ( vscode . workspace . onDidChangeTextDocument ( e => {
103+ const uri = e . document . uri . toString ( )
104+ const timeout = timeoutMap . get ( uri )
98105 if ( timeout != null ) {
99106 window . clearTimeout ( timeout )
100- timeoutMap . delete ( e . textDocument . uri )
107+ timeoutMap . delete ( uri )
101108 }
102- timeoutMap . set ( e . textDocument . uri , window . setTimeout ( ( ) => {
103- timeoutMap . delete ( e . textDocument . uri )
104- this . saveDocument ( e . textDocument , TextDocumentSaveReason . AfterDelay ) . catch ( ( error : Error ) => {
105- monaco . errorHandler . onUnexpectedError ( new Error ( `[LSP] Unable to save the document ${ e . textDocument . uri . toString ( ) } ` , {
109+ timeoutMap . set ( uri , window . setTimeout ( ( ) => {
110+ timeoutMap . delete ( uri )
111+ this . saveDocument ( e . document , TextDocumentSaveReason . AfterDelay ) . catch ( ( error : Error ) => {
112+ monaco . errorHandler . onUnexpectedError ( new Error ( `[LSP] Unable to save the document ${ uri } ` , {
106113 cause : error
107114 } ) )
108115 } )
@@ -116,10 +123,9 @@ export default class CodinGameMonacoWorkspace extends MonacoWorkspace {
116123 return disposableCollection
117124 }
118125
119- override dispose ( ) : void {
120- super . dispose ( )
126+ dispose ( ) : void {
121127 this . autoSaveModelDisposable ?. dispose ( )
122- this . configurations . dispose ( )
128+ this . configuration . dispose ( )
123129 this . onWillSaveTextDocumentEmitter . dispose ( )
124130 this . onDidSaveTextDocumentEmitter . dispose ( )
125131 }
0 commit comments