@opensumi/ide-editor 2.21.13 → 2.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/breadcrumb/default.js.map +1 -1
- package/lib/browser/breadcrumb/document-symbol.js.map +1 -1
- package/lib/browser/breadcrumb/index.js.map +1 -1
- package/lib/browser/component.js.map +1 -1
- package/lib/browser/decoration-applier.js.map +1 -1
- package/lib/browser/diff/compare.js.map +1 -1
- package/lib/browser/diff/index.d.ts.map +1 -1
- package/lib/browser/diff/index.js +1 -1
- package/lib/browser/diff/index.js.map +1 -1
- package/lib/browser/doc-cache/empty-doc-cache.js.map +1 -1
- package/lib/browser/doc-cache/local-storage-cache.js.map +1 -1
- package/lib/browser/doc-model/editor-document-model-service.js +3 -3
- package/lib/browser/doc-model/editor-document-model-service.js.map +1 -1
- package/lib/browser/doc-model/editor-document-model.d.ts +8 -0
- package/lib/browser/doc-model/editor-document-model.d.ts.map +1 -1
- package/lib/browser/doc-model/editor-document-model.js +61 -11
- package/lib/browser/doc-model/editor-document-model.js.map +1 -1
- package/lib/browser/doc-model/editor-document-registry.js.map +1 -1
- package/lib/browser/doc-model/override.js.map +1 -1
- package/lib/browser/doc-model/save-task.js +1 -1
- package/lib/browser/doc-model/save-task.js.map +1 -1
- package/lib/browser/doc-model/saveParticipants.d.ts +7 -7
- package/lib/browser/doc-model/saveParticipants.d.ts.map +1 -1
- package/lib/browser/doc-model/saveParticipants.js +69 -38
- package/lib/browser/doc-model/saveParticipants.js.map +1 -1
- package/lib/browser/doc-model/types.d.ts +1 -1
- package/lib/browser/doc-model/types.d.ts.map +1 -1
- package/lib/browser/editor-collection.service.d.ts +8 -3
- package/lib/browser/editor-collection.service.d.ts.map +1 -1
- package/lib/browser/editor-collection.service.js +75 -66
- package/lib/browser/editor-collection.service.js.map +1 -1
- package/lib/browser/editor-opener.js.map +1 -1
- package/lib/browser/editor.contribution.d.ts.map +1 -1
- package/lib/browser/editor.contribution.js +31 -3
- package/lib/browser/editor.contribution.js.map +1 -1
- package/lib/browser/editor.decoration.service.d.ts +5 -6
- package/lib/browser/editor.decoration.service.d.ts.map +1 -1
- package/lib/browser/editor.decoration.service.js +9 -1
- package/lib/browser/editor.decoration.service.js.map +1 -1
- package/lib/browser/editor.override.js +2 -2
- package/lib/browser/editor.override.js.map +1 -1
- package/lib/browser/editor.status-bar.service.js.map +1 -1
- package/lib/browser/editor.view.d.ts.map +1 -1
- package/lib/browser/editor.view.js +20 -23
- package/lib/browser/editor.view.js.map +1 -1
- package/lib/browser/error.d.ts +1 -1
- package/lib/browser/error.d.ts.map +1 -1
- package/lib/browser/feature.js.map +1 -1
- package/lib/browser/format/format.service.js.map +1 -1
- package/lib/browser/format/formatterSelect.js.map +1 -1
- package/lib/browser/fs-resource/file-tree-set.js +6 -6
- package/lib/browser/fs-resource/file-tree-set.js.map +1 -1
- package/lib/browser/fs-resource/fs-editor-doc.js +1 -1
- package/lib/browser/fs-resource/fs-editor-doc.js.map +1 -1
- package/lib/browser/fs-resource/fs-resource.js.map +1 -1
- package/lib/browser/fs-resource/index.js.map +1 -1
- package/lib/browser/history/index.d.ts.map +1 -1
- package/lib/browser/history/index.js +2 -1
- package/lib/browser/history/index.js.map +1 -1
- package/lib/browser/index.d.ts.map +1 -1
- package/lib/browser/index.js +2 -0
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/language/diagnostic-collection.d.ts +5 -5
- package/lib/browser/language/diagnostic-collection.d.ts.map +1 -1
- package/lib/browser/language/diagnostic-collection.js +1 -1
- package/lib/browser/language/diagnostic-collection.js.map +1 -1
- package/lib/browser/language/language-status.contribution.js.map +1 -1
- package/lib/browser/language/language-status.service.js.map +1 -1
- package/lib/browser/language/language.service.d.ts +4 -3
- package/lib/browser/language/language.service.d.ts.map +1 -1
- package/lib/browser/language/language.service.js +8 -2
- package/lib/browser/language/language.service.js.map +1 -1
- package/lib/browser/menu/editor.context.js +3 -3
- package/lib/browser/menu/editor.context.js.map +1 -1
- package/lib/browser/menu/editor.menu.d.ts +2 -2
- package/lib/browser/menu/editor.menu.d.ts.map +1 -1
- package/lib/browser/menu/editor.menu.js +6 -8
- package/lib/browser/menu/editor.menu.js.map +1 -1
- package/lib/browser/menu/open-type-menu.contribution.js +9 -9
- package/lib/browser/menu/open-type-menu.contribution.js.map +1 -1
- package/lib/browser/menu/title-context.menu.js.map +1 -1
- package/lib/browser/merge-editor/merge-editor.contribution.d.ts +8 -0
- package/lib/browser/merge-editor/merge-editor.contribution.d.ts.map +1 -0
- package/lib/browser/merge-editor/merge-editor.contribution.js +29 -0
- package/lib/browser/merge-editor/merge-editor.contribution.js.map +1 -0
- package/lib/browser/merge-editor/merge-editor.provider.d.ts +8 -0
- package/lib/browser/merge-editor/merge-editor.provider.d.ts.map +1 -0
- package/lib/browser/merge-editor/merge-editor.provider.js +44 -0
- package/lib/browser/merge-editor/merge-editor.provider.js.map +1 -0
- package/lib/browser/monaco-contrib/callHierarchy/callHierarchy.contribution.js.map +1 -1
- package/lib/browser/monaco-contrib/callHierarchy/callHierarchy.service.js +7 -7
- package/lib/browser/monaco-contrib/callHierarchy/callHierarchy.service.js.map +1 -1
- package/lib/browser/monaco-contrib/command/command.service.d.ts +1 -1
- package/lib/browser/monaco-contrib/command/command.service.d.ts.map +1 -1
- package/lib/browser/monaco-contrib/command/command.service.js.map +1 -1
- package/lib/browser/monaco-contrib/tokenizer/textmate-registry.js.map +1 -1
- package/lib/browser/monaco-contrib/tokenizer/textmate.service.d.ts +2 -1
- package/lib/browser/monaco-contrib/tokenizer/textmate.service.d.ts.map +1 -1
- package/lib/browser/monaco-contrib/tokenizer/textmate.service.js +5 -2
- package/lib/browser/monaco-contrib/tokenizer/textmate.service.js.map +1 -1
- package/lib/browser/monaco-contrib/typeHierarchy/typeHierarchy.contribution.js.map +1 -1
- package/lib/browser/monaco-contrib/typeHierarchy/typeHierarchy.service.js +7 -7
- package/lib/browser/monaco-contrib/typeHierarchy/typeHierarchy.service.js.map +1 -1
- package/lib/browser/navigation.module.less +1 -1
- package/lib/browser/navigation.view.d.ts.map +1 -1
- package/lib/browser/navigation.view.js +26 -15
- package/lib/browser/navigation.view.js.map +1 -1
- package/lib/browser/preference/contribution.js.map +1 -1
- package/lib/browser/preference/converter.d.ts +3 -3
- package/lib/browser/preference/converter.d.ts.map +1 -1
- package/lib/browser/preference/schema.d.ts +1 -1
- package/lib/browser/preference/schema.d.ts.map +1 -1
- package/lib/browser/preference/schema.js +8 -8
- package/lib/browser/preference/schema.js.map +1 -1
- package/lib/browser/quick-open/go-to-line.js.map +1 -1
- package/lib/browser/quick-open/workspace-symbol-quickopen.d.ts.map +1 -1
- package/lib/browser/quick-open/workspace-symbol-quickopen.js +2 -2
- package/lib/browser/quick-open/workspace-symbol-quickopen.js.map +1 -1
- package/lib/browser/resource.service.js.map +1 -1
- package/lib/browser/tab.view.d.ts +1 -1
- package/lib/browser/tab.view.d.ts.map +1 -1
- package/lib/browser/tab.view.js +2 -2
- package/lib/browser/tab.view.js.map +1 -1
- package/lib/browser/types.d.ts +5 -5
- package/lib/browser/types.d.ts.map +1 -1
- package/lib/browser/untitled-resource.js +1 -1
- package/lib/browser/untitled-resource.js.map +1 -1
- package/lib/browser/view/suggest-widget.js.map +1 -1
- package/lib/browser/workbench-editor.service.d.ts +17 -0
- package/lib/browser/workbench-editor.service.d.ts.map +1 -1
- package/lib/browser/workbench-editor.service.js +259 -176
- package/lib/browser/workbench-editor.service.js.map +1 -1
- package/lib/common/doc-cache.d.ts +2 -2
- package/lib/common/doc-cache.d.ts.map +1 -1
- package/lib/common/editor.d.ts +20 -6
- package/lib/common/editor.d.ts.map +1 -1
- package/lib/common/editor.js +12 -1
- package/lib/common/editor.js.map +1 -1
- package/lib/common/language.d.ts +18 -7
- package/lib/common/language.d.ts.map +1 -1
- package/lib/common/language.js +15 -7
- package/lib/common/language.js.map +1 -1
- package/lib/common/mocks/workbench-editor.service.js.map +1 -1
- package/lib/common/resource.d.ts +8 -2
- package/lib/common/resource.d.ts.map +1 -1
- package/lib/common/resource.js +1 -0
- package/lib/common/resource.js.map +1 -1
- package/package.json +17 -16
- package/src/browser/breadcrumb/default.ts +299 -0
- package/src/browser/breadcrumb/document-symbol.ts +187 -0
- package/src/browser/breadcrumb/index.ts +96 -0
- package/src/browser/component.ts +204 -0
- package/src/browser/decoration-applier.ts +256 -0
- package/src/browser/diff/compare.ts +99 -0
- package/src/browser/diff/index.ts +81 -0
- package/src/browser/doc-cache/empty-doc-cache.ts +26 -0
- package/src/browser/doc-cache/index.ts +2 -0
- package/src/browser/doc-cache/local-storage-cache.ts +67 -0
- package/src/browser/doc-model/editor-document-error.ts +10 -0
- package/src/browser/doc-model/editor-document-model-service.ts +346 -0
- package/src/browser/doc-model/editor-document-model.ts +690 -0
- package/src/browser/doc-model/editor-document-registry.ts +119 -0
- package/src/browser/doc-model/editor-is-fn.ts +9 -0
- package/src/browser/doc-model/main.ts +4 -0
- package/src/browser/doc-model/override.ts +49 -0
- package/src/browser/doc-model/save-task.ts +88 -0
- package/src/browser/doc-model/saveParticipants.ts +227 -0
- package/src/browser/doc-model/types.ts +350 -0
- package/src/browser/editor-collection.service.ts +790 -0
- package/src/browser/editor-opener.ts +44 -0
- package/src/browser/editor.contribution.ts +1438 -0
- package/src/browser/editor.decoration.service.ts +247 -0
- package/src/browser/editor.less +4 -0
- package/src/browser/editor.module.less +548 -0
- package/src/browser/editor.override.ts +133 -0
- package/src/browser/editor.status-bar.service.ts +116 -0
- package/src/browser/editor.view.tsx +623 -0
- package/src/browser/error.ts +21 -0
- package/src/browser/feature.ts +63 -0
- package/src/browser/format/format.service.ts +95 -0
- package/src/browser/format/formatterSelect.ts +82 -0
- package/src/browser/fs-resource/file-tree-set.ts +126 -0
- package/src/browser/fs-resource/fs-editor-doc.ts +213 -0
- package/src/browser/fs-resource/fs-resource.ts +247 -0
- package/src/browser/fs-resource/index.ts +27 -0
- package/src/browser/grid/grid.service.ts +288 -0
- package/src/browser/history/index.ts +228 -0
- package/src/browser/index.ts +236 -0
- package/src/browser/language/diagnostic-collection.ts +83 -0
- package/src/browser/language/language-status.contribution.ts +81 -0
- package/src/browser/language/language-status.service.ts +32 -0
- package/src/browser/language/language.service.ts +185 -0
- package/src/browser/menu/editor.context.ts +186 -0
- package/src/browser/menu/editor.menu.ts +45 -0
- package/src/browser/menu/open-type-menu.contribution.ts +90 -0
- package/src/browser/menu/title-context.menu.ts +54 -0
- package/src/browser/merge-editor/merge-editor.contribution.ts +25 -0
- package/src/browser/merge-editor/merge-editor.provider.ts +36 -0
- package/src/browser/monaco-contrib/callHierarchy/callHierarchy.contribution.ts +78 -0
- package/src/browser/monaco-contrib/callHierarchy/callHierarchy.service.ts +160 -0
- package/src/browser/monaco-contrib/command/command.service.ts +438 -0
- package/src/browser/monaco-contrib/index.ts +4 -0
- package/src/browser/monaco-contrib/tokenizer/textmate-registry.ts +107 -0
- package/src/browser/monaco-contrib/tokenizer/textmate-tokenizer.ts +104 -0
- package/src/browser/monaco-contrib/tokenizer/textmate.service.ts +925 -0
- package/src/browser/monaco-contrib/typeHierarchy/typeHierarchy.contribution.ts +78 -0
- package/src/browser/monaco-contrib/typeHierarchy/typeHierarchy.service.ts +154 -0
- package/src/browser/navigation.module.less +96 -0
- package/src/browser/navigation.view.tsx +254 -0
- package/src/browser/preference/contribution.ts +8 -0
- package/src/browser/preference/converter.ts +793 -0
- package/src/browser/preference/schema.ts +1896 -0
- package/src/browser/preference/util.ts +14 -0
- package/src/browser/quick-open/go-to-line.ts +164 -0
- package/src/browser/quick-open/workspace-symbol-quickopen.ts +276 -0
- package/src/browser/resource.service.ts +263 -0
- package/src/browser/tab.view.tsx +514 -0
- package/src/browser/types.ts +467 -0
- package/src/browser/untitled-resource.ts +223 -0
- package/src/browser/view/editor.react.tsx +82 -0
- package/src/browser/view/react-hook.tsx +7 -0
- package/src/browser/view/suggest-widget.ts +77 -0
- package/src/browser/view/topPadding.ts +18 -0
- package/src/browser/workbench-editor.service.ts +2291 -0
- package/src/common/doc-cache.ts +117 -0
- package/src/common/editor.ts +799 -0
- package/src/common/index.ts +6 -0
- package/src/common/language-status.ts +33 -0
- package/src/common/language.ts +206 -0
- package/src/common/mocks/workbench-editor.service.ts +52 -0
- package/src/common/resource.ts +147 -0
- package/src/common/utils.ts +10 -0
- package/src/index.ts +1 -0
- package/lib/browser/component/scroll/scroll.d.ts +0 -2
- package/lib/browser/component/scroll/scroll.d.ts.map +0 -1
- package/lib/browser/component/scroll/scroll.js +0 -5
- package/lib/browser/component/scroll/scroll.js.map +0 -1
- package/lib/browser/component/scroll/scroll.module.less +0 -86
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Autowired } from '@opensumi/di';
|
|
2
|
+
import {
|
|
3
|
+
Domain,
|
|
4
|
+
CommandContribution,
|
|
5
|
+
CommandRegistry,
|
|
6
|
+
Event,
|
|
7
|
+
IContextKeyService,
|
|
8
|
+
IContextKey,
|
|
9
|
+
Uri,
|
|
10
|
+
} from '@opensumi/ide-core-browser';
|
|
11
|
+
import { RawContextKey } from '@opensumi/ide-core-browser/lib/raw-context-key';
|
|
12
|
+
import {
|
|
13
|
+
CallHierarchyItem,
|
|
14
|
+
CallHierarchyProviderRegistry,
|
|
15
|
+
ICallHierarchyService,
|
|
16
|
+
} from '@opensumi/ide-monaco/lib/browser/contrib/callHierarchy';
|
|
17
|
+
import { Position } from '@opensumi/monaco-editor-core/esm/vs/editor/common/core/position';
|
|
18
|
+
|
|
19
|
+
import { BrowserEditorContribution, IEditor, IEditorFeatureRegistry } from '../../types';
|
|
20
|
+
|
|
21
|
+
export const executePrepareCallHierarchyCommand = {
|
|
22
|
+
id: '_executePrepareCallHierarchy',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const executeProvideIncomingCallsCommand = {
|
|
26
|
+
id: '_executeProvideIncomingCalls',
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const executeProvideOutgoingCallsCommand = {
|
|
30
|
+
id: '_executeProvideOutgoingCalls',
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const _ctxHasCallHierarchyProvider = new RawContextKey<boolean>('editorHasCallHierarchyProvider', false);
|
|
34
|
+
|
|
35
|
+
@Domain(CommandContribution, BrowserEditorContribution)
|
|
36
|
+
export class CallHierarchyContribution implements CommandContribution, BrowserEditorContribution {
|
|
37
|
+
private ctxHasProvider: IContextKey<boolean>;
|
|
38
|
+
|
|
39
|
+
@Autowired(IContextKeyService)
|
|
40
|
+
protected readonly contextKeyService: IContextKeyService;
|
|
41
|
+
|
|
42
|
+
@Autowired(ICallHierarchyService)
|
|
43
|
+
protected readonly callHierarchyService: ICallHierarchyService;
|
|
44
|
+
|
|
45
|
+
registerCommands(commands: CommandRegistry) {
|
|
46
|
+
commands.registerCommand(executePrepareCallHierarchyCommand, {
|
|
47
|
+
execute: (resource: Uri, position: Position) =>
|
|
48
|
+
this.callHierarchyService.prepareCallHierarchyProvider(resource, position),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
commands.registerCommand(executeProvideIncomingCallsCommand, {
|
|
52
|
+
execute: (item: CallHierarchyItem) => this.callHierarchyService.provideIncomingCalls(item),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
commands.registerCommand(executeProvideOutgoingCallsCommand, {
|
|
56
|
+
execute: (item: CallHierarchyItem) => this.callHierarchyService.provideOutgoingCalls(item),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
registerEditorFeature(registry: IEditorFeatureRegistry) {
|
|
61
|
+
this.ctxHasProvider = _ctxHasCallHierarchyProvider.bind(this.contextKeyService);
|
|
62
|
+
|
|
63
|
+
registry.registerEditorFeatureContribution({
|
|
64
|
+
contribute: (editor: IEditor) => {
|
|
65
|
+
const monacoEditor = editor.monacoEditor;
|
|
66
|
+
return Event.any<any>(
|
|
67
|
+
monacoEditor.onDidChangeModel,
|
|
68
|
+
monacoEditor.onDidChangeModelLanguage,
|
|
69
|
+
CallHierarchyProviderRegistry.onDidChange,
|
|
70
|
+
)(() => {
|
|
71
|
+
if (monacoEditor.hasModel()) {
|
|
72
|
+
this.ctxHasProvider.set(CallHierarchyProviderRegistry.has(monacoEditor.getModel()));
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { Injectable, Autowired } from '@opensumi/di';
|
|
2
|
+
import {
|
|
3
|
+
CancellationToken,
|
|
4
|
+
IDisposable,
|
|
5
|
+
IPosition,
|
|
6
|
+
arrays,
|
|
7
|
+
RefCountedDisposable,
|
|
8
|
+
onUnexpectedExternalError,
|
|
9
|
+
URI,
|
|
10
|
+
Uri,
|
|
11
|
+
} from '@opensumi/ide-core-common';
|
|
12
|
+
import {
|
|
13
|
+
CallHierarchyItem,
|
|
14
|
+
CallHierarchyProvider,
|
|
15
|
+
CallHierarchyProviderRegistry,
|
|
16
|
+
ICallHierarchyService,
|
|
17
|
+
IncomingCall,
|
|
18
|
+
OutgoingCall,
|
|
19
|
+
} from '@opensumi/ide-monaco/lib/browser/contrib/callHierarchy';
|
|
20
|
+
import { ITextModel, Position } from '@opensumi/ide-monaco/lib/browser/monaco-api/types';
|
|
21
|
+
|
|
22
|
+
import { IEditorDocumentModelService } from '../../doc-model/types';
|
|
23
|
+
|
|
24
|
+
const { isNonEmptyArray } = arrays;
|
|
25
|
+
|
|
26
|
+
declare type ProviderResult<T> = T | undefined | null | Thenable<T | undefined | null>;
|
|
27
|
+
/* ---------------------------------------------------------------------------------------------
|
|
28
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
29
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
30
|
+
*--------------------------------------------------------------------------------------------*/
|
|
31
|
+
// Some code copied and modified from https://github.com/microsoft/vscode/tree/main/src/vs/workbench/contrib/callHierarchy/common/callHierarchy.ts
|
|
32
|
+
|
|
33
|
+
export class CallHierarchyModel {
|
|
34
|
+
static async create(
|
|
35
|
+
model: ITextModel,
|
|
36
|
+
position: IPosition,
|
|
37
|
+
token: CancellationToken,
|
|
38
|
+
): Promise<CallHierarchyModel | undefined> {
|
|
39
|
+
const [provider] = CallHierarchyProviderRegistry.ordered(model);
|
|
40
|
+
if (!provider) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
const session = await provider.prepareCallHierarchy(model, position, token);
|
|
44
|
+
if (!session) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
return new CallHierarchyModel(
|
|
48
|
+
session.roots.reduce((p, c) => p + c._sessionId, ''),
|
|
49
|
+
provider,
|
|
50
|
+
session.roots,
|
|
51
|
+
new RefCountedDisposable(session),
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
readonly root: CallHierarchyItem;
|
|
56
|
+
|
|
57
|
+
private constructor(
|
|
58
|
+
readonly id: string,
|
|
59
|
+
readonly provider: CallHierarchyProvider,
|
|
60
|
+
readonly roots: CallHierarchyItem[],
|
|
61
|
+
readonly ref: RefCountedDisposable,
|
|
62
|
+
) {
|
|
63
|
+
this.root = roots[0];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
dispose(): void {
|
|
67
|
+
this.ref.release();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
fork(item: CallHierarchyItem): CallHierarchyModel {
|
|
71
|
+
const that = this;
|
|
72
|
+
return new (class extends CallHierarchyModel {
|
|
73
|
+
constructor() {
|
|
74
|
+
super(that.id, that.provider, [item], that.ref.acquire());
|
|
75
|
+
}
|
|
76
|
+
})();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async resolveIncomingCalls(item: CallHierarchyItem, token: CancellationToken): Promise<IncomingCall[]> {
|
|
80
|
+
try {
|
|
81
|
+
const result = await this.provider.provideIncomingCalls(item, token);
|
|
82
|
+
if (isNonEmptyArray(result)) {
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
} catch (e) {
|
|
86
|
+
onUnexpectedExternalError(e);
|
|
87
|
+
}
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async resolveOutgoingCalls(item: CallHierarchyItem, token: CancellationToken): Promise<OutgoingCall[]> {
|
|
92
|
+
try {
|
|
93
|
+
const result = await this.provider.provideOutgoingCalls(item, token);
|
|
94
|
+
if (isNonEmptyArray(result)) {
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
} catch (e) {
|
|
98
|
+
onUnexpectedExternalError(e);
|
|
99
|
+
}
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@Injectable()
|
|
105
|
+
export class CallHierarchyService implements ICallHierarchyService {
|
|
106
|
+
@Autowired(IEditorDocumentModelService)
|
|
107
|
+
protected readonly modelService: IEditorDocumentModelService;
|
|
108
|
+
|
|
109
|
+
private models: Map<string, CallHierarchyModel> = new Map<string, CallHierarchyModel>();
|
|
110
|
+
|
|
111
|
+
registerCallHierarchyProvider(selector: any, provider: CallHierarchyProvider) {
|
|
112
|
+
CallHierarchyProviderRegistry.register(selector, provider);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async prepareCallHierarchyProvider(resource: Uri, position: Position) {
|
|
116
|
+
let textModel = this.modelService.getModelReference(URI.parse(resource.toString()))?.instance.getMonacoModel();
|
|
117
|
+
let textModelReference: IDisposable | undefined;
|
|
118
|
+
if (!textModel) {
|
|
119
|
+
const result = await this.modelService.createModelReference(URI.parse(resource.toString()));
|
|
120
|
+
textModel = result.instance.getMonacoModel();
|
|
121
|
+
textModelReference = result;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
const model = await CallHierarchyModel.create(textModel, position, CancellationToken.None);
|
|
126
|
+
if (!model) {
|
|
127
|
+
return [];
|
|
128
|
+
}
|
|
129
|
+
//
|
|
130
|
+
this.models.set(model.id, model);
|
|
131
|
+
this.models.forEach((value, key, map) => {
|
|
132
|
+
if (map.size > 10) {
|
|
133
|
+
value.dispose();
|
|
134
|
+
this.models.delete(key);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
return [model.root];
|
|
138
|
+
} finally {
|
|
139
|
+
textModelReference?.dispose();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
provideIncomingCalls(item: CallHierarchyItem): ProviderResult<IncomingCall[]> {
|
|
144
|
+
const model = this.models.get(item._sessionId);
|
|
145
|
+
if (!model) {
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return model.resolveIncomingCalls(item, CancellationToken.None);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
provideOutgoingCalls(item: CallHierarchyItem): ProviderResult<OutgoingCall[]> {
|
|
153
|
+
const model = this.models.get(item._sessionId);
|
|
154
|
+
if (!model) {
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return model.resolveOutgoingCalls(item, CancellationToken.None);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
import { Injectable, Autowired } from '@opensumi/di';
|
|
2
|
+
import {
|
|
3
|
+
Command,
|
|
4
|
+
Emitter,
|
|
5
|
+
CommandRegistry,
|
|
6
|
+
CommandHandler,
|
|
7
|
+
HANDLER_NOT_FOUND,
|
|
8
|
+
ILogger,
|
|
9
|
+
EDITOR_COMMANDS,
|
|
10
|
+
CommandService,
|
|
11
|
+
IReporterService,
|
|
12
|
+
REPORT_NAME,
|
|
13
|
+
ServiceNames,
|
|
14
|
+
memoize,
|
|
15
|
+
Uri,
|
|
16
|
+
MonacoOverrideServiceRegistry,
|
|
17
|
+
} from '@opensumi/ide-core-browser';
|
|
18
|
+
import {
|
|
19
|
+
CommandsRegistry as MonacoCommandsRegistry,
|
|
20
|
+
EditorExtensionsRegistry,
|
|
21
|
+
ICommandEvent,
|
|
22
|
+
ICommandService,
|
|
23
|
+
IMonacoActionRegistry,
|
|
24
|
+
IMonacoCommandService,
|
|
25
|
+
IMonacoCommandsRegistry,
|
|
26
|
+
MonacoEditorCommandHandler,
|
|
27
|
+
} from '@opensumi/ide-monaco/lib/browser/contrib/command';
|
|
28
|
+
import { URI } from '@opensumi/ide-monaco/lib/browser/monaco-api';
|
|
29
|
+
import { StandaloneServices } from '@opensumi/ide-monaco/lib/browser/monaco-api/services';
|
|
30
|
+
import { Event, ICodeEditor, IEvent } from '@opensumi/ide-monaco/lib/browser/monaco-api/types';
|
|
31
|
+
|
|
32
|
+
import { MonacoCodeService } from '../../editor.override';
|
|
33
|
+
import { EditorCollectionService, WorkbenchEditorService } from '../../types';
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* vscode 会有一些别名 command,如果直接执行这些别名 command 会报错,做一个转换
|
|
37
|
+
*/
|
|
38
|
+
const MonacoCommandAlias = {
|
|
39
|
+
'editor.action.smartSelect.grow': 'editor.action.smartSelect.expand',
|
|
40
|
+
cursorWordPartStartLeft: 'cursorWordPartLeft',
|
|
41
|
+
cursorWordPartStartLeftSelect: 'cursorWordPartLeftSelect',
|
|
42
|
+
'editor.action.previewDeclaration': 'editor.action.peekDefinition',
|
|
43
|
+
'editor.action.openDeclarationToTheSide': 'editor.action.revealDefinitionAside',
|
|
44
|
+
'editor.action.goToDeclaration': 'editor.action.revealDefinition',
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* monaco 命令分两种
|
|
49
|
+
* 一种命令不需要带参数,是封装过的命令,即为 action
|
|
50
|
+
* 一种是正常命令,执行可以带参数
|
|
51
|
+
*/
|
|
52
|
+
export enum MonacoCommandType {
|
|
53
|
+
ACTION,
|
|
54
|
+
COMMAND,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type MonacoCommand = Command & { type: MonacoCommandType };
|
|
58
|
+
|
|
59
|
+
@Injectable()
|
|
60
|
+
export class MonacoCommandService implements IMonacoCommandService {
|
|
61
|
+
_serviceBrand: undefined;
|
|
62
|
+
|
|
63
|
+
private _onDidExecuteCommand: Emitter<ICommandEvent> = new Emitter<ICommandEvent>();
|
|
64
|
+
|
|
65
|
+
onDidExecuteCommand: Event<ICommandEvent> = this._onDidExecuteCommand.event;
|
|
66
|
+
|
|
67
|
+
private delegate: ICommandService;
|
|
68
|
+
/**
|
|
69
|
+
* 事件触发器,在执行命令的时候会触发
|
|
70
|
+
* @type {Emitter<ICommandEvent>}
|
|
71
|
+
* @memberof MonacoCommandService
|
|
72
|
+
*/
|
|
73
|
+
_onWillExecuteCommand: Emitter<ICommandEvent> = new Emitter<ICommandEvent>();
|
|
74
|
+
|
|
75
|
+
@Autowired(ILogger)
|
|
76
|
+
private logger: ILogger;
|
|
77
|
+
|
|
78
|
+
@Autowired(CommandRegistry)
|
|
79
|
+
commandRegistry: CommandRegistry;
|
|
80
|
+
|
|
81
|
+
@Autowired(CommandService)
|
|
82
|
+
commandService: CommandService;
|
|
83
|
+
|
|
84
|
+
@Autowired(IReporterService)
|
|
85
|
+
reporterService: IReporterService;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 设置委托对象
|
|
89
|
+
* @param delegate 真正要执行 monaco 内部 command 的 commandSerice
|
|
90
|
+
*/
|
|
91
|
+
setDelegate(delegate: ICommandService) {
|
|
92
|
+
this.delegate = delegate;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
get onWillExecuteCommand(): IEvent<ICommandEvent> {
|
|
96
|
+
return this._onWillExecuteCommand.event;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 执行命令
|
|
101
|
+
* 先去全局 commands 里找,若没有尝试执行 delegate 的 command
|
|
102
|
+
* @param commandId
|
|
103
|
+
* @param args
|
|
104
|
+
*/
|
|
105
|
+
async executeCommand<T>(commandId: string, ...args: any[]): Promise<T | undefined> {
|
|
106
|
+
this.logger.debug('command: ' + commandId);
|
|
107
|
+
this._onWillExecuteCommand.fire({ commandId, args });
|
|
108
|
+
try {
|
|
109
|
+
const res = await this.commandService.executeCommand<T>(commandId, ...args);
|
|
110
|
+
this._onDidExecuteCommand.fire({ commandId, args });
|
|
111
|
+
return res;
|
|
112
|
+
} catch (err) {
|
|
113
|
+
// 如果不是 handler 未找到直接抛错,否则执行 delegate 逻辑
|
|
114
|
+
if (err?.name !== HANDLER_NOT_FOUND) {
|
|
115
|
+
throw err;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (this.delegate) {
|
|
119
|
+
const res = this.delegate.executeCommand(
|
|
120
|
+
MonacoCommandAlias[commandId] ? MonacoCommandAlias[commandId] : commandId,
|
|
121
|
+
...args,
|
|
122
|
+
);
|
|
123
|
+
this._onDidExecuteCommand.fire({ commandId, args });
|
|
124
|
+
return res;
|
|
125
|
+
}
|
|
126
|
+
this.reporterService.point(REPORT_NAME.NOT_FOUND_COMMAND, commandId);
|
|
127
|
+
return Promise.reject(new Error(`command '${commandId}' not found`));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
@Injectable()
|
|
132
|
+
export class MonacoCommandRegistry implements IMonacoCommandsRegistry {
|
|
133
|
+
@Autowired(CommandRegistry)
|
|
134
|
+
private commands: CommandRegistry;
|
|
135
|
+
|
|
136
|
+
@Autowired(WorkbenchEditorService)
|
|
137
|
+
private workbenchEditorService: WorkbenchEditorService;
|
|
138
|
+
|
|
139
|
+
@Autowired(EditorCollectionService)
|
|
140
|
+
private editorCollectionService: EditorCollectionService;
|
|
141
|
+
|
|
142
|
+
@Autowired(MonacoOverrideServiceRegistry)
|
|
143
|
+
private readonly overrideServiceRegistry: MonacoOverrideServiceRegistry;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* 校验 command id 是否是 monaco id
|
|
147
|
+
* @param command 要校验的 id
|
|
148
|
+
* @returns 若找到则为转换过 monaco id,否则为 undefined
|
|
149
|
+
*/
|
|
150
|
+
validate(command: string): string | undefined {
|
|
151
|
+
return this.commands.getRawCommand(command)?.id;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* 注册 monaco 命令
|
|
156
|
+
* 命令 id 会统一加入 monaco 前缀
|
|
157
|
+
* monaco handler 会注入当前 editor 参数
|
|
158
|
+
* @param command 注册的命令
|
|
159
|
+
* @param handler 命令处理函数
|
|
160
|
+
*/
|
|
161
|
+
registerCommand(command: Command, handler: MonacoEditorCommandHandler): void {
|
|
162
|
+
this.commands.registerCommand(command, this.newHandler(handler));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* 注册处理函数函数
|
|
167
|
+
* monaco handler 会注入当前 editor 参数
|
|
168
|
+
* @param command 命令 id
|
|
169
|
+
* @param handler 命令处理函数
|
|
170
|
+
*/
|
|
171
|
+
registerHandler(commandID: string, handler: MonacoEditorCommandHandler): void {
|
|
172
|
+
this.commands.registerHandler(commandID, this.newHandler(handler));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* 包装 monaco 命令处理函数为内部处理函数
|
|
177
|
+
* @param monacoHandler 要处理的 monaco 命令处理函数
|
|
178
|
+
*/
|
|
179
|
+
protected newHandler(monacoHandler: MonacoEditorCommandHandler): CommandHandler {
|
|
180
|
+
return {
|
|
181
|
+
execute: (...args) => this.execute(monacoHandler, ...args),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* 给 monacoHandler 传递 editor 参数
|
|
187
|
+
* @param monacoHandler 要处理的 monaco 命令函数
|
|
188
|
+
* @param args 要透传的参数
|
|
189
|
+
*/
|
|
190
|
+
protected execute(monacoHandler: MonacoEditorCommandHandler, ...args: any[]): any {
|
|
191
|
+
const editor = this.getActiveCodeEditor();
|
|
192
|
+
if (editor) {
|
|
193
|
+
// editor.focus();
|
|
194
|
+
return Promise.resolve(monacoHandler.execute(editor, ...args));
|
|
195
|
+
}
|
|
196
|
+
return Promise.resolve();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
get codeEditorService(): MonacoCodeService | undefined {
|
|
200
|
+
return this.overrideServiceRegistry.getRegisteredService(ServiceNames.CODE_EDITOR_SERVICE);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* 获取当前活动的编辑器
|
|
205
|
+
* 此处的活动编辑器和 workbenchEditorService.currentEditor 的概念不同,对于diffEditor,需要获取确实的那个editor而不是modifiedEditor
|
|
206
|
+
*/
|
|
207
|
+
protected getActiveCodeEditor(): ICodeEditor | undefined {
|
|
208
|
+
// 先从 monaco 内部获取到当前 focus 的 editor
|
|
209
|
+
const editor = this.codeEditorService?.getFocusedCodeEditor();
|
|
210
|
+
if (editor) {
|
|
211
|
+
return editor;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// 如果获取不到再从 editor-collection 的焦点追踪,contextMenu追踪中取
|
|
215
|
+
if (this.editorCollectionService.currentEditor) {
|
|
216
|
+
return this.editorCollectionService.currentEditor.monacoEditor;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// 使用当前 editorGroup.editor 兜底
|
|
220
|
+
const editorGroup = this.workbenchEditorService.currentEditorGroup;
|
|
221
|
+
if (editorGroup) {
|
|
222
|
+
const editor = editorGroup.currentOrPreviousFocusedEditor || editorGroup.currentEditor;
|
|
223
|
+
if (editor) {
|
|
224
|
+
return editor.monacoEditor;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
@Injectable()
|
|
231
|
+
export class MonacoActionRegistry implements IMonacoActionRegistry {
|
|
232
|
+
private static COMMON_ACTIONS = new Map<string, string>([
|
|
233
|
+
['undo', EDITOR_COMMANDS.UNDO.id],
|
|
234
|
+
['redo', EDITOR_COMMANDS.REDO.id],
|
|
235
|
+
['editor.action.selectAll', EDITOR_COMMANDS.SELECT_ALL.id],
|
|
236
|
+
]);
|
|
237
|
+
|
|
238
|
+
private static CONVERT_MONACO_COMMAND_ARGS = new Map<string, (...args: any[]) => any[]>([
|
|
239
|
+
['editor.action.showReferences', (uri, ...args) => [URI.parse(uri), ...args]],
|
|
240
|
+
['editor.action.goToLocations', (uri, ...args) => [URI.parse(uri), ...args]],
|
|
241
|
+
]);
|
|
242
|
+
|
|
243
|
+
private static CONVERT_MONACO_ACTIONS_TO_CONTRIBUTION_ID = new Map<string, string>([
|
|
244
|
+
['editor.action.rename', 'editor.contrib.renameController'],
|
|
245
|
+
]);
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* 要排除注册的 Action
|
|
249
|
+
*
|
|
250
|
+
* @protected
|
|
251
|
+
* @memberof MonacoActionModule
|
|
252
|
+
*/
|
|
253
|
+
protected static readonly EXCLUDE_ACTIONS = [
|
|
254
|
+
'setContext',
|
|
255
|
+
'editor.action.quickCommand',
|
|
256
|
+
'editor.action.quickOutline',
|
|
257
|
+
'editor.action.toggleHighContrast',
|
|
258
|
+
'editor.action.gotoLine',
|
|
259
|
+
];
|
|
260
|
+
|
|
261
|
+
@Autowired()
|
|
262
|
+
monacoCommandRegistry: MonacoCommandRegistry;
|
|
263
|
+
|
|
264
|
+
@Autowired(MonacoOverrideServiceRegistry)
|
|
265
|
+
private readonly overrideServiceRegistry: MonacoOverrideServiceRegistry;
|
|
266
|
+
|
|
267
|
+
@memoize
|
|
268
|
+
get globalInstantiationService() {
|
|
269
|
+
const codeEditorService = this.overrideServiceRegistry.getRegisteredService(ServiceNames.CODE_EDITOR_SERVICE);
|
|
270
|
+
const textModelService = this.overrideServiceRegistry.getRegisteredService(ServiceNames.TEXT_MODEL_SERVICE);
|
|
271
|
+
const contextKeyService = this.overrideServiceRegistry.getRegisteredService(ServiceNames.CONTEXT_KEY_SERVICE);
|
|
272
|
+
const globalInstantiationService = StandaloneServices.initialize({
|
|
273
|
+
codeEditorService,
|
|
274
|
+
textModelService,
|
|
275
|
+
contextKeyService,
|
|
276
|
+
});
|
|
277
|
+
return globalInstantiationService;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
@memoize
|
|
281
|
+
get monacoEditorRegistry() {
|
|
282
|
+
return EditorExtensionsRegistry;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
@memoize
|
|
286
|
+
get monacoCommands() {
|
|
287
|
+
return MonacoCommandsRegistry.getCommands();
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
registerMonacoActions() {
|
|
291
|
+
const editorActions = new Map(
|
|
292
|
+
this.monacoEditorRegistry.getEditorActions().map(({ id, label, alias }) => [
|
|
293
|
+
id,
|
|
294
|
+
{
|
|
295
|
+
label,
|
|
296
|
+
alias,
|
|
297
|
+
},
|
|
298
|
+
]),
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
for (const id of this.monacoCommands.keys()) {
|
|
302
|
+
if (MonacoActionRegistry.EXCLUDE_ACTIONS.includes(id)) {
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const data: { label?: string; alias?: string } = editorActions.get(id) ?? {};
|
|
307
|
+
const handler = this.actAndComHandler(editorActions, id);
|
|
308
|
+
this.monacoCommandRegistry.registerCommand(
|
|
309
|
+
{
|
|
310
|
+
id,
|
|
311
|
+
label: data.label,
|
|
312
|
+
alias: data.alias,
|
|
313
|
+
},
|
|
314
|
+
handler,
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
// 将 monaco 命令处理函数代理到有 label 的新的命令上
|
|
318
|
+
const command = MonacoActionRegistry.COMMON_ACTIONS.get(id);
|
|
319
|
+
if (command) {
|
|
320
|
+
this.monacoCommandRegistry.registerHandler(command, handler);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* monaco 内部有些 contribution 既注册了 actions 又注册了 commands,在这里优先调取 commands
|
|
327
|
+
*/
|
|
328
|
+
private actAndComHandler(
|
|
329
|
+
actions: Map<
|
|
330
|
+
string,
|
|
331
|
+
{
|
|
332
|
+
label: string;
|
|
333
|
+
alias: string;
|
|
334
|
+
}
|
|
335
|
+
>,
|
|
336
|
+
id: string,
|
|
337
|
+
): MonacoEditorCommandHandler {
|
|
338
|
+
if (MonacoActionRegistry.CONVERT_MONACO_ACTIONS_TO_CONTRIBUTION_ID.has(id)) {
|
|
339
|
+
const toConver = MonacoActionRegistry.CONVERT_MONACO_ACTIONS_TO_CONTRIBUTION_ID.get(id)!;
|
|
340
|
+
if (this.monacoEditorRegistry.getSomeEditorContributions([toConver]).length > 0) {
|
|
341
|
+
return this.newCommandHandler(id);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return actions.has(id) ? this.newActionHandler(id) : this.newCommandHandler(id);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* 是否是 _execute 开头的 monaco 命令
|
|
349
|
+
*/
|
|
350
|
+
private isInternalExecuteCommand(commandId: string) {
|
|
351
|
+
return commandId.startsWith('_execute');
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* monaco 内部会判断 uri 执行是否是 Uri 实例,执行改类命令统一转换一下
|
|
356
|
+
* @param args
|
|
357
|
+
*/
|
|
358
|
+
private processInternalCommandArgument(commandId: string, args: any[] = []): any[] {
|
|
359
|
+
if (this.isInternalExecuteCommand(commandId)) {
|
|
360
|
+
return args.map((arg) => (arg instanceof Uri ? URI.revive(arg) : arg));
|
|
361
|
+
} else if (MonacoActionRegistry.CONVERT_MONACO_COMMAND_ARGS.has(commandId)) {
|
|
362
|
+
return MonacoActionRegistry.CONVERT_MONACO_COMMAND_ARGS.get(commandId)!(...args);
|
|
363
|
+
}
|
|
364
|
+
return args;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* 调用 monaco 内部 _commandService 执行命令
|
|
369
|
+
* 实际执行的就是 MonacoCommandService
|
|
370
|
+
* @param commandId 命令名称
|
|
371
|
+
*/
|
|
372
|
+
protected newCommandHandler(commandId: string): MonacoEditorCommandHandler {
|
|
373
|
+
return {
|
|
374
|
+
execute: (editor, ...args) => {
|
|
375
|
+
if (!editor) {
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
const editorCommand =
|
|
379
|
+
!!this.monacoEditorRegistry.getEditorCommand(commandId) ||
|
|
380
|
+
!(
|
|
381
|
+
this.isInternalExecuteCommand(commandId) ||
|
|
382
|
+
commandId === 'setContext' ||
|
|
383
|
+
MonacoActionRegistry.COMMON_ACTIONS.has(commandId)
|
|
384
|
+
);
|
|
385
|
+
const instantiationService = editorCommand
|
|
386
|
+
? editor && editor['_instantiationService']
|
|
387
|
+
: this.globalInstantiationService;
|
|
388
|
+
if (!instantiationService) {
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
const commandArgs = this.processInternalCommandArgument(commandId, args);
|
|
392
|
+
return instantiationService.invokeFunction(this.monacoCommands.get(commandId)?.handler, ...commandArgs);
|
|
393
|
+
},
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* 包装 action 为命令处理函数
|
|
399
|
+
* 调用 getAction 执行 run 命令
|
|
400
|
+
* @param id action id
|
|
401
|
+
*/
|
|
402
|
+
protected newActionHandler(id: string): MonacoEditorCommandHandler {
|
|
403
|
+
return {
|
|
404
|
+
execute: (editor) => {
|
|
405
|
+
const action = editor.getAction(id);
|
|
406
|
+
if (action && action.isSupported()) {
|
|
407
|
+
return this.runAction(id, editor);
|
|
408
|
+
}
|
|
409
|
+
},
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* 执行 action
|
|
415
|
+
* @param id 要执行的 action
|
|
416
|
+
* @param editor 执行 action 的 editor,默认为当前 editor
|
|
417
|
+
*/
|
|
418
|
+
protected runAction(id: string, editor: ICodeEditor): Promise<void> {
|
|
419
|
+
if (editor) {
|
|
420
|
+
const action = editor.getAction(id);
|
|
421
|
+
if (action) {
|
|
422
|
+
return action.run();
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
return Promise.resolve();
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* 生成键盘处理函数
|
|
431
|
+
* @param action 对应 action
|
|
432
|
+
*/
|
|
433
|
+
protected newKeyboardHandler(action: string): MonacoEditorCommandHandler {
|
|
434
|
+
return {
|
|
435
|
+
execute: (editor, ...args) => editor.trigger('keyboard', action, args),
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
}
|