@theia/plugin-ext 1.34.2 → 1.36.0-next.21

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.
Files changed (131) hide show
  1. package/lib/common/plugin-api-rpc-model.d.ts +18 -1
  2. package/lib/common/plugin-api-rpc-model.d.ts.map +1 -1
  3. package/lib/common/plugin-api-rpc-model.js.map +1 -1
  4. package/lib/common/plugin-api-rpc.d.ts +10 -5
  5. package/lib/common/plugin-api-rpc.d.ts.map +1 -1
  6. package/lib/common/plugin-api-rpc.js.map +1 -1
  7. package/lib/common/plugin-protocol.d.ts +44 -10
  8. package/lib/common/plugin-protocol.d.ts.map +1 -1
  9. package/lib/common/plugin-protocol.js.map +1 -1
  10. package/lib/hosted/browser/hosted-plugin.d.ts.map +1 -1
  11. package/lib/hosted/browser/hosted-plugin.js +16 -21
  12. package/lib/hosted/browser/hosted-plugin.js.map +1 -1
  13. package/lib/hosted/node/hosted-plugin-deployer-handler.js +1 -1
  14. package/lib/hosted/node/hosted-plugin-deployer-handler.js.map +1 -1
  15. package/lib/hosted/node/hosted-plugin-process.js.map +1 -1
  16. package/lib/hosted/node/plugin-activation-events.d.ts +7 -0
  17. package/lib/hosted/node/plugin-activation-events.d.ts.map +1 -0
  18. package/lib/hosted/node/plugin-activation-events.js +96 -0
  19. package/lib/hosted/node/plugin-activation-events.js.map +1 -0
  20. package/lib/hosted/node/plugin-host-rpc.js +2 -2
  21. package/lib/hosted/node/plugin-host-rpc.js.map +1 -1
  22. package/lib/hosted/node/plugin-manifest-loader.d.ts +2 -1
  23. package/lib/hosted/node/plugin-manifest-loader.d.ts.map +1 -1
  24. package/lib/hosted/node/plugin-manifest-loader.js +2 -1
  25. package/lib/hosted/node/plugin-manifest-loader.js.map +1 -1
  26. package/lib/hosted/node/scanners/scanner-theia.d.ts.map +1 -1
  27. package/lib/hosted/node/scanners/scanner-theia.js +27 -36
  28. package/lib/hosted/node/scanners/scanner-theia.js.map +1 -1
  29. package/lib/main/browser/data-transfer/data-transfer-type-converters.d.ts +9 -0
  30. package/lib/main/browser/data-transfer/data-transfer-type-converters.d.ts.map +1 -0
  31. package/lib/main/browser/data-transfer/data-transfer-type-converters.js +65 -0
  32. package/lib/main/browser/data-transfer/data-transfer-type-converters.js.map +1 -0
  33. package/lib/main/browser/dialogs/modal-notification.d.ts.map +1 -1
  34. package/lib/main/browser/dialogs/modal-notification.js +4 -2
  35. package/lib/main/browser/dialogs/modal-notification.js.map +1 -1
  36. package/lib/main/browser/languages-main.d.ts +8 -1
  37. package/lib/main/browser/languages-main.d.ts.map +1 -1
  38. package/lib/main/browser/languages-main.js +26 -2
  39. package/lib/main/browser/languages-main.js.map +1 -1
  40. package/lib/main/browser/main-file-system-event-service.d.ts.map +1 -1
  41. package/lib/main/browser/main-file-system-event-service.js +6 -9
  42. package/lib/main/browser/main-file-system-event-service.js.map +1 -1
  43. package/lib/main/browser/plugin-contribution-handler.d.ts.map +1 -1
  44. package/lib/main/browser/plugin-contribution-handler.js +4 -1
  45. package/lib/main/browser/plugin-contribution-handler.js.map +1 -1
  46. package/lib/main/browser/plugin-ext-frontend-module.d.ts.map +1 -1
  47. package/lib/main/browser/plugin-ext-frontend-module.js +3 -0
  48. package/lib/main/browser/plugin-ext-frontend-module.js.map +1 -1
  49. package/lib/main/browser/text-editors-main.d.ts +2 -2
  50. package/lib/main/browser/text-editors-main.d.ts.map +1 -1
  51. package/lib/main/browser/text-editors-main.js +2 -2
  52. package/lib/main/browser/text-editors-main.js.map +1 -1
  53. package/lib/main/browser/webview/webview-context-keys.d.ts +13 -0
  54. package/lib/main/browser/webview/webview-context-keys.d.ts.map +1 -0
  55. package/lib/main/browser/webview/webview-context-keys.js +64 -0
  56. package/lib/main/browser/webview/webview-context-keys.js.map +1 -0
  57. package/lib/main/node/handlers/plugin-theia-directory-handler.js +1 -1
  58. package/lib/main/node/handlers/plugin-theia-directory-handler.js.map +1 -1
  59. package/lib/plugin/dialogs.js +2 -2
  60. package/lib/plugin/dialogs.js.map +1 -1
  61. package/lib/plugin/file-system-ext-impl.d.ts +11 -5
  62. package/lib/plugin/file-system-ext-impl.d.ts.map +1 -1
  63. package/lib/plugin/file-system-ext-impl.js +8 -16
  64. package/lib/plugin/file-system-ext-impl.js.map +1 -1
  65. package/lib/plugin/known-commands.d.ts.map +1 -1
  66. package/lib/plugin/known-commands.js +13 -0
  67. package/lib/plugin/known-commands.js.map +1 -1
  68. package/lib/plugin/languages/document-drop-edit.d.ts +16 -0
  69. package/lib/plugin/languages/document-drop-edit.d.ts.map +1 -0
  70. package/lib/plugin/languages/document-drop-edit.js +23 -0
  71. package/lib/plugin/languages/document-drop-edit.js.map +1 -0
  72. package/lib/plugin/languages.d.ts +9 -2
  73. package/lib/plugin/languages.d.ts.map +1 -1
  74. package/lib/plugin/languages.js +27 -1
  75. package/lib/plugin/languages.js.map +1 -1
  76. package/lib/plugin/plugin-context.d.ts +2 -1
  77. package/lib/plugin/plugin-context.d.ts.map +1 -1
  78. package/lib/plugin/plugin-context.js +16 -6
  79. package/lib/plugin/plugin-context.js.map +1 -1
  80. package/lib/plugin/preference-registry.d.ts +5 -3
  81. package/lib/plugin/preference-registry.d.ts.map +1 -1
  82. package/lib/plugin/preference-registry.js +31 -42
  83. package/lib/plugin/preference-registry.js.map +1 -1
  84. package/lib/plugin/preference-registry.spec.js +29 -41
  85. package/lib/plugin/preference-registry.spec.js.map +1 -1
  86. package/lib/plugin/text-editors.d.ts +1 -1
  87. package/lib/plugin/text-editors.d.ts.map +1 -1
  88. package/lib/plugin/text-editors.js +2 -2
  89. package/lib/plugin/text-editors.js.map +1 -1
  90. package/lib/plugin/type-converters.d.ts +6 -0
  91. package/lib/plugin/type-converters.d.ts.map +1 -1
  92. package/lib/plugin/type-converters.js +37 -1
  93. package/lib/plugin/type-converters.js.map +1 -1
  94. package/lib/plugin/types-impl.d.ts +6 -1
  95. package/lib/plugin/types-impl.d.ts.map +1 -1
  96. package/lib/plugin/types-impl.js +16 -3
  97. package/lib/plugin/types-impl.js.map +1 -1
  98. package/lib/plugin/webview-views.js +2 -2
  99. package/lib/plugin/webview-views.js.map +1 -1
  100. package/package.json +27 -27
  101. package/src/common/plugin-api-rpc-model.ts +22 -1
  102. package/src/common/plugin-api-rpc.ts +18 -5
  103. package/src/common/plugin-protocol.ts +47 -14
  104. package/src/hosted/browser/hosted-plugin.ts +15 -20
  105. package/src/hosted/node/hosted-plugin-deployer-handler.ts +1 -1
  106. package/src/hosted/node/hosted-plugin-process.ts +2 -2
  107. package/src/hosted/node/plugin-activation-events.ts +111 -0
  108. package/src/hosted/node/plugin-host-rpc.ts +2 -2
  109. package/src/hosted/node/plugin-manifest-loader.ts +4 -3
  110. package/src/hosted/node/scanners/scanner-theia.ts +59 -75
  111. package/src/main/browser/data-transfer/data-transfer-type-converters.ts +70 -0
  112. package/src/main/browser/dialogs/modal-notification.ts +4 -2
  113. package/src/main/browser/languages-main.ts +34 -4
  114. package/src/main/browser/main-file-system-event-service.ts +6 -9
  115. package/src/main/browser/plugin-contribution-handler.ts +6 -3
  116. package/src/main/browser/plugin-ext-frontend-module.ts +3 -0
  117. package/src/main/browser/text-editors-main.ts +3 -2
  118. package/src/main/browser/webview/webview-context-keys.ts +49 -0
  119. package/src/main/node/handlers/plugin-theia-directory-handler.ts +1 -1
  120. package/src/plugin/dialogs.ts +2 -2
  121. package/src/plugin/file-system-ext-impl.ts +8 -18
  122. package/src/plugin/known-commands.ts +16 -1
  123. package/src/plugin/languages/document-drop-edit.ts +44 -0
  124. package/src/plugin/languages.ts +41 -3
  125. package/src/plugin/plugin-context.ts +18 -6
  126. package/src/plugin/preference-registry.spec.ts +29 -45
  127. package/src/plugin/preference-registry.ts +33 -45
  128. package/src/plugin/text-editors.ts +2 -2
  129. package/src/plugin/type-converters.ts +37 -0
  130. package/src/plugin/types-impl.ts +15 -1
  131. package/src/plugin/webview-views.ts +2 -2
