forked from arduino/arduino-ide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use a monaco editor for the monitor output
Closes arduino#105 Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
- Loading branch information
Akos Kitta
committed
Nov 29, 2022
1 parent
d6a4b0f
commit 732e1ad
Showing
11 changed files
with
554 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
arduino-ide-extension/src/browser/serial/monitor/monitor-context-menu-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { MenuPath } from '@theia/core/lib/common/menu'; | ||
import { injectable } from '@theia/core/shared/inversify'; | ||
import { MonacoContextMenuService } from '@theia/monaco/lib/browser/monaco-context-menu'; | ||
|
||
export namespace MonitorContextMenu { | ||
export const MENU_PATH: MenuPath = ['monitor_context_menu']; | ||
export const TEXT_EDIT_GROUP = [...MENU_PATH, '0_text_edit_group']; | ||
export const WIDGET_GROUP = [...MENU_PATH, '1_widget_group']; | ||
} | ||
|
||
@injectable() | ||
export class MonitorContextMenuService extends MonacoContextMenuService { | ||
protected override menuPath(): MenuPath { | ||
return MonitorContextMenu.MENU_PATH; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
arduino-ide-extension/src/browser/serial/monitor/monitor-editor-factory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { inject, injectable } from '@theia/core/shared/inversify'; | ||
import { IContextMenuService } from '@theia/monaco-editor-core/esm/vs/platform/contextview/browser/contextView'; | ||
import { MonacoContextMenuService } from '@theia/monaco/lib/browser/monaco-context-menu'; | ||
import { | ||
EditorServiceOverrides, | ||
MonacoEditor, | ||
} from '@theia/monaco/lib/browser/monaco-editor'; | ||
import { MonacoEditorModel } from '@theia/monaco/lib/browser/monaco-editor-model'; | ||
import { OutputEditorFactory } from '../../theia/output/output-editor-factory'; | ||
import { MonitorContextMenuService } from './monitor-context-menu-service'; | ||
import { MonitorUri } from './monitor-uri'; | ||
|
||
@injectable() | ||
export class MonitorEditorFactory extends OutputEditorFactory { | ||
@inject(MonitorContextMenuService) | ||
private readonly monitorContextMenuService: MonacoContextMenuService; | ||
|
||
override readonly scheme: string = MonitorUri.scheme; | ||
|
||
protected override createOptions( | ||
model: MonacoEditorModel, | ||
defaultOptions: MonacoEditor.IOptions | ||
): MonacoEditor.IOptions { | ||
return { | ||
...super.createOptions(model, defaultOptions), | ||
// To hide the margin in the editor https://github.com/microsoft/monaco-editor/issues/1960 | ||
lineNumbers: 'off', | ||
glyphMargin: false, | ||
folding: false, | ||
lineDecorationsWidth: 0, | ||
lineNumbersMinChars: 0, | ||
}; | ||
} | ||
|
||
protected override *createOverrides( | ||
model: MonacoEditorModel, | ||
defaultOverrides: EditorServiceOverrides | ||
): EditorServiceOverrides { | ||
yield [IContextMenuService, this.monitorContextMenuService]; | ||
for (const [identifier, provider] of defaultOverrides) { | ||
if (identifier !== IContextMenuService) { | ||
yield [identifier, provider]; | ||
} | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
arduino-ide-extension/src/browser/serial/monitor/monitor-editor-model-factory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { injectable } from '@theia/core/shared/inversify'; | ||
import { OutputEditorModelFactory } from '@theia/output/lib/browser/output-editor-model-factory'; | ||
import { MonitorUri } from './monitor-uri'; | ||
|
||
@injectable() | ||
export class MonitorEditorModelFactory extends OutputEditorModelFactory { | ||
override readonly scheme: string = MonitorUri.scheme; | ||
} |
32 changes: 32 additions & 0 deletions
32
arduino-ide-extension/src/browser/serial/monitor/monitor-resource-provider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Deferred } from '@theia/core/lib/common/promise-util'; | ||
import { Resource, ResourceResolver } from '@theia/core/lib/common/resource'; | ||
import URI from '@theia/core/lib/common/uri'; | ||
import { inject, injectable } from '@theia/core/shared/inversify'; | ||
import { IReference } from '@theia/monaco-editor-core/esm/vs/base/common/lifecycle'; | ||
import { MonacoEditorModel } from '@theia/monaco/lib/browser/monaco-editor-model'; | ||
import { MonacoTextModelService } from '@theia/monaco/lib/browser/monaco-text-model-service'; | ||
import { MonitorResource } from './monitor-resource'; | ||
import { MonitorUri } from './monitor-uri'; | ||
|
||
@injectable() | ||
export class MonitorResourceProvider implements ResourceResolver { | ||
readonly resource: MonitorResource; | ||
|
||
constructor( | ||
@inject(MonacoTextModelService) textModelService: MonacoTextModelService | ||
) { | ||
const editorModelRef = new Deferred<IReference<MonacoEditorModel>>(); | ||
this.resource = new MonitorResource(MonitorUri, editorModelRef); | ||
textModelService | ||
.createModelReference(MonitorUri) | ||
.then((ref) => editorModelRef.resolve(ref)); | ||
} | ||
|
||
async resolve(uri: URI): Promise<Resource> { | ||
if (this.resource.uri.toString() === uri.toString()) { | ||
return this.resource; | ||
} | ||
// Note: this is totally normal. This is the way Theia loads a resource. | ||
throw new Error(`Cannot handle URI: ${uri.toString()}`); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
arduino-ide-extension/src/browser/serial/monitor/monitor-resource.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { ResourceReadOptions } from '@theia/core/lib/common/resource'; | ||
import { OutputResource } from '@theia/output/lib/browser/output-resource'; | ||
|
||
export class MonitorResource extends OutputResource { | ||
override async readContents(options?: ResourceReadOptions): Promise<string> { | ||
if (!this._textModel) { | ||
return ''; | ||
} | ||
return super.readContents(options); | ||
} | ||
|
||
async reset(): Promise<void> { | ||
this.textModel?.setValue(''); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
arduino-ide-extension/src/browser/serial/monitor/monitor-uri.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import URI from '@theia/core/lib/common/uri'; | ||
|
||
export const MonitorUri = new URI('monitor:/arduino'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.