@theia/plugin-ext 1.31.0-next.3 → 1.31.0-next.33

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 (116) hide show
  1. package/lib/common/cache.d.ts +12 -0
  2. package/lib/common/cache.d.ts.map +1 -0
  3. package/lib/common/cache.js +48 -0
  4. package/lib/common/cache.js.map +1 -0
  5. package/lib/common/plugin-api-rpc-model.d.ts +67 -2
  6. package/lib/common/plugin-api-rpc-model.d.ts.map +1 -1
  7. package/lib/common/plugin-api-rpc-model.js +12 -1
  8. package/lib/common/plugin-api-rpc-model.js.map +1 -1
  9. package/lib/common/plugin-api-rpc.d.ts +34 -2
  10. package/lib/common/plugin-api-rpc.d.ts.map +1 -1
  11. package/lib/common/plugin-api-rpc.js.map +1 -1
  12. package/lib/hosted/browser/hosted-plugin.d.ts +15 -12
  13. package/lib/hosted/browser/hosted-plugin.d.ts.map +1 -1
  14. package/lib/hosted/browser/hosted-plugin.js.map +1 -1
  15. package/lib/main/browser/{callhierarchy/callhierarchy-type-converters.d.ts → hierarchy/hierarchy-types-converters.d.ts} +14 -14
  16. package/lib/main/browser/hierarchy/hierarchy-types-converters.d.ts.map +1 -0
  17. package/lib/main/browser/hierarchy/hierarchy-types-converters.js +175 -0
  18. package/lib/main/browser/hierarchy/hierarchy-types-converters.js.map +1 -0
  19. package/lib/main/browser/languages-main.d.ts +12 -1
  20. package/lib/main/browser/languages-main.d.ts.map +1 -1
  21. package/lib/main/browser/languages-main.js +144 -9
  22. package/lib/main/browser/languages-main.js.map +1 -1
  23. package/lib/main/browser/menus/menus-contribution-handler.d.ts.map +1 -1
  24. package/lib/main/browser/menus/menus-contribution-handler.js +16 -18
  25. package/lib/main/browser/menus/menus-contribution-handler.js.map +1 -1
  26. package/lib/main/browser/menus/plugin-menu-command-adapter.js +1 -1
  27. package/lib/main/browser/menus/plugin-menu-command-adapter.js.map +1 -1
  28. package/lib/main/browser/menus/vscode-theia-menu-mappings.d.ts +2 -2
  29. package/lib/main/browser/menus/vscode-theia-menu-mappings.d.ts.map +1 -1
  30. package/lib/main/browser/menus/vscode-theia-menu-mappings.js +16 -16
  31. package/lib/main/browser/menus/vscode-theia-menu-mappings.js.map +1 -1
  32. package/lib/main/browser/terminal-main.d.ts +7 -1
  33. package/lib/main/browser/terminal-main.d.ts.map +1 -1
  34. package/lib/main/browser/terminal-main.js +23 -1
  35. package/lib/main/browser/terminal-main.js.map +1 -1
  36. package/lib/main/browser/view/tree-view-widget.d.ts +43 -3
  37. package/lib/main/browser/view/tree-view-widget.d.ts.map +1 -1
  38. package/lib/main/browser/view/tree-view-widget.js +184 -31
  39. package/lib/main/browser/view/tree-view-widget.js.map +1 -1
  40. package/lib/plugin/custom-editors.d.ts.map +1 -1
  41. package/lib/plugin/custom-editors.js +2 -29
  42. package/lib/plugin/custom-editors.js.map +1 -1
  43. package/lib/plugin/known-commands.d.ts.map +1 -1
  44. package/lib/plugin/known-commands.js +9 -0
  45. package/lib/plugin/known-commands.js.map +1 -1
  46. package/lib/plugin/languages/call-hierarchy.js +1 -1
  47. package/lib/plugin/languages/call-hierarchy.js.map +1 -1
  48. package/lib/plugin/languages/inlay-hints.d.ts +20 -0
  49. package/lib/plugin/languages/inlay-hints.d.ts.map +1 -0
  50. package/lib/plugin/languages/inlay-hints.js +128 -0
  51. package/lib/plugin/languages/inlay-hints.js.map +1 -0
  52. package/lib/plugin/languages/inline-values.d.ts +11 -0
  53. package/lib/plugin/languages/inline-values.d.ts.map +1 -0
  54. package/lib/plugin/languages/inline-values.js +45 -0
  55. package/lib/plugin/languages/inline-values.js.map +1 -0
  56. package/lib/plugin/languages/type-hierarchy.d.ts +19 -0
  57. package/lib/plugin/languages/type-hierarchy.d.ts.map +1 -0
  58. package/lib/plugin/languages/type-hierarchy.js +96 -0
  59. package/lib/plugin/languages/type-hierarchy.js.map +1 -0
  60. package/lib/plugin/languages.d.ts +13 -2
  61. package/lib/plugin/languages.d.ts.map +1 -1
  62. package/lib/plugin/languages.js +60 -0
  63. package/lib/plugin/languages.js.map +1 -1
  64. package/lib/plugin/plugin-context.d.ts.map +1 -1
  65. package/lib/plugin/plugin-context.js +36 -8
  66. package/lib/plugin/plugin-context.js.map +1 -1
  67. package/lib/plugin/terminal-ext.d.ts +11 -1
  68. package/lib/plugin/terminal-ext.d.ts.map +1 -1
  69. package/lib/plugin/terminal-ext.js +44 -0
  70. package/lib/plugin/terminal-ext.js.map +1 -1
  71. package/lib/plugin/tree/tree-views.d.ts +5 -1
  72. package/lib/plugin/tree/tree-views.d.ts.map +1 -1
  73. package/lib/plugin/tree/tree-views.js +28 -1
  74. package/lib/plugin/tree/tree-views.js.map +1 -1
  75. package/lib/plugin/type-converters.d.ts +11 -1
  76. package/lib/plugin/type-converters.d.ts.map +1 -1
  77. package/lib/plugin/type-converters.js +77 -5
  78. package/lib/plugin/type-converters.js.map +1 -1
  79. package/lib/plugin/types-impl.d.ts +73 -2
  80. package/lib/plugin/types-impl.d.ts.map +1 -1
  81. package/lib/plugin/types-impl.js +169 -6
  82. package/lib/plugin/types-impl.js.map +1 -1
  83. package/lib/plugin/types-impl.spec.js +14 -0
  84. package/lib/plugin/types-impl.spec.js.map +1 -1
  85. package/lib/plugin/workspace.js +1 -1
  86. package/lib/plugin/workspace.js.map +1 -1
  87. package/package.json +26 -25
  88. package/src/common/cache.ts +51 -0
  89. package/src/common/plugin-api-rpc-model.ts +75 -2
  90. package/src/common/plugin-api-rpc.ts +42 -2
  91. package/src/hosted/browser/hosted-plugin.ts +9 -9
  92. package/src/main/browser/hierarchy/hierarchy-types-converters.ts +189 -0
  93. package/src/main/browser/languages-main.ts +201 -25
  94. package/src/main/browser/menus/menus-contribution-handler.ts +19 -21
  95. package/src/main/browser/menus/plugin-menu-command-adapter.ts +1 -1
  96. package/src/main/browser/menus/vscode-theia-menu-mappings.ts +17 -17
  97. package/src/main/browser/terminal-main.ts +29 -2
  98. package/src/main/browser/view/tree-view-widget.tsx +220 -30
  99. package/src/plugin/custom-editors.ts +1 -33
  100. package/src/plugin/known-commands.ts +12 -1
  101. package/src/plugin/languages/call-hierarchy.ts +2 -2
  102. package/src/plugin/languages/inlay-hints.ts +149 -0
  103. package/src/plugin/languages/inline-values.ts +50 -0
  104. package/src/plugin/languages/type-hierarchy.ts +117 -0
  105. package/src/plugin/languages.ts +108 -2
  106. package/src/plugin/plugin-context.ts +44 -10
  107. package/src/plugin/terminal-ext.ts +54 -2
  108. package/src/plugin/tree/tree-views.ts +40 -2
  109. package/src/plugin/type-converters.ts +82 -7
  110. package/src/plugin/types-impl.spec.ts +16 -0
  111. package/src/plugin/types-impl.ts +189 -4
  112. package/src/plugin/workspace.ts +1 -1
  113. package/lib/main/browser/callhierarchy/callhierarchy-type-converters.d.ts.map +0 -1
  114. package/lib/main/browser/callhierarchy/callhierarchy-type-converters.js +0 -178
  115. package/lib/main/browser/callhierarchy/callhierarchy-type-converters.js.map +0 -1
  116. package/src/main/browser/callhierarchy/callhierarchy-type-converters.ts +0 -193