@@ -0,0 +1,70 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 Red Hat, Inc. and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { IDataTransferItem, VSDataTransfer } from '@theia/monaco-editor-core/esm/vs/base/common/dataTransfer';
18
+ import { DataTransferDTO, DataTransferItemDTO } from '../../../common/plugin-api-rpc-model';
19
+ import { URI } from '../../../plugin/types-impl';
20
+
21
+ export namespace DataTransferItem {
22
+ export async function from(mime: string, item: IDataTransferItem): Promise<DataTransferItemDTO> {
23
+ const stringValue = await item.asString();
24
+
25
+ if (mime === 'text/uri-list') {
26
+ return {
27
+ id: item.id,
28
+ asString: '',
29
+ fileData: undefined,
30
+ uriListData: serializeUriList(stringValue),
31
+ };
32
+ }
33
+
34
+ const fileValue = item.asFile();
35
+ return {
36
+ id: item.id,
37
+ asString: stringValue,
38
+ fileData: fileValue ? { name: fileValue.name, uri: fileValue.uri } : undefined,
39
+ };
40
+ }
41
+
42
+ function serializeUriList(stringValue: string): ReadonlyArray<string | URI> {
43
+ return stringValue.split('\r\n').map(part => {
44
+ if (part.startsWith('#')) {
45
+ return part;
46
+ }
47
+
48
+ try {
49
+ return URI.parse(part);
50
+ } catch {
51
+ // noop
52
+ }
53
+
54
+ return part;
55
+ });
56
+ }
57
+ }
58
+
59
+ export namespace DataTransfer {
60
+ export async function toDataTransferDTO(value: VSDataTransfer): Promise<DataTransferDTO> {
61
+ return {
62
+ items: await Promise.all(
63
+ Array.from(value.entries())
64
+ .map(
65
+ async ([mime, item]) => [mime, await DataTransferItem.from(mime, item)]
66
+ )
67
+ )
68
+ };
69
+ }
70
+ }
@@ -77,8 +77,10 @@ export class ModalNotification extends AbstractDialog<string | undefined> {
77
77
  detailElement.textContent = options.detail;
78
78
  }
