@theia/typehierarchy 1.53.0-next.5 → 1.53.0-next.55

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.
@@ -1,163 +1,163 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2019 TypeFox 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-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { injectable } from '@theia/core/shared/inversify';
18
- import { Disposable } from '@theia/core/lib/common/disposable';
19
- import { SymbolKind, Range, TextDocumentPositionParams } from '@theia/core/shared/vscode-languageserver-protocol';
20
-
21
- @injectable()
22
- export class TypeHierarchyRegistry {
23
-
24
- protected readonly providers = new Map<string, TypeHierarchyProvider>();
25
-
26
- async get(languageId: string | undefined): Promise<TypeHierarchyProvider | undefined> {
27
- return languageId ? this.providers.get(languageId) : undefined;
28
- }
29
-
30
- register(provider: TypeHierarchyProvider): Disposable {
31
- const { languageId } = provider;
32
- if (this.providers.has(languageId)) {
33
- throw new Error(`type hierarchy provider for '${languageId}' language is already registered`);
34
- }
35
- this.providers.set(languageId, provider);
36
- return Disposable.create(() => this.providers.delete(languageId));
37
- }
38
-
39
- }
40
-
41
- export interface TypeHierarchyProvider extends Disposable {
42
- readonly languageId: string;
43
- get(params: TypeHierarchyParams): Promise<TypeHierarchyItem | undefined>;
44
- resolve(params: ResolveTypeHierarchyItemParams): Promise<TypeHierarchyItem | undefined>;
45
-
46
- }
47
-
48
- /**
49
- * The type hierarchy params is an extension of the `TextDocumentPositionParams` with optional properties
50
- * which can be used to eagerly resolve the item when requesting from the server.
51
- */
52
- export interface TypeHierarchyParams extends TextDocumentPositionParams {
53
-
54
- /**
55
- * The hierarchy levels to resolve. `0` indicates no level. When not defined, it is treated as `0`.
56
- */
57
- resolve?: number;
58
-
59
- /**
60
- * The direction of the hierarchy levels to resolve.
61
- */
62
- direction?: TypeHierarchyDirection
63
-
64
- }
65
-
66
- export const enum TypeHierarchyDirection {
67
-
68
- /**
69
- * Flag for retrieving/resolving the subtypes.
70
- */
71
- Children,
72
-
73
- /**
74
- * Flag to use when retrieving/resolving the supertypes.
75
- */
76
- Parents,
77
-
78
- /**
79
- * Flag for resolving both the super- and subtypes.
80
- */
81
- Both
82
-
83
- }
84
-
85
- /**
86
- * Parameters for the `typeHierarchy/resolve` request.
87
- */
88
- export interface ResolveTypeHierarchyItemParams {
89
-
90
- /**
91
- * The item to resolve.
92
- */
93
- item: TypeHierarchyItem;
94
-
95
- /**
96
- * The hierarchy levels to resolve. `0` indicates no level.
97
- */
98
- resolve: number;
99
-
100
- /**
101
- * The direction of the hierarchy levels to resolve.
102
- */
103
- direction: TypeHierarchyDirection;
104
- }
105
-
106
- export interface TypeHierarchyItem {
107
-
108
- /**
109
- * The human readable name of the hierarchy item.
110
- */
111
- name: string;
112
-
113
- /**
114
- * Optional detail for the hierarchy item. It can be, for instance, the signature of a function or method.
115
- */
116
- detail?: string;
117
-
118
- /**
119
- * The kind of the hierarchy item. For instance, class or interface.
120
- */
121
- kind: SymbolKind;
122
-
123
- /**
124
- * `true` if the hierarchy item is deprecated. Otherwise, `false`. It is `false` by default.
125
- */
126
- deprecated?: boolean;
127
-
128
- /**
129
- * The URI of the text document where this type hierarchy item belongs to.
130
- */
131
- uri: string;
132
-
133
- /**
134
- * The range enclosing this type hierarchy item not including leading/trailing whitespace but everything else
135
- * like comments. This information is typically used to determine if the clients cursor is inside the type
136
- * hierarchy item to reveal in the symbol in the UI.
137
- */
138
- range: Range;
139
-
140
- /**
141
- * The range that should be selected and revealed when this type hierarchy item is being picked, e.g the name
142
- * of a function. Must be contained by the `range`.
143
- */
144
- selectionRange: Range;
145
-
146
- /**
147
- * If this type hierarchy item is resolved, it contains the direct parents. Could be empty if the item does
148
- * not have any direct parents. If not defined, the parents have not been resolved yet.
149
- */
150
- parents?: TypeHierarchyItem[];
151
-
152
- /**
153
- * If this type hierarchy item is resolved, it contains the direct children of the current item. Could be
154
- * empty if the item does not have any descendants. If not defined, the children have not been resolved.
155
- */
156
- children?: TypeHierarchyItem[];
157
-
158
- /**
159
- * An optional data field can be used to identify a type hierarchy item in a resolve request.
160
- */
161
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
162
- data?: any;
163
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2019 TypeFox 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-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { injectable } from '@theia/core/shared/inversify';
18
+ import { Disposable } from '@theia/core/lib/common/disposable';
19
+ import { SymbolKind, Range, TextDocumentPositionParams } from '@theia/core/shared/vscode-languageserver-protocol';
20
+
21
+ @injectable()
22
+ export class TypeHierarchyRegistry {
23
+
24
+ protected readonly providers = new Map<string, TypeHierarchyProvider>();
25
+
26
+ async get(languageId: string | undefined): Promise<TypeHierarchyProvider | undefined> {
27
+ return languageId ? this.providers.get(languageId) : undefined;
28
+ }
29
+
30
+ register(provider: TypeHierarchyProvider): Disposable {
31
+ const { languageId } = provider;
32
+ if (this.providers.has(languageId)) {
33
+ throw new Error(`type hierarchy provider for '${languageId}' language is already registered`);
34
+ }
35
+ this.providers.set(languageId, provider);
36
+ return Disposable.create(() => this.providers.delete(languageId));
37
+ }
38
+
39
+ }
40
+
41
+ export interface TypeHierarchyProvider extends Disposable {
42
+ readonly languageId: string;
43
+ get(params: TypeHierarchyParams): Promise<TypeHierarchyItem | undefined>;
44
+ resolve(params: ResolveTypeHierarchyItemParams): Promise<TypeHierarchyItem | undefined>;
45
+
46
+ }
47
+
48
+ /**
49
+ * The type hierarchy params is an extension of the `TextDocumentPositionParams` with optional properties
50
+ * which can be used to eagerly resolve the item when requesting from the server.
51
+ */
52
+ export interface TypeHierarchyParams extends TextDocumentPositionParams {
53
+
54
+ /**
55
+ * The hierarchy levels to resolve. `0` indicates no level. When not defined, it is treated as `0`.
56
+ */
57
+ resolve?: number;
58
+
59
+ /**
60
+ * The direction of the hierarchy levels to resolve.
61
+ */
62
+ direction?: TypeHierarchyDirection
63
+
64
+ }
65
+
66
+ export const enum TypeHierarchyDirection {
67
+
68
+ /**
69
+ * Flag for retrieving/resolving the subtypes.
70
+ */
71
+ Children,
72
+
73
+ /**
74
+ * Flag to use when retrieving/resolving the supertypes.
75
+ */
76
+ Parents,
77
+
78
+ /**
79
+ * Flag for resolving both the super- and subtypes.
80
+ */
81
+ Both
82
+
83
+ }
84
+
85
+ /**
86
+ * Parameters for the `typeHierarchy/resolve` request.
87
+ */
88
+ export interface ResolveTypeHierarchyItemParams {
89
+
90
+ /**
91
+ * The item to resolve.
92
+ */
93
+ item: TypeHierarchyItem;
94
+
95
+ /**
96
+ * The hierarchy levels to resolve. `0` indicates no level.
97
+ */
98
+ resolve: number;
99
+
100
+ /**
101
+ * The direction of the hierarchy levels to resolve.
102
+ */
103
+ direction: TypeHierarchyDirection;
104
+ }
105
+
106
+ export interface TypeHierarchyItem {
107
+
108
+ /**
109
+ * The human readable name of the hierarchy item.
110
+ */
111
+ name: string;
112
+
113
+ /**
114
+ * Optional detail for the hierarchy item. It can be, for instance, the signature of a function or method.
115
+ */
116
+ detail?: string;
117
+
118
+ /**
119
+ * The kind of the hierarchy item. For instance, class or interface.
120
+ */
121
+ kind: SymbolKind;
122
+
123
+ /**
124
+ * `true` if the hierarchy item is deprecated. Otherwise, `false`. It is `false` by default.
125
+ */
126
+ deprecated?: boolean;
127
+
128
+ /**
129
+ * The URI of the text document where this type hierarchy item belongs to.
130
+ */
131
+ uri: string;
132
+
133
+ /**
134
+ * The range enclosing this type hierarchy item not including leading/trailing whitespace but everything else
135
+ * like comments. This information is typically used to determine if the clients cursor is inside the type
136
+ * hierarchy item to reveal in the symbol in the UI.
137
+ */
138
+ range: Range;
139
+
140
+ /**
141
+ * The range that should be selected and revealed when this type hierarchy item is being picked, e.g the name
142
+ * of a function. Must be contained by the `range`.
143
+ */
144
+ selectionRange: Range;
145
+
146
+ /**
147
+ * If this type hierarchy item is resolved, it contains the direct parents. Could be empty if the item does
148
+ * not have any direct parents. If not defined, the parents have not been resolved yet.
149
+ */
150
+ parents?: TypeHierarchyItem[];
151
+
152
+ /**
153
+ * If this type hierarchy item is resolved, it contains the direct children of the current item. Could be
154
+ * empty if the item does not have any descendants. If not defined, the children have not been resolved.
155
+ */
156
+ children?: TypeHierarchyItem[];
157
+
158
+ /**
159
+ * An optional data field can be used to identify a type hierarchy item in a resolve request.
160
+ */
161
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
162
+ data?: any;
163
+ }
@@ -1,89 +1,89 @@
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-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { CancellationToken } from '@theia/core';
18
- import { ContributionProvider, Disposable, Emitter, Event } from '@theia/core/lib/common';
19
- import URI from '@theia/core/lib/common/uri';
20
- import { inject, injectable, named, postConstruct } from '@theia/core/shared/inversify';
21
- import { DocumentUri, Position } from '@theia/core/shared/vscode-languageserver-protocol';
22
- import { LanguageSelector, score } from '@theia/editor/lib/common/language-selector';
23
- import { TypeHierarchyItem } from './typehierarchy';
24
-
25
- export const TypeHierarchyService = Symbol('TypeHierarchyService');
26
-
27
- export interface TypeHierarchySession {
28
- items: TypeHierarchyItem[];
29
- dispose(): void;
30
- }
31
-
32
- export interface TypeHierarchyService {
33
-
34
- readonly selector: LanguageSelector;
35
-
36
- prepareSession(uri: DocumentUri, position: Position, cancellationToken: CancellationToken): Promise<TypeHierarchySession | undefined>
37
- provideSuperTypes(sessionId: string, itemId: string, cancellationToken: CancellationToken): Promise<TypeHierarchyItem[] | undefined>
38
- provideSubTypes(sessionId: string, itemId: string, cancellationToken: CancellationToken): Promise<TypeHierarchyItem[] | undefined>
39
- }
40
-
41
- @injectable()
42
- export class TypeHierarchyServiceProvider {
43
-
44
- @inject(ContributionProvider) @named(TypeHierarchyService)
45
- protected readonly contributions: ContributionProvider<TypeHierarchyService>;
46
-
47
- protected readonly onDidChangeEmitter = new Emitter<void>();
48
- get onDidChange(): Event<void> {
49
- return this.onDidChangeEmitter.event;
50
- }
51
-
52
- private services: TypeHierarchyService[] = [];
53
-
54
- @postConstruct()
55
- init(): void {
56
- this.services = this.services.concat(this.contributions.getContributions());
57
- }
58
-
59
- get(languageId: string, uri: URI): TypeHierarchyService | undefined {
60
- return this.services
61
- .filter(service => this.score(service, languageId, uri) > 0)
62
- .sort((left, right) => this.score(right, languageId, uri) - this.score(left, languageId, uri))[0];
63
- }
64
-
65
- protected score(service: TypeHierarchyService, languageId: string, uri: URI): number {
66
- return score(service.selector, uri.scheme, uri.path.toString(), languageId, true);
67
- }
68
-
69
- add(service: TypeHierarchyService): Disposable {
70
- this.services.push(service);
71
- const that = this;
72
- this.onDidChangeEmitter.fire();
73
- return {
74
- dispose: () => {
75
- that.remove(service);
76
- }
77
- };
78
- }
79
-
80
- private remove(service: TypeHierarchyService): boolean {
81
- const length = this.services.length;
82
- this.services = this.services.filter(value => value !== service);
83
- const serviceWasRemoved = length !== this.services.length;
84
- if (serviceWasRemoved) {
85
- this.onDidChangeEmitter.fire();
86
- }
87
- return serviceWasRemoved;
88
- }
89
- }
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-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { CancellationToken } from '@theia/core';
18
+ import { ContributionProvider, Disposable, Emitter, Event } from '@theia/core/lib/common';
19
+ import URI from '@theia/core/lib/common/uri';
20
+ import { inject, injectable, named, postConstruct } from '@theia/core/shared/inversify';
21
+ import { DocumentUri, Position } from '@theia/core/shared/vscode-languageserver-protocol';
22
+ import { LanguageSelector, score } from '@theia/editor/lib/common/language-selector';
23
+ import { TypeHierarchyItem } from './typehierarchy';
24
+
25
+ export const TypeHierarchyService = Symbol('TypeHierarchyService');
26
+
27
+ export interface TypeHierarchySession {
28
+ items: TypeHierarchyItem[];
29
+ dispose(): void;
30
+ }
31
+
32
+ export interface TypeHierarchyService {
33
+
34
+ readonly selector: LanguageSelector;
35
+
36
+ prepareSession(uri: DocumentUri, position: Position, cancellationToken: CancellationToken): Promise<TypeHierarchySession | undefined>
37
+ provideSuperTypes(sessionId: string, itemId: string, cancellationToken: CancellationToken): Promise<TypeHierarchyItem[] | undefined>
38
+ provideSubTypes(sessionId: string, itemId: string, cancellationToken: CancellationToken): Promise<TypeHierarchyItem[] | undefined>
39
+ }
40
+
41
+ @injectable()
42
+ export class TypeHierarchyServiceProvider {
43
+
44
+ @inject(ContributionProvider) @named(TypeHierarchyService)
45
+ protected readonly contributions: ContributionProvider<TypeHierarchyService>;
46
+
47
+ protected readonly onDidChangeEmitter = new Emitter<void>();
48
+ get onDidChange(): Event<void> {
49
+ return this.onDidChangeEmitter.event;
50
+ }
51
+
52
+ private services: TypeHierarchyService[] = [];
53
+
54
+ @postConstruct()
55
+ init(): void {
56
+ this.services = this.services.concat(this.contributions.getContributions());
57
+ }
58
+
59
+ get(languageId: string, uri: URI): TypeHierarchyService | undefined {
60
+ return this.services
61
+ .filter(service => this.score(service, languageId, uri) > 0)
62
+ .sort((left, right) => this.score(right, languageId, uri) - this.score(left, languageId, uri))[0];
63
+ }
64
+
65
+ protected score(service: TypeHierarchyService, languageId: string, uri: URI): number {
66
+ return score(service.selector, uri.scheme, uri.path.toString(), languageId, true);
67
+ }
68
+
69
+ add(service: TypeHierarchyService): Disposable {
70
+ this.services.push(service);
71
+ const that = this;
72
+ this.onDidChangeEmitter.fire();
73
+ return {
74
+ dispose: () => {
75
+ that.remove(service);
76
+ }
77
+ };
78
+ }
79
+
80
+ private remove(service: TypeHierarchyService): boolean {
81
+ const length = this.services.length;
82
+ this.services = this.services.filter(value => value !== service);
83
+ const serviceWasRemoved = length !== this.services.length;
84
+ if (serviceWasRemoved) {
85
+ this.onDidChangeEmitter.fire();
86
+ }
87
+ return serviceWasRemoved;
88
+ }
89
+ }
@@ -1,31 +1,31 @@
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-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { UriComponents } from '@theia/core/lib/common/uri';
18
- import { Range, SymbolKind, SymbolTag } from '@theia/core/shared/vscode-languageserver-protocol';
19
-
20
- export interface TypeHierarchyItem {
21
- _sessionId?: string;
22
- _itemId?: string;
23
-
24
- kind: SymbolKind;
25
- tags?: readonly SymbolTag[];
26
- name: string;
27
- detail?: string;
28
- uri: UriComponents;
29
- range: Range;
30
- selectionRange: Range;
31
- }
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-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { UriComponents } from '@theia/core/lib/common/uri';
18
+ import { Range, SymbolKind, SymbolTag } from '@theia/core/shared/vscode-languageserver-protocol';
19
+
20
+ export interface TypeHierarchyItem {
21
+ _sessionId?: string;
22
+ _itemId?: string;
23
+
24
+ kind: SymbolKind;
25
+ tags?: readonly SymbolTag[];
26
+ name: string;
27
+ detail?: string;
28
+ uri: UriComponents;
29
+ range: Range;
30
+ selectionRange: Range;
31
+ }
@@ -1,29 +1,29 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2019 TypeFox 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-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- /* note: this bogus test file is required so that
18
- we are able to run mocha unit tests on this
19
- package, without having any actual unit tests in it.
20
- This way a coverage report will be generated,
21
- showing 0% coverage, instead of no report.
22
- This file can be removed once we have real unit
23
- tests in place. */
24
-
25
- describe('typehierarchy package', () => {
26
-
27
- it('support code coverage statistics', () => true);
28
-
29
- });
1
+ // *****************************************************************************
2
+ // Copyright (C) 2019 TypeFox 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-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ /* note: this bogus test file is required so that
18
+ we are able to run mocha unit tests on this
19
+ package, without having any actual unit tests in it.
20
+ This way a coverage report will be generated,
21
+ showing 0% coverage, instead of no report.
22
+ This file can be removed once we have real unit
23
+ tests in place. */
24
+
25
+ describe('typehierarchy package', () => {
26
+
27
+ it('support code coverage statistics', () => true);
28
+
29
+ });