@@ -0,0 +1,149 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2022 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
+ * Copyright (c) Microsoft Corporation. All rights reserved.
18
+ * Licensed under the MIT License. See License.txt in the project root for license information.
19
+ *--------------------------------------------------------------------------------------------*/
20
+
21
+ // copied and modified from https://github.com/microsoft/vscode/blob/1.65.0/src/vs/workbench/api/common/extHostLanguageFeatures.ts#L1178-L1288
22
+
23
+ import * as theia from '@theia/plugin';
24
+ import * as Converter from '../type-converters';
25
+ import { Cache } from '../../common/cache';
26
+ import { ChainedCacheId, InlayHint, InlayHintLabelPart, Range } from '../../common/plugin-api-rpc-model';
27
+ import { CommandRegistryImpl } from '../command-registry';
28
+ import { DisposableCollection } from '@theia/core/lib/common/disposable';
29
+ import { DocumentsExtImpl } from '../documents';
30
+ import { InlayHintDto, InlayHintsDto } from '../../common';
31
+ import { URI } from '@theia/core/shared/vscode-uri';
32
+ import { isLocationArray } from './util';
33
+
34
+ export class InlayHintsAdapter {
35
+
36
+ private cache = new Cache<theia.InlayHint>('InlayHints');
37
+ private readonly disposables = new Map<number, DisposableCollection>();
38
+
39
+ constructor(
40
+ private readonly provider: theia.InlayHintsProvider,
41
+ private readonly documents: DocumentsExtImpl,
42
+ private readonly commands: CommandRegistryImpl
43
+ ) { }
44
+
45
+ async provideInlayHints(resource: URI, range: Range, token: theia.CancellationToken): Promise<InlayHintsDto | undefined> {
46
+ const documentData = this.documents.getDocumentData(resource);
47
+ if (!documentData) {
48
+ return Promise.reject(new Error(`There are no documents for ${resource}`));
49
+ }
50
+
51
+ const doc = documentData.document;
52
+ const ran = Converter.toRange(range);
53
+ const hints = await this.provider.provideInlayHints(doc, ran, token);
54
+
55
+ if (!Array.isArray(hints) || hints.length === 0) {
56
+ return undefined;
57
+ }
58
+
59
+ if (token.isCancellationRequested) {
60
+ return undefined;
61
+ }
62
+
63
+ const pid = this.cache.add(hints);
64
+ this.disposables.set(pid, new DisposableCollection());
65
+ const result: InlayHintsDto = { hints: [], cacheId: pid };
66
+
67
+ for (let i = 0; i < hints.length; i++) {
68
+ if (this.isValidInlayHint(hints[i], ran)) {
69
+ result.hints.push(this.convertInlayHint(hints[i], [pid, i]));
70
+ }
71
+ }
72
+
73
+ return result;
74
+ }
75
+
76
+ async resolveInlayHint(id: ChainedCacheId, token: theia.CancellationToken): Promise<InlayHint | undefined> {
77
+ if (typeof this.provider.resolveInlayHint !== 'function') {
78
+ return undefined;
79
+ }
80
+ const item = this.cache.get(...id);
81
+ if (!item) {
82
+ return undefined;
83
+ }
84
+ const hint = await this.provider.resolveInlayHint!(item, token);
85
+ if (!hint) {
86
+ return undefined;
87
+ }
88
+ if (!this.isValidInlayHint(hint)) {
89
+ return undefined;
90
+ }
91
+ return this.convertInlayHint(hint, id);
92
+ }
93
+
94
+ private isValidInlayHint(hint: theia.InlayHint, range?: theia.Range): boolean {
95
+ if (hint.label.length === 0 || Array.isArray(hint.label) && hint.label.every(part => part.value.length === 0)) {
96
+ return false;
97
+ }
98
+ if (range && !range.contains(hint.position)) {
99
+ return false;
100
+ }
101
+ return true;
102
+ }
103
+
104
+ private convertInlayHint(hint: theia.InlayHint, id: ChainedCacheId): InlayHintDto {
105
+
106
+ const disposables = this.disposables.get(id[0]);
107
+ if (!disposables) {
108
+ throw Error('DisposableCollection is missing...');
109
+ }
110
+
111
+ const result: InlayHintDto = {
112
+ label: '', // fill-in below.
113
+ cacheId: id,
114
+ tooltip: hint.tooltip,
115
+ position: Converter.fromPosition(hint.position),
116
+ textEdits: hint.textEdits && hint.textEdits.map(Converter.fromTextEdit),
117
+ kind: hint.kind && Converter.InlayHintKind.from(hint.kind),
118
+ paddingLeft: hint.paddingLeft,
119
+ paddingRight: hint.paddingRight,
120
+ };
121
+
122
+ if (typeof hint.label === 'string') {
123
+ result.label = hint.label;
124
+ } else {
125
+ result.label = hint.label.map(part => {
126
+ const partResult: InlayHintLabelPart = { label: part.value };
127
+ if (part.tooltip) {
128
+ partResult.tooltip = typeof partResult === 'string' ? part.tooltip : Converter.fromMarkdown(part.tooltip);
129
+ }
130
+ if (isLocationArray(part.location)) {
131
+ partResult.location = Converter.fromLocation(part.location);
132
+ }
133
+ if (part.command) {
134
+ partResult.command = this.commands.converter.toSafeCommand(part.command, disposables);
135
+ }
136
+ return partResult;
137
+ });
138
+ }
139
+
140
+ return result;
141
+ }
142
+
143
+ async releaseHints(id: number): Promise<void> {
144
+ this.disposables.get(id)?.dispose();
145
+ this.disposables.delete(id);
146
+ this.cache.delete(id);
147
+ }
148
+
149
+ }
@@ -0,0 +1,50 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2022 STMicroelectronics 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 { URI } from '@theia/core/shared/vscode-uri';
18
+ import * as theia from '@theia/plugin';
19
+ import { InlineValue, InlineValueContext, Range } from '../../common/plugin-api-rpc-model';
20
+ import { DocumentsExtImpl } from '../documents';
21
+ import * as Converter from '../type-converters';
22
+
23
+ export class InlineValuesAdapter {
24
+
25
+ constructor(
26
+ private readonly provider: theia.InlineValuesProvider,
27
+ private readonly documents: DocumentsExtImpl
28
+ ) { }
29
+
30
+ async provideInlineValues(resource: URI, range: Range, context: InlineValueContext, token: theia.CancellationToken): Promise<InlineValue[] | undefined> {
31
+ const documentData = this.documents.getDocumentData(resource);
32
+ if (!documentData) {
33
+ return Promise.reject(new Error(`There is no document data for ${resource}`));
34
+ }
35
+
36
+ const document = documentData.document;
37
+ const viewPort = Converter.toRange(range);
38
+ const ctx = Converter.toInlineValueContext(context);
39
+
40
+ return Promise.resolve(this.provider.provideInlineValues(document, viewPort, ctx, token)).then(inlineValue => {
41
+ if (!inlineValue) {
42
+ return undefined;
43
+ }
44
+ if (Array.isArray(inlineValue)) {
45
+ return inlineValue.map(iv => Converter.fromInlineValue(iv));
46
+ }
47
+ return undefined;
48
+ });
49
+ }
50
+ }
@@ -0,0 +1,117 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2022 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 { URI } from '@theia/core/shared/vscode-uri';
18
+ import * as theia from '@theia/plugin';
19
+ import { IdGenerator } from '../../common/id-generator';
20
+ import * as rpc from '../../common/plugin-api-rpc';
21
+ import * as model from '../../common/plugin-api-rpc-model';
22
+ import { DocumentsExtImpl } from '../documents';
23
+ import { fromRange, SymbolKind } from '../type-converters';
24
+ import * as types from '../types-impl';
25
+
26
+ export class TypeHierarchyAdapter {
27
+
28
+ private readonly idGenerator = new IdGenerator('');
29
+ protected readonly cache = new Map<string, Map<string, theia.TypeHierarchyItem>>();
30
+
31
+ constructor(
32
+ private readonly provider: theia.TypeHierarchyProvider,
33
+ private readonly documents: DocumentsExtImpl,
34
+ ) { }
35
+
36
+ private fromTypeHierarchyItem(item: theia.TypeHierarchyItem, sessionId: string): model.TypeHierarchyItem {
37
+ const sessionCache = this.cache.get(sessionId)!;
38
+ const itemId = sessionCache.size.toString(36);
39
+
40
+ const definition: model.TypeHierarchyItem = {
41
+ _itemId: itemId,
42
+ _sessionId: sessionId,
43
+
44
+ kind: SymbolKind.fromSymbolKind(item.kind),
45
+ tags: item.tags,
46
+ name: item.name,
47
+ detail: item.detail,
48
+ uri: item.uri,
49
+
50
+ range: fromRange(item.range),
51
+ selectionRange: fromRange(item.selectionRange),
52
+ };
53
+ sessionCache.set(itemId, item);
54
+ return definition;
55
+ }
56
+
57
+ async prepareSession(uri: URI, position: rpc.Position, token: theia.CancellationToken): Promise<model.TypeHierarchyItem[] | undefined> {
58
+ const documentData = this.documents.getDocumentData(uri);
59
+ if (!documentData) {
60
+ return Promise.reject(new Error(`There is no document for ${uri}`));
61
+ }
62
+
63
+ const definition = await this.provider.prepareTypeHierarchy(documentData.document,
64
+ new types.Position(
65
+ position.lineNumber,
66
+ position.column
67
+ ),
68
+ token
69
+ );
70
+
71
+ if (!definition) {
72
+ return undefined;
73
+ }
74
+
75
+ const sessionId = this.idGenerator.nextId();
76
+
77
+ this.cache.set(sessionId, new Map());
78
+ return Array.isArray(definition) ? definition.map(item => this.fromTypeHierarchyItem(item, sessionId)) : [this.fromTypeHierarchyItem(definition, sessionId)];
79
+ }
80
+
81
+ async provideSupertypes(sessionId: string, itemId: string, token: theia.CancellationToken): Promise<model.TypeHierarchyItem[] | undefined> {
82
+ const item = this.fetchItemFromCatch(sessionId, itemId);
83
+ if (!item) {
84
+ throw new Error('missing type hierarchy item');
85
+ }
86
+ const supertypes = await this.provider.provideTypeHierarchySupertypes(item, token);
87
+ if (!supertypes) {
88
+ return undefined;
89
+ }
90
+ return supertypes.map(supertype => this.fromTypeHierarchyItem(supertype, sessionId));
91
+ }
92
+
93
+ async provideSubtypes(sessionId: string, itemId: string, token: theia.CancellationToken): Promise<model.TypeHierarchyItem[] | undefined> {
94
+ const item = this.fetchItemFromCatch(sessionId, itemId);
95
+ if (!item) {
96
+ throw new Error('missing type hierarchy item');
97
+ }
98
+ const subTypes = await this.provider.provideTypeHierarchySubtypes(item, token);
99
+ if (!subTypes) {
100
+ return undefined;
101
+ }
102
+ return subTypes.map(subtype => this.fromTypeHierarchyItem(subtype, sessionId));
103
+ }
104
+
105
+ private fetchItemFromCatch(sessionId: string, itemId: string): theia.TypeHierarchyItem | undefined {
106
+ return this.cache.get(sessionId!)?.get(itemId!);
107
+ }
108
+
109
+ releaseSession(session?: string): Promise<boolean> {
110
+ if (session !== undefined) {
111
+ return Promise.resolve(this.cache.delete(session));
112
+ } else {
113
+ this.cache.clear();
114
+ return Promise.resolve(true);
115
+ }
116
+ }
117
+ }
@@ -25,6 +25,8 @@ import {
25
25
  WorkspaceEditDto,
26
26
  PluginInfo,
27
27
  Plugin,
28
+ InlayHintsDto,
29
+ InlayHintDto,
28
30
  } from '../common/plugin-api-rpc';
