-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(problems and notification): update problems and notification code
- Loading branch information
Showing
35 changed files
with
481 additions
and
110 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
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
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
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,50 @@ | ||
import 'reflect-metadata'; | ||
import * as React from 'react'; | ||
import { IStatusBarItem } from 'mo'; | ||
import { Controller } from 'mo/react/controller'; | ||
import { | ||
IPanelService, | ||
PanelService, | ||
IStatusBarService, | ||
StatusBarService, | ||
} from 'mo/services'; | ||
import { singleton, container } from 'tsyringe'; | ||
import { STATUS_PROBLEMS, PANEL_PROBLEMS } from 'mo/model/problems'; | ||
export interface IProblemsController { | ||
onClick?: (e: React.MouseEvent, item: IStatusBarItem) => void; | ||
} | ||
@singleton() | ||
export class ProblemsController | ||
extends Controller | ||
implements IProblemsController { | ||
private readonly panelService: IPanelService; | ||
private readonly statusBarService: IStatusBarService; | ||
constructor() { | ||
super(); | ||
this.panelService = container.resolve(PanelService); | ||
this.statusBarService = container.resolve(StatusBarService); | ||
this.init(); | ||
} | ||
private showHideProblems() { | ||
const { current, hidden } = this.panelService.getState(); | ||
if (hidden) { | ||
this.panelService.showHide(); | ||
} else if (current?.id !== PANEL_PROBLEMS.id) { | ||
this.panelService.open(PANEL_PROBLEMS); | ||
} else { | ||
this.panelService.showHide(); | ||
} | ||
} | ||
|
||
public onClick = (e: React.MouseEvent, item: IStatusBarItem) => { | ||
this.showHideProblems(); | ||
}; | ||
private init() { | ||
this.statusBarService.appendLeftItem( | ||
Object.assign(STATUS_PROBLEMS, { | ||
onClick: this.onClick, | ||
}) | ||
); | ||
this.panelService.add(PANEL_PROBLEMS); | ||
} | ||
} |
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
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,10 @@ | ||
import { IExtensionService } from 'mo'; | ||
import { IExtension } from 'mo/model/extension'; | ||
|
||
function init() {} | ||
|
||
export const ExtendEditor: IExtension = { | ||
activate(extensionCtx: IExtensionService) { | ||
init(); | ||
}, | ||
}; |
2 changes: 1 addition & 1 deletion
2
src/workbench/statusBar/editor/index.tsx → ...extensions/editor/statusBarView/index.tsx
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import * as React from 'react'; | ||
|
||
export function EditorMarkers(props: any) { | ||
export function EditorStatusBarView(props: any) { | ||
const { data = { ln: 0, col: 0 } } = props; | ||
return <span>{`Ln ${data.ln}, Col ${data.col}`}</span>; | ||
} |
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
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,37 @@ | ||
import React from 'react'; | ||
import { IExtension } from 'mo/model/extension'; | ||
import { IExtensionService, notificationService } from 'mo'; | ||
import { Button } from 'mo/components/button'; | ||
function init() { | ||
notificationService.addNotifications([ | ||
{ | ||
id: 1, | ||
value: '测试消息模块1', | ||
status: 1, | ||
render: (item) => { | ||
return ( | ||
<div> | ||
<div>{item.value}</div> | ||
<Button>测试</Button> | ||
</div> | ||
); | ||
}, | ||
}, | ||
{ | ||
id: 2, | ||
value: '测试消息模块2', | ||
status: 1, | ||
}, | ||
{ | ||
id: 3, | ||
value: '测试消息模块3', | ||
status: 1, | ||
}, | ||
]); | ||
} | ||
|
||
export const ExtendNotification: IExtension = { | ||
activate(extensionCtx: IExtensionService) { | ||
init(); | ||
}, | ||
}; |
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,42 @@ | ||
import { IExtensionService } from 'mo'; | ||
import { IExtension } from 'mo/model/extension'; | ||
import { problemsService } from 'mo'; | ||
|
||
function init() { | ||
const MockItem = { | ||
id: 1, | ||
name: 'text.tsx', | ||
value: { | ||
code: 'text.tsx', | ||
message: '文件夹', | ||
startLineNumber: 0, | ||
startColumn: 1, | ||
endLineNumber: 0, | ||
endColumn: 1, | ||
status: 1, | ||
}, | ||
children: [ | ||
{ | ||
id: 3, | ||
name: '0-1', | ||
value: { | ||
code: 'endLineNumber', | ||
message: '语法错误', | ||
startLineNumber: 0, | ||
startColumn: 1, | ||
endLineNumber: 0, | ||
endColumn: 1, | ||
status: 2, | ||
}, | ||
children: [], | ||
}, | ||
], | ||
}; | ||
problemsService.addProblems(MockItem); | ||
} | ||
|
||
export const ExtendProblems: IExtension = { | ||
activate(extensionCtx: IExtensionService) { | ||
init(); | ||
}, | ||
}; |
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
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
This file was deleted.
Oops, something went wrong.
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,76 @@ | ||
import * as React from 'react'; | ||
import { injectable } from 'tsyringe'; | ||
import { IStatusBarItem } from 'mo/model/workbench/statusBar'; | ||
import { IPanelItem } from 'mo/model/workbench/panel'; | ||
import { | ||
ProblemsStatusBarView, | ||
ProblemsPanelView, | ||
} from 'mo/workbench/problems'; | ||
|
||
export enum MarkerSeverity { | ||
Hint = 1, | ||
Info = 2, | ||
Warning = 4, | ||
Error = 8, | ||
} | ||
export interface IRelatedInformation { | ||
code: string; | ||
message: string; | ||
startLineNumber: number; | ||
startColumn: number; | ||
endLineNumber: number; | ||
endColumn: number; | ||
status: MarkerSeverity; | ||
} | ||
export interface IProblemsItem<T = any> { | ||
id?: number; | ||
name: string; | ||
value: IRelatedInformation; | ||
children: IProblemsItem[]; | ||
} | ||
|
||
export interface IProblems<T = any> { | ||
id: string; | ||
name: string; | ||
data: IProblemsItem<T>[]; | ||
show?: boolean; | ||
} | ||
export const STATUS_PROBLEMS: IStatusBarItem = { | ||
id: 'MoProblems', | ||
sortIndex: 1, | ||
data: { | ||
warnings: 0, | ||
errors: 0, | ||
infos: 0, | ||
}, | ||
name: 'Problems', | ||
render: (item: IStatusBarItem) => <ProblemsStatusBarView {...item} />, | ||
}; | ||
export const PANEL_PROBLEMS: IPanelItem = { | ||
id: 'ProblemsPane', | ||
name: 'problems', | ||
data: null, | ||
renderPane: (item) => <ProblemsPanelView {...item} />, | ||
}; | ||
|
||
@injectable() | ||
export class ProblemsModel<T> implements IProblems<T> { | ||
static readonly ID = 'MO_PROBLEMS'; | ||
static readonly NAME = 'Problems'; | ||
public id: string; | ||
public name: string; | ||
public data: IProblemsItem<T>[]; | ||
public show: boolean; | ||
|
||
constructor( | ||
id: string = ProblemsModel.ID, | ||
name: string = ProblemsModel.NAME, | ||
data: IProblemsItem<T>[] = [], | ||
show: boolean = false | ||
) { | ||
this.id = id; | ||
this.name = name; | ||
this.show = show; | ||
this.data = data; | ||
} | ||
} |
Oops, something went wrong.