monaco-editor-wrapper
Advanced tools
Comparing version 2.0.0-next.1 to 2.0.0-next.2
@@ -19,10 +19,4 @@ import { updateUserConfiguration } from 'vscode/service-override/configuration'; | ||
} | ||
return this.updateConfig(wrapperConfig.userConfiguration ?? {}) | ||
.then(() => { | ||
console.log('Init of VscodeApiConfig was completed.'); | ||
return Promise.resolve(); | ||
}) | ||
.catch(e => { | ||
return Promise.reject(e); | ||
}); | ||
await this.updateConfig(wrapperConfig.userConfiguration ?? {}); | ||
console.log('Init of VscodeApiConfig was completed.'); | ||
} | ||
@@ -29,0 +23,0 @@ async updateConfig(config) { |
@@ -60,3 +60,2 @@ import 'monaco-editor/esm/vs/editor/edcore.main.js'; | ||
private monacoEditorWrapper; | ||
private wasStarted; | ||
private id; | ||
@@ -88,6 +87,6 @@ private htmlElement; | ||
updateEditorOptions(options: editor.IEditorOptions & editor.IGlobalEditorOptions | VscodeUserConfiguration): Promise<void>; | ||
restartLanguageClient(): Promise<string>; | ||
restartLanguageClient(): Promise<void>; | ||
reportStatus(): string[]; | ||
dispose(): Promise<string>; | ||
disposeLanguageClient(): Promise<string>; | ||
dispose(): Promise<void>; | ||
disposeLanguageClient(): Promise<void>; | ||
updateLayout(): void; | ||
@@ -94,0 +93,0 @@ private disposeEditor; |
@@ -5,3 +5,3 @@ // support all editor features | ||
import { createConfiguredEditor, createConfiguredDiffEditor, createModelReference } from 'vscode/monaco'; | ||
import { initServices, MonacoLanguageClient } from 'monaco-languageclient'; | ||
import { initServices, MonacoLanguageClient, wasVscodeApiInitialized } from 'monaco-languageclient'; | ||
import { toSocket, WebSocketMessageReader, WebSocketMessageWriter } from 'vscode-ws-jsonrpc'; | ||
@@ -23,3 +23,2 @@ import { BrowserMessageReader, BrowserMessageWriter } from 'vscode-languageserver-protocol/browser.js'; | ||
monacoEditorWrapper; | ||
wasStarted = false; | ||
id; | ||
@@ -34,3 +33,3 @@ htmlElement; | ||
this.init(userConfig); | ||
return this.startInternal(); | ||
await this.startInternal(); | ||
} | ||
@@ -106,26 +105,18 @@ init(userConfig) { | ||
this.monacoEditorWrapper = this.useVscodeConfig ? new MonacoVscodeApiWrapper() : new DirectMonacoEditorWrapper(); | ||
await (this.wasStarted ? Promise.resolve('No service init on restart') : initServices(this.serviceConfig)) | ||
.then(() => { | ||
this.monacoEditorWrapper?.init(this.editorConfig, this.monacoConfig); | ||
}) | ||
.then(() => { | ||
let promise; | ||
if (this.editorConfig.useDiffEditor) { | ||
promise = this.createDiffEditor(this.htmlElement); | ||
} | ||
else { | ||
promise = this.createEditor(this.htmlElement); | ||
} | ||
return promise.then(() => { | ||
this.wasStarted = true; | ||
const lcc = this.languageClientConfig; | ||
if (lcc.enabled) { | ||
console.log('Starting monaco-languageclient'); | ||
return this.startLanguageClientConnection(lcc); | ||
} | ||
else { | ||
return Promise.resolve('All fine. monaco-languageclient is not used.'); | ||
} | ||
}); | ||
}); | ||
await (wasVscodeApiInitialized() ? Promise.resolve('No service init on restart') : initServices(this.serviceConfig)); | ||
await this.monacoEditorWrapper?.init(this.editorConfig, this.monacoConfig); | ||
if (this.editorConfig.useDiffEditor) { | ||
await this.createDiffEditor(this.htmlElement); | ||
} | ||
else { | ||
await this.createEditor(this.htmlElement); | ||
} | ||
const lcc = this.languageClientConfig; | ||
if (lcc.enabled) { | ||
console.log('Starting monaco-languageclient'); | ||
await this.startLanguageClientConnection(lcc); | ||
} | ||
else { | ||
await Promise.resolve('All fine. monaco-languageclient is not used.'); | ||
} | ||
} | ||
@@ -180,10 +171,8 @@ isStarted() { | ||
} | ||
updateEditorOptions(options) { | ||
async updateEditorOptions(options) { | ||
if (this.monacoEditorWrapper) { | ||
return this.monacoEditorWrapper.updateConfig(options) | ||
.then(() => { | ||
if (this.useVscodeConfig) { | ||
this.editor?.updateOptions(options); | ||
} | ||
}); | ||
await this.monacoEditorWrapper.updateConfig(options); | ||
if (this.useVscodeConfig) { | ||
this.editor?.updateOptions(options); | ||
} | ||
} | ||
@@ -196,3 +185,3 @@ else { | ||
await this.disposeLanguageClient(); | ||
return this.startLanguageClientConnection(this.languageClientConfig); | ||
await this.startLanguageClientConnection(this.languageClientConfig); | ||
} | ||
@@ -212,10 +201,8 @@ reportStatus() { | ||
if (this.languageClientConfig.enabled) { | ||
return this.disposeLanguageClient() | ||
.then(() => { | ||
this.monacoEditorWrapper = undefined; | ||
return Promise.resolve('Successfully completed dispose.'); | ||
}); | ||
await this.disposeLanguageClient(); | ||
this.monacoEditorWrapper = undefined; | ||
await Promise.resolve('Monaco editor and languageclient completed disposed.'); | ||
} | ||
else { | ||
return Promise.resolve('Monaco editor has been disposed.'); | ||
await Promise.resolve('Monaco editor has been disposed.'); | ||
} | ||
@@ -225,15 +212,15 @@ } | ||
if (this.languageClient && this.languageClient.isRunning()) { | ||
return await this.languageClient.dispose() | ||
.then(() => { | ||
try { | ||
await this.languageClient.dispose(); | ||
this.worker?.terminate(); | ||
this.worker = undefined; | ||
this.languageClient = undefined; | ||
return 'monaco-languageclient and monaco-editor were successfully disposed'; | ||
}) | ||
.catch((e) => { | ||
return `Disposing the monaco-languageclient resulted in error: ${e}`; | ||
}); | ||
await Promise.resolve('monaco-languageclient and monaco-editor were successfully disposed.'); | ||
} | ||
catch (e) { | ||
await Promise.reject(`Disposing the monaco-languageclient resulted in error: ${e}`); | ||
} | ||
} | ||
else { | ||
return Promise.reject('Unable to dispose monaco-languageclient: It is not yet started.'); | ||
await Promise.reject('Unable to dispose monaco-languageclient: It is not yet started.'); | ||
} | ||
@@ -265,6 +252,4 @@ } | ||
async createEditor(container) { | ||
return this.updateEditorModel(false) | ||
.then(() => { | ||
this.editor = createConfiguredEditor(container, this.editorOptions); | ||
}); | ||
await this.updateEditorModel(false); | ||
this.editor = createConfiguredEditor(container, this.editorOptions); | ||
} | ||
@@ -274,11 +259,8 @@ async updateEditorModel(updateEditor) { | ||
const uri = Uri.parse(`/tmp/model${this.id}.${this.editorConfig.languageId}`); | ||
return createModelReference(uri, this.editorConfig.code) | ||
.then((m) => { | ||
this.modelRef = m; | ||
this.modelRef.object.setLanguageId(this.editorConfig.languageId); | ||
this.editorOptions.model = this.modelRef.object.textEditorModel; | ||
if (updateEditor && this.editor) { | ||
this.editor.setModel(this.editorOptions.model); | ||
} | ||
}); | ||
this.modelRef = await createModelReference(uri, this.editorConfig.code); | ||
this.modelRef.object.setLanguageId(this.editorConfig.languageId); | ||
this.editorOptions.model = this.modelRef.object.textEditorModel; | ||
if (updateEditor && this.editor) { | ||
this.editor.setModel(this.editorOptions.model); | ||
} | ||
} | ||
@@ -297,15 +279,13 @@ createDiffEditor(container) { | ||
promises.push(createModelReference(uriOriginal, this.editorConfig.codeOriginal)); | ||
return Promise.all(promises) | ||
.then((refs) => { | ||
this.modelRef = refs[0]; | ||
this.modelRef.object.setLanguageId(this.editorConfig.languageId); | ||
this.modelOriginalRef = refs[1]; | ||
this.modelOriginalRef.object.setLanguageId(this.editorConfig.languageId); | ||
if (this.diffEditor && this.modelRef.object.textEditorModel !== null && this.modelOriginalRef.object.textEditorModel !== null) { | ||
this.diffEditor?.setModel({ | ||
original: this.modelOriginalRef.object.textEditorModel, | ||
modified: this.modelRef.object.textEditorModel | ||
}); | ||
} | ||
}); | ||
const refs = await Promise.all(promises); | ||
this.modelRef = refs[0]; | ||
this.modelRef.object.setLanguageId(this.editorConfig.languageId); | ||
this.modelOriginalRef = refs[1]; | ||
this.modelOriginalRef.object.setLanguageId(this.editorConfig.languageId); | ||
if (this.diffEditor && this.modelRef.object.textEditorModel !== null && this.modelOriginalRef.object.textEditorModel !== null) { | ||
this.diffEditor?.setModel({ | ||
original: this.modelOriginalRef.object.textEditorModel, | ||
modified: this.modelRef.object.textEditorModel | ||
}); | ||
} | ||
} | ||
@@ -348,11 +328,11 @@ startLanguageClientConnection(languageClientConfig) { | ||
messageTransports.reader.onClose(() => this.languageClient?.stop()); | ||
await this.languageClient.start() | ||
.then(() => { | ||
const msg = 'monaco-languageclient was successfully started.'; | ||
resolve(msg); | ||
}) | ||
.catch((e) => { | ||
const errorMsg = `monaco-languageclient start was unsuccessful: ${e.message}`; | ||
try { | ||
await this.languageClient.start(); | ||
} | ||
catch (e) { | ||
const errorMsg = `monaco-languageclient start was unsuccessful: ${e}`; | ||
reject(errorMsg); | ||
}); | ||
} | ||
const msg = 'monaco-languageclient was successfully started.'; | ||
resolve(msg); | ||
} | ||
@@ -359,0 +339,0 @@ createLanguageClient(transports) { |
{ | ||
"name": "monaco-editor-wrapper", | ||
"version": "2.0.0-next.1", | ||
"version": "2.0.0-next.2", | ||
"license": "MIT", | ||
@@ -87,5 +87,3 @@ "description": "Monaco-Editor and Monaco Languageclient Wrapper", | ||
"peerDependencies": { | ||
"monaco-editor": "~0.37.1", | ||
"monaco-languageclient": "5.1.0-next.2", | ||
"vscode": "npm:@codingame/monaco-vscode-api@~1.78.0", | ||
"monaco-languageclient": "5.1.0-next.3", | ||
"vscode-ws-jsonrpc": "3.0.0" | ||
@@ -92,0 +90,0 @@ }, |
@@ -34,10 +34,4 @@ import { updateUserConfiguration } from 'vscode/service-override/configuration'; | ||
return this.updateConfig(wrapperConfig.userConfiguration ?? {}) | ||
.then(() => { | ||
console.log('Init of VscodeApiConfig was completed.'); | ||
return Promise.resolve(); | ||
}) | ||
.catch(e => { | ||
return Promise.reject(e); | ||
}); | ||
await this.updateConfig(wrapperConfig.userConfiguration ?? {}); | ||
console.log('Init of VscodeApiConfig was completed.'); | ||
} | ||
@@ -44,0 +38,0 @@ |
@@ -5,3 +5,3 @@ // support all editor features | ||
import { createConfiguredEditor, createConfiguredDiffEditor, createModelReference } from 'vscode/monaco'; | ||
import { InitializeServiceConfig, initServices, MonacoLanguageClient } from 'monaco-languageclient'; | ||
import { InitializeServiceConfig, initServices, MonacoLanguageClient, wasVscodeApiInitialized } from 'monaco-languageclient'; | ||
import { toSocket, WebSocketMessageReader, WebSocketMessageWriter } from 'vscode-ws-jsonrpc'; | ||
@@ -82,3 +82,2 @@ import { BrowserMessageReader, BrowserMessageWriter } from 'vscode-languageserver-protocol/browser.js'; | ||
private wasStarted = false; | ||
private id: string; | ||
@@ -94,3 +93,3 @@ private htmlElement: HTMLElement; | ||
this.init(userConfig); | ||
return this.startInternal(); | ||
await this.startInternal(); | ||
} | ||
@@ -173,24 +172,18 @@ | ||
this.monacoEditorWrapper = this.useVscodeConfig ? new MonacoVscodeApiWrapper() : new DirectMonacoEditorWrapper(); | ||
await (this.wasStarted ? Promise.resolve('No service init on restart') : initServices(this.serviceConfig)) | ||
.then(() => { | ||
this.monacoEditorWrapper?.init(this.editorConfig, this.monacoConfig); | ||
}) | ||
.then(() => { | ||
let promise: Promise<void>; | ||
if (this.editorConfig.useDiffEditor) { | ||
promise = this.createDiffEditor(this.htmlElement); | ||
} else { | ||
promise = this.createEditor(this.htmlElement); | ||
} | ||
return promise.then(() => { | ||
this.wasStarted = true; | ||
const lcc = this.languageClientConfig; | ||
if (lcc.enabled) { | ||
console.log('Starting monaco-languageclient'); | ||
return this.startLanguageClientConnection(lcc); | ||
} else { | ||
return Promise.resolve('All fine. monaco-languageclient is not used.'); | ||
} | ||
}); | ||
}); | ||
await (wasVscodeApiInitialized() ? Promise.resolve('No service init on restart') : initServices(this.serviceConfig)); | ||
await this.monacoEditorWrapper?.init(this.editorConfig, this.monacoConfig); | ||
if (this.editorConfig.useDiffEditor) { | ||
await this.createDiffEditor(this.htmlElement); | ||
} else { | ||
await this.createEditor(this.htmlElement); | ||
} | ||
const lcc = this.languageClientConfig; | ||
if (lcc.enabled) { | ||
console.log('Starting monaco-languageclient'); | ||
await this.startLanguageClientConnection(lcc); | ||
} else { | ||
await Promise.resolve('All fine. monaco-languageclient is not used.'); | ||
} | ||
} | ||
@@ -261,10 +254,8 @@ | ||
updateEditorOptions(options: editor.IEditorOptions & editor.IGlobalEditorOptions | VscodeUserConfiguration): Promise<void> { | ||
async updateEditorOptions(options: editor.IEditorOptions & editor.IGlobalEditorOptions | VscodeUserConfiguration): Promise<void> { | ||
if (this.monacoEditorWrapper) { | ||
return this.monacoEditorWrapper.updateConfig(options) | ||
.then(() => { | ||
if (this.useVscodeConfig) { | ||
this.editor?.updateOptions(options as editor.IEditorOptions & editor.IGlobalEditorOptions); | ||
} | ||
}); | ||
await this.monacoEditorWrapper.updateConfig(options); | ||
if (this.useVscodeConfig) { | ||
this.editor?.updateOptions(options as editor.IEditorOptions & editor.IGlobalEditorOptions); | ||
} | ||
} else { | ||
@@ -275,5 +266,5 @@ return Promise.reject('Update was called when editor wrapper was not correctly configured.'); | ||
async restartLanguageClient(): Promise<string> { | ||
async restartLanguageClient(): Promise<void> { | ||
await this.disposeLanguageClient(); | ||
return this.startLanguageClientConnection(this.languageClientConfig); | ||
await this.startLanguageClientConnection(this.languageClientConfig); | ||
} | ||
@@ -291,3 +282,3 @@ | ||
async dispose() { | ||
async dispose(): Promise<void> { | ||
this.disposeEditor(); | ||
@@ -297,28 +288,25 @@ this.disposeDiffEditor(); | ||
if (this.languageClientConfig.enabled) { | ||
return this.disposeLanguageClient() | ||
.then(() => { | ||
this.monacoEditorWrapper = undefined; | ||
return Promise.resolve('Successfully completed dispose.'); | ||
}); | ||
await this.disposeLanguageClient(); | ||
this.monacoEditorWrapper = undefined; | ||
await Promise.resolve('Monaco editor and languageclient completed disposed.'); | ||
} | ||
else { | ||
return Promise.resolve('Monaco editor has been disposed.'); | ||
await Promise.resolve('Monaco editor has been disposed.'); | ||
} | ||
} | ||
public async disposeLanguageClient(): Promise<string> { | ||
public async disposeLanguageClient(): Promise<void> { | ||
if (this.languageClient && this.languageClient.isRunning()) { | ||
return await this.languageClient.dispose() | ||
.then(() => { | ||
this.worker?.terminate(); | ||
this.worker = undefined; | ||
this.languageClient = undefined; | ||
return 'monaco-languageclient and monaco-editor were successfully disposed'; | ||
}) | ||
.catch((e: Error) => { | ||
return `Disposing the monaco-languageclient resulted in error: ${e}`; | ||
}); | ||
try { | ||
await this.languageClient.dispose(); | ||
this.worker?.terminate(); | ||
this.worker = undefined; | ||
this.languageClient = undefined; | ||
await Promise.resolve('monaco-languageclient and monaco-editor were successfully disposed.'); | ||
} catch (e) { | ||
await Promise.reject(`Disposing the monaco-languageclient resulted in error: ${e}`); | ||
} | ||
} | ||
else { | ||
return Promise.reject('Unable to dispose monaco-languageclient: It is not yet started.'); | ||
await Promise.reject('Unable to dispose monaco-languageclient: It is not yet started.'); | ||
} | ||
@@ -353,6 +341,4 @@ } | ||
private async createEditor(container: HTMLElement): Promise<void> { | ||
return this.updateEditorModel(false) | ||
.then(() => { | ||
this.editor = createConfiguredEditor(container!, this.editorOptions); | ||
}); | ||
await this.updateEditorModel(false); | ||
this.editor = createConfiguredEditor(container!, this.editorOptions); | ||
} | ||
@@ -364,11 +350,8 @@ | ||
const uri = Uri.parse(`/tmp/model${this.id}.${this.editorConfig.languageId}`); | ||
return createModelReference(uri, this.editorConfig.code) | ||
.then((m) => { | ||
this.modelRef = m as unknown as IReference<ITextFileEditorModel>; | ||
this.modelRef.object.setLanguageId(this.editorConfig.languageId); | ||
this.editorOptions!.model = this.modelRef.object.textEditorModel; | ||
if (updateEditor && this.editor) { | ||
this.editor.setModel(this.editorOptions!.model); | ||
} | ||
}); | ||
this.modelRef = await createModelReference(uri, this.editorConfig.code) as unknown as IReference<ITextFileEditorModel>; | ||
this.modelRef.object.setLanguageId(this.editorConfig.languageId); | ||
this.editorOptions!.model = this.modelRef.object.textEditorModel; | ||
if (updateEditor && this.editor) { | ||
this.editor.setModel(this.editorOptions!.model); | ||
} | ||
} | ||
@@ -391,16 +374,15 @@ | ||
promises.push(createModelReference(uriOriginal, this.editorConfig.codeOriginal)); | ||
return Promise.all(promises) | ||
.then((refs) => { | ||
this.modelRef = refs[0] as unknown as IReference<ITextFileEditorModel>; | ||
this.modelRef.object.setLanguageId(this.editorConfig.languageId); | ||
this.modelOriginalRef = refs[1] as unknown as IReference<ITextFileEditorModel>; | ||
this.modelOriginalRef.object.setLanguageId(this.editorConfig.languageId); | ||
if (this.diffEditor && this.modelRef.object.textEditorModel !== null && this.modelOriginalRef.object.textEditorModel !== null) { | ||
this.diffEditor?.setModel({ | ||
original: this.modelOriginalRef!.object!.textEditorModel, | ||
modified: this.modelRef!.object!.textEditorModel | ||
}); | ||
} | ||
const refs = await Promise.all(promises); | ||
this.modelRef = refs[0] as unknown as IReference<ITextFileEditorModel>; | ||
this.modelRef.object.setLanguageId(this.editorConfig.languageId); | ||
this.modelOriginalRef = refs[1] as unknown as IReference<ITextFileEditorModel>; | ||
this.modelOriginalRef.object.setLanguageId(this.editorConfig.languageId); | ||
if (this.diffEditor && this.modelRef.object.textEditorModel !== null && this.modelOriginalRef.object.textEditorModel !== null) { | ||
this.diffEditor?.setModel({ | ||
original: this.modelOriginalRef!.object!.textEditorModel, | ||
modified: this.modelRef!.object!.textEditorModel | ||
}); | ||
} | ||
} | ||
@@ -449,12 +431,10 @@ | ||
messageTransports.reader.onClose(() => this.languageClient?.stop()); | ||
await this.languageClient.start() | ||
.then(() => { | ||
const msg = 'monaco-languageclient was successfully started.'; | ||
resolve(msg); | ||
}) | ||
.catch((e: Error) => { | ||
const errorMsg = `monaco-languageclient start was unsuccessful: ${e.message}`; | ||
reject(errorMsg); | ||
}); | ||
try { | ||
await this.languageClient.start(); | ||
} catch (e) { | ||
const errorMsg = `monaco-languageclient start was unsuccessful: ${e}`; | ||
reject(errorMsg); | ||
} | ||
const msg = 'monaco-languageclient was successfully started.'; | ||
resolve(msg); | ||
} | ||
@@ -461,0 +441,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
4
2
19744600
3933