29
31
  import { RPCProtocol } from '../common/rpc-protocol';
30
32
  import * as theia from '@theia/plugin';
@@ -62,13 +64,17 @@ import {
62
64
  CallHierarchyIncomingCall,
63
65
  CallHierarchyOutgoingCall,
64
66
  LinkedEditingRanges,
65
- EvaluatableExpression
67
+ EvaluatableExpression,
68
+ InlineValue,
69
+ InlineValueContext,
70
+ TypeHierarchyItem
66
71
  } from '../common/plugin-api-rpc-model';
67
72
  import { CompletionAdapter } from './languages/completion';
68
73
  import { Diagnostics } from './languages/diagnostics';
69
74
  import { SignatureHelpAdapter } from './languages/signature';
70
75
  import { HoverAdapter } from './languages/hover';
71
76
  import { EvaluatableExpressionAdapter } from './languages/evaluatable-expression';
77
+ import { InlineValuesAdapter } from './languages/inline-values';
72
78
  import { DocumentHighlightAdapter } from './languages/document-highlight';
73
79
  import { DocumentFormattingAdapter } from './languages/document-formatting';
74
80
  import { RangeFormattingAdapter } from './languages/range-formatting';
@@ -91,6 +97,7 @@ import { Event } from '@theia/core/lib/common/event';
91
97
  import { CommandRegistryImpl } from './command-registry';