79
79
 
80
- actions.forEach((action: MainMessageItem) => {
81
- const button = this.createButton(action.title);
80
+ actions.forEach((action: MainMessageItem, index: number) => {
81
+ const button = index === 0
82
+ ? this.appendAcceptButton(action.title)
83
+ : this.createButton(action.title);
82
84
  button.classList.add('main');
83
85
  this.controlPanel.appendChild(button);
84
86
  this.addKeyListener(button,
@@ -44,7 +44,7 @@ import {
44
44
  } from '../../common/plugin-api-rpc-model';
45
45
  import { RPCProtocol } from '../../common/rpc-protocol';
46
46
  import { MonacoLanguages, WorkspaceSymbolProvider } from '@theia/monaco/lib/browser/monaco-languages';
47
- import CoreURI from '@theia/core/lib/common/uri';
47
+ import { URI } from '@theia/core/lib/common/uri';
48
48
  import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable';
49
49
  import { Emitter, Event } from '@theia/core/lib/common/event';
50
50
  import { ProblemManager } from '@theia/markers/lib/browser';
@@ -71,6 +71,8 @@ import { EditorLanguageStatusService, LanguageStatus as EditorLanguageStatus } f
71
71
  import { LanguageSelector, RelativePattern } from '@theia/editor/lib/common/language-selector';
72
72
  import { ILanguageFeaturesService } from '@theia/monaco-editor-core/esm/vs/editor/common/services/languageFeatures';
73
73
  import {
74
+ DocumentOnDropEdit,
75
+ DocumentOnDropEditProvider,
74
76
  EvaluatableExpression,
75
77
  EvaluatableExpressionProvider,
76
78
  InlineValue,
@@ -78,7 +80,10 @@ import {
78
80
  InlineValuesProvider
79
81
  } from '@theia/monaco-editor-core/esm/vs/editor/common/languages';
80
82
  import { ITextModel } from '@theia/monaco-editor-core/esm/vs/editor/common/model';
81
- import { CodeActionTriggerKind } from '../../plugin/types-impl';
83
+ import { CodeActionTriggerKind, SnippetString } from '../../plugin/types-impl';
84
+ import { DataTransfer } from './data-transfer/data-transfer-type-converters';
85
+ import { VSDataTransfer } from '@theia/monaco-editor-core/esm/vs/base/common/dataTransfer';
86
+ import { FileUploadService } from '@theia/filesystem/lib/browser/file-upload-service';
82
87
 
83
88
  /**
84
89
  * @monaco-uplift The public API declares these functions as (languageId: string, service).
@@ -107,6 +112,9 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {
107
112
  @inject(EditorLanguageStatusService)
108
113
  protected readonly languageStatusService: EditorLanguageStatusService;
109
114
 
115
+ @inject(FileUploadService)
116
+ protected readonly fileUploadService: FileUploadService;
117
+
110
118
  private readonly proxy: LanguagesExt;
111
119
  private readonly services = new Map<number, Disposable>();
112
120
  private readonly toDispose = new DisposableCollection();
@@ -252,13 +260,13 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {
252
260
 
253
261
  $clearDiagnostics(id: string): void {
254
262
  for (const uri of this.problemManager.getUris()) {
255
- this.problemManager.setMarkers(new CoreURI(uri), id, []);
263
+ this.problemManager.setMarkers(new URI(uri), id, []);
256
264
  }
257
265
  }
258
266
 
259
267
  $changeDiagnostics(id: string, delta: [string, MarkerData[]][]): void {
260
268
  for (const [uriString, markers] of delta) {
261
- const uri = new CoreURI(uriString);
269
+ const uri = new URI(uriString);
262
270
  this.problemManager.setMarkers(uri, id, markers.map(reviveMarker));
263
271
  }
264
272
  }
@@ -718,6 +726,28 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {
718
726
  return this.proxy.$provideOnTypeFormattingEdits(handle, model.uri, position, ch, options, token);
719
727
  }
720
728
 
729
+ $registerDocumentDropEditProvider(handle: number, selector: SerializedDocumentFilter[]): void {
730
+ this.register(handle, (StandaloneServices.get(ILanguageFeaturesService).documentOnDropEditProvider.register(selector, this.createDocumentDropEditProvider(handle))));
731
+ }
732
+
733
+ createDocumentDropEditProvider(handle: number): DocumentOnDropEditProvider {
734
+ return {
735
+ provideDocumentOnDropEdits: async (model, position, dataTransfer, token) => this.provideDocumentDropEdits(handle, model, position, dataTransfer, token)
736
+ };
737
+ }
738
+
739
+ protected async provideDocumentDropEdits(handle: number, model: ITextModel, position: monaco.IPosition,
740
+ dataTransfer: VSDataTransfer, token: CancellationToken): Promise<DocumentOnDropEdit | undefined> {
741
+ await this.fileUploadService.upload(new URI(), { source: dataTransfer, leaveInTemp: true });
742
+ const edit = await this.proxy.$provideDocumentDropEdits(handle, model.uri, position, await DataTransfer.toDataTransferDTO(dataTransfer), token);
743
+ if (edit) {
744
+ return {
745
+ insertText: edit.insertText instanceof SnippetString ? { snippet: edit.insertText.value } : edit.insertText,
746
+ additionalEdit: toMonacoWorkspaceEdit(edit?.additionalEdit)
747
+ };
748
+ }
749
+ }
750
+
721
751
  $registerFoldingRangeProvider(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[], eventHandle: number | undefined): void {
722
752
  const languageSelector = this.toLanguageSelector(selector);
723
753
  const provider = this.createFoldingRangeProvider(handle);
@@ -37,13 +37,13 @@ export class MainFileSystemEventService {
37
37
  const proxy = rpc.getProxy(MAIN_RPC_CONTEXT.ExtHostFileSystemEventService);
38
38
  const fileService = container.get(FileService);
39
39
 
40
- // file system events - (changes the editor and other make)
41
- const events: FileSystemEvents = {
42
- created: [],
43
- changed: [],
44
- deleted: []
45
- };
46
40
  this.toDispose.push(fileService.onDidFilesChange(event => {
41
+ // file system events - (changes the editor and others make)
42
+ const events: FileSystemEvents = {
43
+ created: [],
44
+ changed: [],
45
+ deleted: []
46
+ };
47
47
  for (const change of event.changes) {
48
48
  switch (change.type) {
49
49
  case FileChangeType.ADDED:
@@ -59,9 +59,6 @@ export class MainFileSystemEventService {
59
59
  }
60
60
 
61
61
  proxy.$onFileEvent(events);
62
- events.created.length = 0;
63
- events.changed.length = 0;
64
- events.deleted.length = 0;
65
62
  }));
66
63
 
67
64
  // BEFORE file operation
@@ -21,7 +21,7 @@ import { TextmateRegistry, getEncodedLanguageId, MonacoTextmateService, GrammarD
21
21
  import { MenusContributionPointHandler } from './menus/menus-contribution-handler';
22
22
  import { PluginViewRegistry } from './view/plugin-view-registry';
23
23
  import { PluginCustomEditorRegistry } from './custom-editors/plugin-custom-editor-registry';
24
- import { PluginContribution, IndentationRules, FoldingRules, ScopeMap, DeployedPlugin, GrammarsContribution, EnterAction, OnEnterRule } from '../../common';
24
+ import { PluginContribution, IndentationRules, FoldingRules, ScopeMap, DeployedPlugin, GrammarsContribution, EnterAction, OnEnterRule, RegExpOptions } from '../../common';
25
25
  import {
26
26
  DefaultUriLabelProviderContribution,
27
27
  LabelProviderContribution,
@@ -488,11 +488,14 @@ export class PluginContributionHandler {
488
488
  return Disposable.NULL;
489
489
  }
490
490
 
491
- private createRegex(value: string | undefined): RegExp | undefined {
491
+ private createRegex(value: string | RegExpOptions | undefined): RegExp | undefined {
492
492
  if (typeof value === 'string') {
493
493
  return new RegExp(value, '');
494
494
  }
495
- return undefined;
495
+ if (typeof value == 'undefined') {
496
+ return undefined;
497
+ }
498
+ return new RegExp(value.pattern, value.flags);
496
499
  }
497
500
 
498
501
  private convertIndentationRules(rules?: IndentationRules): monaco.languages.IndentationRule | undefined {
@@ -82,6 +82,7 @@ import { PluginMenuCommandAdapter } from './menus/plugin-menu-command-adapter';
82
82
  import './theme-icon-override';
83
83
  import { PluginTerminalRegistry } from './plugin-terminal-registry';
84
84
  import { DnDFileContentStore } from './view/dnd-file-content-store';
85
+ import { WebviewContextKeys } from './webview/webview-context-keys';
85
86
 
86
87
  export default new ContainerModule((bind, unbind, isBound, rebind) => {
87
88
 
@@ -177,6 +178,8 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
177
178
  bind(WebviewWidget).toSelf();
178
179
  bind(WebviewWidgetFactory).toDynamicValue(ctx => new WebviewWidgetFactory(ctx.container)).inSingletonScope();
179
180
  bind(WidgetFactory).toService(WebviewWidgetFactory);
181
+ bind(WebviewContextKeys).toSelf().inSingletonScope();
182
+ bind(FrontendApplicationContribution).toService(WebviewContextKeys);
180
183
 
181
184
  bind(CustomEditorContribution).toSelf().inSingletonScope();
182
185
  bind(CommandContribution).toService(CustomEditorContribution);
@@ -30,6 +30,7 @@ import {
30
30
  DecorationOptions,
31
31
  WorkspaceEditDto,
32
32
  DocumentsMain,
33
+ WorkspaceEditMetadataDto,
33
34
  } from '../../common/plugin-api-rpc';
34
35
  import { Range, TextDocumentShowOptions } from '../../common/plugin-api-rpc-model';
35
36
  import { EditorsAndDocumentsMain } from './editors-and-documents-main';
@@ -126,11 +127,11 @@ export class TextEditorsMainImpl implements TextEditorsMain, Disposable {
126
127
  return Promise.resolve(this.editorsAndDocuments.getEditor(id)!.applyEdits(modelVersionId, edits, opts));
127
128
  }
128
129
 
129
- async $tryApplyWorkspaceEdit(dto: WorkspaceEditDto): Promise<boolean> {
130
+ async $tryApplyWorkspaceEdit(dto: WorkspaceEditDto, metadata?: WorkspaceEditMetadataDto): Promise<boolean> {
130
131
  const workspaceEdit = toMonacoWorkspaceEdit(dto);
131
132
  try {
132
133
  const edits = ResourceEdit.convert(workspaceEdit);
133
- const { success } = await this.bulkEditService.apply(edits);
134
+ const { success } = await this.bulkEditService.apply(edits, { respectAutoSaveConfig: metadata?.isRefactoring });
134
135
  return success;
135
136
  } catch {
136
137
  return false;
@@ -0,0 +1,49 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 Ericsson and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
18
+ import { ContextKey, ContextKeyService } from '@theia/core/lib/browser/context-key-service';
19
+ import { ApplicationShell, FocusTracker, Widget } from '@theia/core/lib/browser';
20
+ import { WebviewWidget } from './webview';
21
+
22
+ @injectable()
23
+ export class WebviewContextKeys {
24
+
25
+ /**
26
+ * Context key representing the `viewType` of the active `WebviewWidget`, if any.
27
+ */
28
+ activeWebviewPanelId: ContextKey<string>;
29
+
30
+ @inject(ApplicationShell)
31
+ protected applicationShell: ApplicationShell;
32
+
33
+ @inject(ContextKeyService)
34
+ protected contextKeyService: ContextKeyService;
35
+
36
+ @postConstruct()
37
+ protected postConstruct(): void {
38
+ this.activeWebviewPanelId = this.contextKeyService.createKey('activeWebviewPanelId', '');
39
+ this.applicationShell.onDidChangeCurrentWidget(this.handleDidChangeCurrentWidget, this);
40
+ }
41
+
42
+ protected handleDidChangeCurrentWidget(change: FocusTracker.IChangedArgs<Widget>): void {
43
+ if (change.newValue instanceof WebviewWidget) {
44
+ this.activeWebviewPanelId.set(change.newValue.viewType);
45
+ } else {
46
+ this.activeWebviewPanelId.set('');
47
+ }
48
+ }
49
+ }
@@ -34,7 +34,7 @@ export class PluginTheiaDirectoryHandler implements PluginDeployerDirectoryHandl
34
34
 
35
35
  accept(resolvedPlugin: PluginDeployerEntry): boolean {
36
36
 
37
- console.log('PluginTheiaDirectoryHandler: accepting plugin with path', resolvedPlugin.path());
37
+ console.debug('PluginTheiaDirectoryHandler: accepting plugin with path', resolvedPlugin.path());
38
38
 
39
39
  // handle only directories
40
40
  if (resolvedPlugin.isFile()) {
@@ -30,8 +30,8 @@ export class DialogsExtImpl {
30
30
  title: options.title,
31
31
  openLabel: options.openLabel,
32
32
  defaultUri: options.defaultUri ? options.defaultUri.path : undefined,
33
- canSelectFiles: options.canSelectFiles ? options.canSelectFiles : true,
34
- canSelectFolders: options.canSelectFolders ? options.canSelectFolders : false,
33
+ canSelectFiles: typeof options.canSelectFiles === 'boolean' ? options.canSelectFiles : true,
34
+ canSelectFolders: typeof options.canSelectFolders === 'boolean' ? options.canSelectFolders : false,
35
35
  canSelectMany: options.canSelectMany,
36
36
  filters: options.filters
37
37
  } as OpenDialogOptionsMain;
@@ -35,16 +35,16 @@ import { PLUGIN_RPC_CONTEXT, FileSystemExt, FileSystemMain, IFileChangeDto } fro
35
35
  import * as vscode from '@theia/plugin';
36
36
  import * as files from '@theia/filesystem/lib/common/files';
37
37
  import * as typeConverter from './type-converters';
38
- import { LanguagesExtImpl } from './languages';
39
38
  import { Schemes as Schemas } from '../common/uri-components';
40
39
  import { State, StateMachine, LinkComputer, Edge } from '../common/link-computer';
41
40
  import { commonPrefixLength } from '@theia/core/lib/common/strings';
42
41
  import { CharCode } from '@theia/core/lib/common/char-code';
43
42
  import { BinaryBuffer } from '@theia/core/lib/common/buffer';
43
+ import { Emitter } from '@theia/core/shared/vscode-languageserver-protocol';
44
44
 
45
45
  type IDisposable = vscode.Disposable;
46
46
 
47
- class FsLinkProvider {
47
+ export class FsLinkProvider {
48
48
 
49
49
  private _schemes: string[] = [];
50
50
  private _stateMachine?: StateMachine;
@@ -204,12 +204,14 @@ export class FileSystemExtImpl implements FileSystemExt {
204
204
  private readonly _usedSchemes = new Set<string>();
205
205
  private readonly _watches = new Map<number, IDisposable>();
206
206
 
207
- private _linkProviderRegistration?: IDisposable;
207
+ private readonly onWillRegisterFileSystemProviderEmitter = new Emitter<FsLinkProvider>();
208
+ readonly onWillRegisterFileSystemProvider = this.onWillRegisterFileSystemProviderEmitter.event;
209
+
208
210
  private _handlePool: number = 0;
209
211
 
210
212
  readonly fileSystem: vscode.FileSystem;
211
213
 
212
- constructor(rpc: RPCProtocol, private _extHostLanguageFeatures: LanguagesExtImpl) {
214
+ constructor(rpc: RPCProtocol) {
213
215
  this._proxy = rpc.getProxy(PLUGIN_RPC_CONTEXT.FILE_SYSTEM_MAIN);
214
216
  this.fileSystem = new ConsumerFileSystem(this._proxy, this._capabilities);
215
217
 
@@ -218,18 +220,7 @@ export class FileSystemExtImpl implements FileSystemExt {
218
220
  }
219
221
 
220
222
  dispose(): void {
221
- if (this._linkProviderRegistration) {
222
- this._linkProviderRegistration.dispose();
223
- }
224
- }
225
-
226
- private _registerLinkProviderIfNotYetRegistered(): void {
227
- if (!this._linkProviderRegistration) {
228
- this._linkProviderRegistration = this._extHostLanguageFeatures.registerDocumentLinkProvider('*', this._linkProvider, {
229
- id: 'theia.fs-ext-impl',
230
- name: 'fs-ext-impl'
231
- });
232
- }
223
+ this.onWillRegisterFileSystemProviderEmitter.dispose();
233
224
  }
234
225
 
235
226
  registerFileSystemProvider(scheme: string, provider: vscode.FileSystemProvider, options: { isCaseSensitive?: boolean, isReadonly?: boolean } = {}) {
@@ -238,8 +229,7 @@ export class FileSystemExtImpl implements FileSystemExt {
238
229
  throw new Error(`a provider for the scheme '${scheme}' is already registered`);
239
230
  }
240
231
 
241
- //
242
- this._registerLinkProviderIfNotYetRegistered();
232
+ this.onWillRegisterFileSystemProviderEmitter.fire(this._linkProvider);
243
233
 
244
234
  const handle = this._handlePool++;
245
235
  this._linkProvider.add(scheme);
@@ -14,8 +14,9 @@
14
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  // *****************************************************************************
16
16
 
17
- import { Range as R, Position as P, Location as L } from '@theia/core/shared/vscode-languageserver-protocol';
18
17
  import * as theia from '@theia/plugin';
18
+ import { Range as R, Position as P, Location as L } from '@theia/core/shared/vscode-languageserver-protocol';
19
+ import { URI as TheiaURI } from '@theia/core/lib/common/uri';
19
20
  import { cloneAndChange } from '../common/objects';
20
21
  import { Position, Range, Location, CallHierarchyItem, TypeHierarchyItem, URI, TextDocumentShowOptions } from './types-impl';
21
22
  import {
@@ -63,6 +64,9 @@ export namespace KnownCommands {
63
64
  }
64
65
  };
65
66
 
67
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
+ const identity = (args: any[]) => args;
69
+
66
70
  mappings['editor.action.select.all'] = ['editor.action.select.all', CONVERT_VSCODE_TO_MONACO];
67
71
  mappings['editor.action.toggleHighContrast'] = ['editor.action.toggleHighContrast', CONVERT_VSCODE_TO_MONACO];
68
72
  mappings['editor.action.moveCarretLeftAction'] = ['editor.action.moveCarretLeftAction', CONVERT_VSCODE_TO_MONACO];
@@ -302,6 +306,17 @@ export namespace KnownCommands {
302
306
  mappings['vscode.open'] = ['vscode.open', CONVERT_VSCODE_TO_MONACO];
303
307
  mappings['vscode.diff'] = ['vscode.diff', CONVERT_VSCODE_TO_MONACO];
304
308
 
309
+ // terminal commands
310
+ mappings['workbench.action.terminal.new'] = ['terminal:new', identity];
311
+ mappings['workbench.action.terminal.newWithProfile'] = ['terminal:new:profile', identity];
312
+ mappings['workbench.action.terminal.selectDefaultShell'] = ['terminal:profile:default', identity];
313
+ mappings['workbench.action.terminal.newInActiveWorkspace'] = ['terminal:new:active:workspace', identity];
314
+ mappings['workbench.action.terminal.clear'] = ['terminal:clear', identity];
315
+ mappings['openInTerminal'] = ['terminal:context', createConversionFunction((uri: URI) => new TheiaURI(uri))];
316
+ mappings['workbench.action.terminal.split'] = ['terminal:split', identity];
317
+ mappings['workbench.action.terminal.focusFind'] = ['terminal:find', identity];
318
+ mappings['workbench.action.terminal.hideFind'] = ['terminal:find:cancel', identity];
319
+
305
320
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
306
321
  export function map<T>(id: string, args: any[] | undefined, toDo: (mappedId: string, mappedArgs: any[] | undefined, mappedResult: ConversionFunction | undefined) => T): T {
307
322
  if (mappings[id]) {
@@ -0,0 +1,44 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 Red Hat, Inc. and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+ import * as theia from '@theia/plugin';
17
+ import { DataTransferDTO, DocumentDropEdit } from '../../common/plugin-api-rpc-model';
18
+ import { CancellationToken } from '@theia/core/shared/vscode-languageserver-protocol';
19
+ import { Position } from '../../common/plugin-api-rpc';
20
+ import * as Converter from '../type-converters';
21
+ import { DocumentsExtImpl } from '../documents';
22
+ import { URI } from '@theia/core/shared/vscode-uri';
23
+ import { FileSystemExtImpl } from '../file-system-ext-impl';
24
+ import * as os from 'os';
25
+ import * as path from 'path';
26
+
27
+ export class DocumentDropEditAdapter {
28
+ constructor(private readonly provider: theia.DocumentDropEditProvider,
29
+ private readonly documents: DocumentsExtImpl,
30
+ private readonly fileSystem: FileSystemExtImpl) { }
31
+
32
+ async provideDocumentDropEdits(resource: URI, position: Position, dataTransfer: DataTransferDTO, token: CancellationToken): Promise<DocumentDropEdit | undefined> {
33
+ return this.provider.provideDocumentDropEdits(
34
+ this.documents.getDocument(resource),
35
+ Converter.toPosition(position),
36
+ Converter.DataTransfer.toDataTransfer(dataTransfer, itemId => this.resolveFileData(itemId)),
37
+ token) as DocumentDropEdit | undefined;
38
+ }
39
+
40
+ private async resolveFileData(itemId: string): Promise<Uint8Array> {
41
+ const filePath = URI.file(path.resolve(os.tmpdir(), 'theia_upload', itemId));
42
+ return this.fileSystem.fileSystem.readFile(filePath);
43
+ }
44
+ }
@@ -69,7 +69,9 @@ import {
69
69
  InlineValue,
70
70
  InlineValueContext,
71
71
  TypeHierarchyItem,
72
- InlineCompletionContext
72
+ InlineCompletionContext,
73
+ DocumentDropEdit,
74
+ DataTransferDTO
73
75
  } from '../common/plugin-api-rpc-model';
74
76
  import { CompletionAdapter } from './languages/completion';
75
77
  import { Diagnostics } from './languages/diagnostics';
@@ -109,6 +111,9 @@ import { LinkedEditingRangeAdapter } from './languages/linked-editing-range';
109
111
  import { serializeEnterRules, serializeIndentation, serializeRegExp } from './languages-utils';
110
112
  import { InlayHintsAdapter } from './languages/inlay-hints';
111
113
  import { InlineCompletionAdapter, InlineCompletionAdapterBase } from './languages/inline-completion';
114
+ import { DocumentDropEditAdapter } from './languages/document-drop-edit';
115
+ import { IDisposable } from '@theia/monaco-editor-core';
116
+ import { FileSystemExtImpl, FsLinkProvider } from './file-system-ext-impl';
112
117
 
113
118
  type Adapter = CompletionAdapter |
114
119
  SignatureHelpAdapter |
@@ -139,7 +144,8 @@ type Adapter = CompletionAdapter |
139
144
  DocumentSemanticTokensAdapter |
140
145
  LinkedEditingRangeAdapter |
141
146
  TypeHierarchyAdapter |
142
- InlineCompletionAdapter;
147
+ InlineCompletionAdapter |
148
+ DocumentDropEditAdapter;
143
149
 
144
150
  export class LanguagesExtImpl implements LanguagesExt {
145
151
 
@@ -147,15 +153,25 @@ export class LanguagesExtImpl implements LanguagesExt {
147
153
 
148
154
  private readonly diagnostics: Diagnostics;
149
155
 
156
+ private linkProviderRegistration?: IDisposable;
157
+
150
158
  private callId = 0;
151
159
  private adaptersMap = new Map<number, Adapter>();
152
160
 
153
161
  constructor(
154
162
  rpc: RPCProtocol,
155
163
  private readonly documents: DocumentsExtImpl,
156
- private readonly commands: CommandRegistryImpl) {
164
+ private readonly commands: CommandRegistryImpl,
165
+ private readonly filesSystem: FileSystemExtImpl) {
157
166
  this.proxy = rpc.getProxy(PLUGIN_RPC_CONTEXT.LANGUAGES_MAIN);
158
167
  this.diagnostics = new Diagnostics(rpc);
168
+ filesSystem.onWillRegisterFileSystemProvider(linkProvider => this.registerLinkProviderIfNotYetRegistered(linkProvider));
169
+ }
170
+
171
+ dispose(): void {
172
+ if (this.linkProviderRegistration) {
173
+ this.linkProviderRegistration.dispose();
174
+ }
159
175
  }
160
176
 
161
177
  get onDidChangeDiagnostics(): Event<theia.DiagnosticChangeEvent> {
@@ -258,6 +274,15 @@ export class LanguagesExtImpl implements LanguagesExt {
258
274
  return undefined;
259
275
  }
260
276
 
277
+ private registerLinkProviderIfNotYetRegistered(linkProvider: FsLinkProvider): void {
278
+ if (!this.linkProviderRegistration) {
279
+ this.linkProviderRegistration = this.registerDocumentLinkProvider('*', linkProvider, {
280
+ id: 'theia.fs-ext-impl',
281
+ name: 'fs-ext-impl'
282
+ });
283
+ }
284
+ }
285
+
261
286
  // ### Completion begin
262
287
  $provideCompletionItems(handle: number, resource: UriComponents, position: Position,
263
288
  context: CompletionContext, token: theia.CancellationToken): Promise<CompletionResultDto | undefined> {
@@ -463,6 +488,19 @@ export class LanguagesExtImpl implements LanguagesExt {
463
488
  }
464
489
  // ### Document Formatting Edit end
465
490
 
491
+ // ### Drop Edit Provider start
492
+ $provideDocumentDropEdits(handle: number, resource: UriComponents, position: Position,
493
+ dataTransfer: DataTransferDTO, token: theia.CancellationToken): Promise<DocumentDropEdit | undefined> {
494
+ return this.withAdapter(handle, DocumentDropEditAdapter, adapter => adapter.provideDocumentDropEdits(URI.revive(resource), position, dataTransfer, token), undefined);
495
+ }
496
+
497
+ registerDocumentDropEditProvider(selector: theia.DocumentSelector, provider: theia.DocumentDropEditProvider): theia.Disposable {
498
+ const callId = this.addNewAdapter(new DocumentDropEditAdapter(provider, this.documents, this.filesSystem));
499
+ this.proxy.$registerDocumentDropEditProvider(callId, this.transformDocumentSelector(selector));
500
+ return this.createDisposable(callId);
501
+ }
502
+ // ### Drop Edit Provider end
503
+
466
504
  // ### Document Range Formatting Edit begin
467
505
  registerDocumentRangeFormattingEditProvider(selector: theia.DocumentSelector, provider: theia.DocumentRangeFormattingEditProvider,
468
506
  pluginInfo: PluginInfo): theia.Disposable {