92
98
  import { DeclarationAdapter } from './languages/declaration';
93
99
  import { CallHierarchyAdapter } from './languages/call-hierarchy';
100
+ import { TypeHierarchyAdapter } from './languages/type-hierarchy';
94
101
  import { BinaryBuffer } from '@theia/core/lib/common/buffer';
95
102
  import { DocumentSemanticTokensAdapter, DocumentRangeSemanticTokensAdapter } from './languages/semantic-highlighting';
96
103
  import { isReadonlyArray } from '../common/arrays';
@@ -98,11 +105,13 @@ import { DisposableCollection, disposableTimeout, Disposable as TheiaDisposable
98
105
  import { Severity } from '@theia/core/lib/common/severity';
99
106
  import { LinkedEditingRangeAdapter } from './languages/linked-editing-range';
100
107
  import { serializeEnterRules, serializeIndentation, serializeRegExp } from './languages-utils';
108
+ import { InlayHintsAdapter } from './languages/inlay-hints';
101
109
 
102
110
  type Adapter = CompletionAdapter |
103
111
  SignatureHelpAdapter |
104
112
  HoverAdapter |
105
113
  EvaluatableExpressionAdapter |
114
+ InlineValuesAdapter |
106
115
  DocumentHighlightAdapter |
107
116
  DocumentFormattingAdapter |
108
117
  RangeFormattingAdapter |
@@ -120,11 +129,13 @@ type Adapter = CompletionAdapter |
120
129
  FoldingProviderAdapter |
121
130
  SelectionRangeProviderAdapter |
122
131
  ColorProviderAdapter |
132
+ InlayHintsAdapter |
123
133
  RenameAdapter |
124
134
  CallHierarchyAdapter |
125
135
  DocumentRangeSemanticTokensAdapter |
126
136
  DocumentSemanticTokensAdapter |
127
- LinkedEditingRangeAdapter;
137
+ LinkedEditingRangeAdapter |
138
+ TypeHierarchyAdapter;
128
139
 
129
140
  export class LanguagesExtImpl implements LanguagesExt {
130
141
 
@@ -365,6 +376,25 @@ export class LanguagesExtImpl implements LanguagesExt {
365
376
  }
366
377
  // ### EvaluatableExpression Provider end
367
378
 
379
+ // ### InlineValues Provider begin
380
+ registerInlineValuesProvider(selector: theia.DocumentSelector, provider: theia.InlineValuesProvider, pluginInfo: PluginInfo): theia.Disposable {
381
+ const eventHandle = typeof provider.onDidChangeInlineValues === 'function' ? this.nextCallId() : undefined;
382
+ const callId = this.addNewAdapter(new InlineValuesAdapter(provider, this.documents));
383
+ this.proxy.$registerInlineValuesProvider(callId, pluginInfo, this.transformDocumentSelector(selector));
384
+ let result = this.createDisposable(callId);
385
+
386
+ if (eventHandle !== undefined) {
387
+ const subscription = provider.onDidChangeInlineValues!(_ => this.proxy.$emitInlineValuesEvent(eventHandle));
388
+ result = Disposable.from(result, subscription);
389
+ }
390
+ return result;
391
+ }
392
+
393
+ $provideInlineValues(handle: number, resource: UriComponents, range: Range, context: InlineValueContext, token: theia.CancellationToken): Promise<InlineValue[] | undefined> {
394
+ return this.withAdapter(handle, InlineValuesAdapter, adapter => adapter.provideInlineValues(URI.revive(resource), range, context, token), undefined);
395
+ }
396
+ // ### InlineValue Provider end
397
+
368
398
  // ### Document Highlight Provider begin
369
399
  registerDocumentHighlightProvider(selector: theia.DocumentSelector, provider: theia.DocumentHighlightProvider, pluginInfo: PluginInfo): theia.Disposable {
370
400
  const callId = this.addNewAdapter(new DocumentHighlightAdapter(provider, this.documents));
@@ -579,6 +609,35 @@ export class LanguagesExtImpl implements LanguagesExt {
579
609
  }
580
610
  // ### Color Provider end
581
611
 
612
+ // ### InlayHints Provider begin
613
+ registerInlayHintsProvider(selector: theia.DocumentSelector, provider: theia.InlayHintsProvider, pluginInfo: PluginInfo): theia.Disposable {
614
+ const eventHandle = typeof provider.onDidChangeInlayHints === 'function' ? this.nextCallId() : undefined;
615
+ const callId = this.addNewAdapter(new InlayHintsAdapter(provider, this.documents, this.commands));
616
+ this.proxy.$registerInlayHintsProvider(callId, pluginInfo, this.transformDocumentSelector(selector));
617
+
618
+ let result = this.createDisposable(callId);
619
+
620
+ if (eventHandle !== undefined) {
621
+ const subscription = provider.onDidChangeInlayHints!(() => this.proxy.$emitInlayHintsEvent(eventHandle));
622
+ result = Disposable.from(result, subscription);
623
+ }
624
+
625
+ return result;
626
+ }
627
+
628
+ $provideInlayHints(handle: number, resource: UriComponents, range: Range, token: theia.CancellationToken): Promise<InlayHintsDto | undefined> {
629
+ return this.withAdapter(handle, InlayHintsAdapter, adapter => adapter.provideInlayHints(URI.revive(resource), range, token), undefined);
630
+ }
631
+
632
+ $resolveInlayHint(handle: number, id: ChainedCacheId, token: theia.CancellationToken): Promise<InlayHintDto | undefined> {
633
+ return this.withAdapter(handle, InlayHintsAdapter, adapter => adapter.resolveInlayHint(id, token), undefined);
634
+ }
635
+
636
+ $releaseInlayHints(handle: number, id: number): void {
637
+ this.withAdapter(handle, InlayHintsAdapter, async adapter => adapter.releaseHints(id), undefined);
638
+ }
639
+ // ### InlayHints Provider end
640
+
582
641
  // ### Folding Range Provider begin
583
642
  registerFoldingRangeProvider(selector: theia.DocumentSelector, provider: theia.FoldingRangeProvider, pluginInfo: PluginInfo): theia.Disposable {
584
643
  const callId = this.addNewAdapter(new FoldingProviderAdapter(provider, this.documents));
@@ -656,6 +715,53 @@ export class LanguagesExtImpl implements LanguagesExt {
656
715
  }
657
716
  // ### Call Hierarchy Provider end
658
717
 
718
+ // ### Type hierarchy Provider begin
719
+ registerTypeHierarchyProvider(selector: theia.DocumentSelector, provider: theia.TypeHierarchyProvider): theia.Disposable {
720
+ const callId = this.addNewAdapter(new TypeHierarchyAdapter(provider, this.documents));
721
+ this.proxy.$registerTypeHierarchyProvider(callId, this.transformDocumentSelector(selector));
722
+ return this.createDisposable(callId);
723
+ }
724
+
725
+ $prepareTypeHierarchy(handle: number, resource: UriComponents, location: Position, token: theia.CancellationToken
726
+ ): Promise<TypeHierarchyItem[] | undefined> {
727
+ return this.withAdapter(
728
+ handle,
729
+ TypeHierarchyAdapter,
730
+ adapter => adapter.prepareSession(URI.revive(resource), location, token),
731
+ undefined
732
+ );
733
+ }
734
+
735
+ $provideSuperTypes(handle: number, sessionId: string, itemId: string, token: theia.CancellationToken):
736
+ Promise<TypeHierarchyItem[] | undefined> {
737
+ return this.withAdapter(
738
+ handle,
739
+ TypeHierarchyAdapter,
740
+ adapter => adapter.provideSupertypes(sessionId, itemId, token),
741
+ undefined
742
+ );
743
+ }
744
+
745
+ $provideSubTypes(handle: number, sessionId: string, itemId: string, token: theia.CancellationToken):
746
+ Promise<TypeHierarchyItem[] | undefined> {
747
+ return this.withAdapter(
748
+ handle,
749
+ TypeHierarchyAdapter,
750
+ adapter => adapter.provideSubtypes(sessionId, itemId, token),
751
+ undefined
752
+ );
753
+ }
754
+
755
+ $releaseTypeHierarchy(handle: number, session?: string): Promise<boolean> {
756
+ return this.withAdapter(
757
+ handle,
758
+ TypeHierarchyAdapter,
759
+ adapter => adapter.releaseSession(session),
760
+ false);
761
+ }
762
+
763
+ // ### Type hierarchy Provider end
764
+
659
765
  // ### Linked Editing Range Provider begin
660
766
  registerLinkedEditingRangeProvider(selector: theia.DocumentSelector, provider: theia.LinkedEditingRangeProvider): theia.Disposable {
661
767
  const handle = this.addNewAdapter(new LinkedEditingRangeAdapter(this.documents, provider));
@@ -79,6 +79,10 @@ import {
79
79
  SignatureHelpTriggerKind,
80
80
  Hover,
81
81
  EvaluatableExpression,
82
+ InlineValueEvaluatableExpression,
83
+ InlineValueText,
84
+ InlineValueVariableLookup,
85
+ InlineValueContext,
82
86
  DocumentHighlightKind,
83
87
  DocumentHighlight,
84
88
  DocumentLink,
@@ -130,6 +134,7 @@ import {
130
134
  CallHierarchyItem,
131
135
  CallHierarchyIncomingCall,
132
136
  CallHierarchyOutgoingCall,
137
+ TypeHierarchyItem,
133
138
  TimelineItem,
134
139
  EnvironmentVariableMutatorType,
135
140
  SemanticTokensLegend,
@@ -145,7 +150,11 @@ import {
145
150
  LinkedEditingRanges,
146
151
  LanguageStatusSeverity,
147
152
  TextDocumentChangeReason,
148
- InputBoxValidationSeverity
153
+ InputBoxValidationSeverity,
154
+ TerminalLink,
155
+ InlayHint,
156
+ InlayHintKind,
157
+ InlayHintLabelPart
149
158
  } from './types-impl';
150
159
  import { AuthenticationExtImpl } from './authentication-ext';
151
160
  import { SymbolKind } from '../common/plugin-api-rpc-model';
@@ -235,14 +244,17 @@ export function createAPIFactory(
235
244
  return authenticationExt.onDidChangeSessions;
236
245
  }
237
246
  };
247
+ function commandIsDeclaredInPackage(id: string, model: PluginPackage): boolean {
248
+ const rawCommands = model.contributes?.commands;
249
+ if (!rawCommands) { return false; }
250
+ return Array.isArray(rawCommands) ? rawCommands.some(candidate => candidate.command === id) : rawCommands.command === id;
251
+ }
238
252
  const commands: typeof theia.commands = {
239
253
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
240
254
  registerCommand(command: theia.CommandDescription | string, handler?: <T>(...args: any[]) => T | Thenable<T | undefined>, thisArg?: any): Disposable {
241
255
  // use of the ID when registering commands
242
256
  if (typeof command === 'string') {
243
- const rawCommands = plugin.rawModel.contributes && plugin.rawModel.contributes.commands;
244
- const contributedCommands = rawCommands ? Array.isArray(rawCommands) ? rawCommands : [rawCommands] : undefined;
245
- if (handler && contributedCommands && contributedCommands.some(item => item.command === command)) {
257
+ if (handler && commandIsDeclaredInPackage(command, plugin.rawModel)) {
246
258
  return commandRegistry.registerHandler(command, handler, thisArg);
247
259
  }
248
260
  return commandRegistry.registerCommand({ id: command }, handler, thisArg);
@@ -254,7 +266,7 @@ export function createAPIFactory(
254
266
  return commandRegistry.executeCommand<T>(commandId, ...args);
255
267
  },
256
268
  registerTextEditorCommand(command: string, handler: (textEditor: theia.TextEditor, edit: theia.TextEditorEdit, ...arg: any[]) => void, thisArg?: any): Disposable {
257
- return commandRegistry.registerCommand({ id: command }, (...args: any[]): any => {
269
+ const internalHandler = (...args: any[]): any => {
258
270
  const activeTextEditor = editors.getActiveEditor();
259
271
  if (!activeTextEditor) {
260
272
  console.warn('Cannot execute ' + command + ' because there is no active text editor.');
@@ -271,7 +283,10 @@ export function createAPIFactory(
271
283
  }, err => {
272
284
  console.warn('An error occurred while running command ' + command, err);
273
285
  });
274
- });
286
+ };
287
+ return commandIsDeclaredInPackage(command, plugin.rawModel)
288
+ ? commandRegistry.registerHandler(command, internalHandler)
289
+ : commandRegistry.registerCommand({ id: command }, internalHandler);
275
290
  },
276
291
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
277
292
  registerHandler(commandId: string, handler: (...args: any[]) => any, thisArg?: any): Disposable {
@@ -289,7 +304,7 @@ export function createAPIFactory(
289
304
  }
290
305
  };
291
306
 
292
- const { onDidChangeActiveTerminal, onDidCloseTerminal, onDidOpenTerminal } = terminalExt;
307
+ const { onDidChangeActiveTerminal, onDidChangeTerminalState, onDidCloseTerminal, onDidOpenTerminal } = terminalExt;
293
308
  const showInformationMessage = messageRegistryExt.showMessage.bind(messageRegistryExt, MainMessageType.Info);
294
309
  const showWarningMessage = messageRegistryExt.showMessage.bind(messageRegistryExt, MainMessageType.Warning);
295
310
  const showErrorMessage = messageRegistryExt.showMessage.bind(messageRegistryExt, MainMessageType.Error);
@@ -439,6 +454,7 @@ export function createAPIFactory(
439
454
  shellArgs?: string[]): theia.Terminal {
440
455
  return terminalExt.createTerminal(nameOrOptions, shellPath, shellArgs);
441
456
  },
457
+ onDidChangeTerminalState,
442
458
  onDidCloseTerminal,
443
459
  onDidOpenTerminal,
444
460
  createTextEditorDecorationType(options: theia.DecorationRenderOptions): theia.TextEditorDecorationType {
@@ -466,8 +482,8 @@ export function createAPIFactory(
466
482
  createInputBox(): theia.InputBox {
467
483
  return quickOpenExt.createInputBox(plugin);
468
484
  },
469
- registerTerminalLinkProvider(provider: theia.TerminalLinkProvider): void {
470
- /* NOOP. To be implemented at later stage */
485
+ registerTerminalLinkProvider(provider: theia.TerminalLinkProvider): theia.Disposable {
486
+ return terminalExt.registerTerminalLinkProvider(provider);
471
487
  },
472
488
  get activeColorTheme(): theia.ColorTheme {
473
489
  return themingExt.activeColorTheme;
@@ -700,6 +716,9 @@ export function createAPIFactory(
700
716
  registerEvaluatableExpressionProvider(selector: theia.DocumentSelector, provider: theia.EvaluatableExpressionProvider): theia.Disposable {
701
717
  return languagesExt.registerEvaluatableExpressionProvider(selector, provider, pluginToPluginInfo(plugin));
702
718
  },
719
+ registerInlineValuesProvider(selector: theia.DocumentSelector, provider: theia.InlineValuesProvider): theia.Disposable {
720
+ return languagesExt.registerInlineValuesProvider(selector, provider, pluginToPluginInfo(plugin));
721
+ },
703
722
  registerDocumentHighlightProvider(selector: theia.DocumentSelector, provider: theia.DocumentHighlightProvider): theia.Disposable {
704
723
  return languagesExt.registerDocumentHighlightProvider(selector, provider, pluginToPluginInfo(plugin));
705
724
  },
@@ -739,6 +758,9 @@ export function createAPIFactory(
739
758
  registerColorProvider(selector: theia.DocumentSelector, provider: theia.DocumentColorProvider): theia.Disposable {
740
759
  return languagesExt.registerColorProvider(selector, provider, pluginToPluginInfo(plugin));
741
760
  },
761
+ registerInlayHintsProvider(selector: theia.DocumentSelector, provider: theia.InlayHintsProvider): theia.Disposable {
762
+ return languagesExt.registerInlayHintsProvider(selector, provider, pluginToPluginInfo(plugin));
763
+ },
742
764
  registerFoldingRangeProvider(selector: theia.DocumentSelector, provider: theia.FoldingRangeProvider): theia.Disposable {
743
765
  return languagesExt.registerFoldingRangeProvider(selector, provider, pluginToPluginInfo(plugin));
744
766
  },
@@ -759,6 +781,9 @@ export function createAPIFactory(
759
781
  registerCallHierarchyProvider(selector: theia.DocumentSelector, provider: theia.CallHierarchyProvider): theia.Disposable {
760
782
  return languagesExt.registerCallHierarchyProvider(selector, provider);
761
783
  },
784
+ registerTypeHierarchyProvider(selector: theia.DocumentSelector, provider: theia.TypeHierarchyProvider): theia.Disposable {
785
+ return languagesExt.registerTypeHierarchyProvider(selector, provider);
786
+ },
762
787
  registerLinkedEditingRangeProvider(selector: theia.DocumentSelector, provider: theia.LinkedEditingRangeProvider): theia.Disposable {
763
788
  return languagesExt.registerLinkedEditingRangeProvider(selector, provider);
764
789
  },
@@ -961,6 +986,10 @@ export function createAPIFactory(
961
986
  SignatureHelpTriggerKind,
962
987
  Hover,
963
988
  EvaluatableExpression,
989
+ InlineValueEvaluatableExpression,
990
+ InlineValueText,
991
+ InlineValueVariableLookup,
992
+ InlineValueContext,
964
993
  DocumentHighlightKind,
965
994
  DocumentHighlight,
966
995
  DocumentLink,
@@ -1013,6 +1042,7 @@ export function createAPIFactory(
1013
1042
  CallHierarchyItem,
1014
1043
  CallHierarchyIncomingCall,
1015
1044
  CallHierarchyOutgoingCall,
1045
+ TypeHierarchyItem,
1016
1046
  TimelineItem,
1017
1047
  EnvironmentVariableMutatorType,
1018
1048
  SemanticTokensLegend,
@@ -1024,10 +1054,14 @@ export function createAPIFactory(
1024
1054
  ColorThemeKind,
1025
1055
  SourceControlInputBoxValidationType,
1026
1056
  FileDecoration,
1057
+ TerminalLink,
1027
1058
  CancellationError,
1028
1059
  ExtensionMode,
1029
1060
  LinkedEditingRanges,
1030
- InputBoxValidationSeverity
1061
+ InputBoxValidationSeverity,
1062
+ InlayHint,
1063
+ InlayHintKind,
1064
+ InlayHintLabelPart
1031
1065
  };
1032
1066
  };
1033
1067
  }