@opensumi/ide-outline 2.21.13 → 2.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/lib/browser/index.js.map +1 -1
  2. package/lib/browser/outline-node.d.ts +1 -1
  3. package/lib/browser/outline-node.d.ts.map +1 -1
  4. package/lib/browser/outline-node.define.js +10 -10
  5. package/lib/browser/outline-node.define.js.map +1 -1
  6. package/lib/browser/outline-node.js +2 -2
  7. package/lib/browser/outline-node.js.map +1 -1
  8. package/lib/browser/outline-node.module.less +5 -23
  9. package/lib/browser/outline.contribution.js +6 -6
  10. package/lib/browser/outline.contribution.js.map +1 -1
  11. package/lib/browser/outline.d.ts +3 -3
  12. package/lib/browser/outline.d.ts.map +1 -1
  13. package/lib/browser/outline.js +11 -11
  14. package/lib/browser/outline.js.map +1 -1
  15. package/lib/browser/services/outline-contextkey.service.js.map +1 -1
  16. package/lib/browser/services/outline-decoration.service.js.map +1 -1
  17. package/lib/browser/services/outline-event.service.d.ts +1 -1
  18. package/lib/browser/services/outline-event.service.d.ts.map +1 -1
  19. package/lib/browser/services/outline-event.service.js.map +1 -1
  20. package/lib/browser/services/outline-model.js.map +1 -1
  21. package/lib/browser/services/outline-model.service.d.ts +0 -2
  22. package/lib/browser/services/outline-model.service.d.ts.map +1 -1
  23. package/lib/browser/services/outline-model.service.js +5 -27
  24. package/lib/browser/services/outline-model.service.js.map +1 -1
  25. package/lib/browser/services/outline-tree.service.js +4 -4
  26. package/lib/browser/services/outline-tree.service.js.map +1 -1
  27. package/package.json +13 -12
  28. package/src/browser/index.ts +33 -0
  29. package/src/browser/outline-node.define.ts +75 -0
  30. package/src/browser/outline-node.module.less +183 -0
  31. package/src/browser/outline-node.tsx +160 -0
  32. package/src/browser/outline.contribution.ts +146 -0
  33. package/src/browser/outline.module.less +11 -0
  34. package/src/browser/outline.tsx +159 -0
  35. package/src/browser/services/outline-contextkey.service.ts +18 -0
  36. package/src/browser/services/outline-decoration.service.ts +60 -0
  37. package/src/browser/services/outline-event.service.ts +45 -0
  38. package/src/browser/services/outline-model.service.ts +584 -0
  39. package/src/browser/services/outline-model.ts +38 -0
  40. package/src/browser/services/outline-tree.service.ts +180 -0
  41. package/src/common/index.ts +32 -0
  42. package/src/index.ts +1 -0
@@ -0,0 +1,180 @@
1
+ import { Injectable, Autowired } from '@opensumi/di';
2
+ import { Tree, ITreeNodeOrCompositeTreeNode } from '@opensumi/ide-components';
3
+ import {
4
+ URI,
5
+ Emitter,
6
+ MaybeNull,
7
+ IdleValue,
8
+ compareRangesUsingStarts,
9
+ getSymbolIcon,
10
+ Event,
11
+ StorageProvider,
12
+ STORAGE_NAMESPACE,
13
+ IStorage,
14
+ } from '@opensumi/ide-core-browser';
15
+ import {
16
+ DocumentSymbolStore,
17
+ INormalizedDocumentSymbol,
18
+ } from '@opensumi/ide-editor/lib/browser/breadcrumb/document-symbol';
19
+
20
+ import { OutlineSortOrder } from '../../common';
21
+ import { OutlineCompositeTreeNode, OutlineTreeNode, OutlineRoot } from '../outline-node.define';
22
+
23
+ import { OutlineContextKeyService } from './outline-contextkey.service';
24
+
25
+ @Injectable()
26
+ export class OutlineTreeService extends Tree {
27
+ @Autowired(DocumentSymbolStore)
28
+ private documentSymbolStore: DocumentSymbolStore;
29
+
30
+ @Autowired(OutlineContextKeyService)
31
+ private outlineContextKeyService: OutlineContextKeyService;
32
+
33
+ @Autowired(StorageProvider)
34
+ private storageProvider: StorageProvider;
35
+
36
+ // 处理字符串排序,IdleValue 在空闲或需要时执行 [idle-or-urgent stratage implementation](https://philipwalton.com/articles/idle-until-urgent)
37
+ private readonly collator = new IdleValue<Intl.Collator>(() => new Intl.Collator(undefined, { numeric: true }));
38
+ private readonly cacheOutlineNodes: Map<string, OutlineCompositeTreeNode | OutlineTreeNode> = new Map();
39
+
40
+ private _sortType: OutlineSortOrder = OutlineSortOrder.ByPosition;
41
+ private _followCursor = false;
42
+
43
+ private _currentUri: MaybeNull<URI>;
44
+
45
+ private onDidChangeEmitter: Emitter<void> = new Emitter();
46
+
47
+ private _whenReady: Promise<void>;
48
+
49
+ private _outlineStorage: IStorage;
50
+
51
+ constructor() {
52
+ super();
53
+ this._whenReady = this.init();
54
+ }
55
+
56
+ async init() {
57
+ this._outlineStorage = await this.storageProvider(STORAGE_NAMESPACE.OUTLINE);
58
+ this._sortType = this._outlineStorage.get('sortType', OutlineSortOrder.ByPosition);
59
+ this.outlineContextKeyService.outlineSortTypeContext.set(this._sortType);
60
+ this._followCursor = this._outlineStorage.get('followCursor', false);
61
+ this.outlineContextKeyService.outlineFollowCursorContext.set(this._followCursor);
62
+ }
63
+
64
+ get whenReady() {
65
+ return this._whenReady;
66
+ }
67
+
68
+ get onDidChange(): Event<void> {
69
+ return this.onDidChangeEmitter.event;
70
+ }
71
+
72
+ get currentUri() {
73
+ return this._currentUri;
74
+ }
75
+
76
+ set currentUri(value: MaybeNull<URI>) {
77
+ this._currentUri = value;
78
+ }
79
+
80
+ get followCursor() {
81
+ return this._followCursor;
82
+ }
83
+
84
+ set followCursor(value: boolean) {
85
+ if (this._followCursor === value) {
86
+ return;
87
+ }
88
+ this._followCursor = value;
89
+ this.outlineContextKeyService.outlineFollowCursorContext.set(value);
90
+ this._outlineStorage.set('followCursor', value);
91
+ this.onDidChangeEmitter.fire();
92
+ }
93
+
94
+ get sortType() {
95
+ return this._sortType;
96
+ }
97
+
98
+ set sortType(type: OutlineSortOrder) {
99
+ if (this._sortType === type) {
100
+ return;
101
+ }
102
+ this._sortType = type;
103
+ this.outlineContextKeyService.outlineSortTypeContext.set(type);
104
+ this._outlineStorage.set('sortType', type);
105
+ this.onDidChangeEmitter.fire();
106
+ }
107
+
108
+ async resolveChildren(
109
+ parent?: OutlineCompositeTreeNode,
110
+ ): Promise<(OutlineCompositeTreeNode | OutlineRoot | OutlineTreeNode)[]> {
111
+ let children: (OutlineCompositeTreeNode | OutlineRoot | OutlineTreeNode)[] = [];
112
+ if (!parent) {
113
+ children = [new OutlineRoot(this, this.currentUri)];
114
+ } else if (parent) {
115
+ if (!OutlineCompositeTreeNode.is(parent)) {
116
+ if (!((parent as OutlineRoot).currentUri || this.currentUri)) {
117
+ return [];
118
+ }
119
+ const symbols = this.documentSymbolStore.getDocumentSymbol(
120
+ ((parent as OutlineRoot).currentUri || this.currentUri)!,
121
+ );
122
+ children =
123
+ symbols?.map((symbol: INormalizedDocumentSymbol) => {
124
+ if (symbol.children?.length) {
125
+ return new OutlineCompositeTreeNode(this, parent, symbol, getSymbolIcon(symbol.kind) + ' outline-icon');
126
+ }
127
+ return new OutlineTreeNode(this, parent, symbol, getSymbolIcon(symbol.kind) + ' outline-icon');
128
+ }) || [];
129
+ } else if (parent.raw) {
130
+ children =
131
+ parent.raw.children
132
+ ?.map((symbol: INormalizedDocumentSymbol) => {
133
+ const cache = this.cacheOutlineNodes.get(symbol.id);
134
+ if (symbol.children?.length) {
135
+ return new OutlineCompositeTreeNode(this, parent, symbol, getSymbolIcon(symbol.kind) + ' outline-icon');
136
+ }
137
+ return new OutlineTreeNode(this, parent, symbol, getSymbolIcon(symbol.kind) + ' outline-icon');
138
+ })
139
+ .filter((node) => !!node.name) || [];
140
+ }
141
+ }
142
+ this.cacheNodes(children);
143
+ return children;
144
+ }
145
+
146
+ private cacheNodes(nodes: (OutlineCompositeTreeNode | OutlineTreeNode | OutlineRoot)[]) {
147
+ for (const node of nodes) {
148
+ if ((node as OutlineTreeNode).raw) {
149
+ // OutlineTreeNode or OutlineCompositeTreeNode
150
+ this.cacheOutlineNodes.set((node as OutlineTreeNode).raw.id, node as OutlineTreeNode);
151
+ }
152
+ }
153
+ }
154
+
155
+ getTreeNodeBySymbol(symbol: INormalizedDocumentSymbol) {
156
+ if (symbol) {
157
+ const cache = this.cacheOutlineNodes.get(symbol.id);
158
+ return cache;
159
+ }
160
+ }
161
+
162
+ sortComparator = (a: ITreeNodeOrCompositeTreeNode, b: ITreeNodeOrCompositeTreeNode) => {
163
+ if (this.sortType === OutlineSortOrder.ByKind) {
164
+ return (
165
+ (a as OutlineTreeNode).raw.kind - (b as OutlineTreeNode).raw.kind ||
166
+ this.collator.getValue().compare(a.displayName, b.displayName)
167
+ );
168
+ } else if (this.sortType === OutlineSortOrder.ByName) {
169
+ return (
170
+ this.collator.getValue().compare(a.displayName, b.displayName) ||
171
+ compareRangesUsingStarts((a as OutlineTreeNode).raw.range, (b as OutlineTreeNode).raw.range)
172
+ );
173
+ } else {
174
+ return (
175
+ compareRangesUsingStarts((a as OutlineTreeNode).raw.range, (b as OutlineTreeNode).raw.range) ||
176
+ this.collator.getValue().compare(a.displayName, b.displayName)
177
+ );
178
+ }
179
+ };
180
+ }
@@ -0,0 +1,32 @@
1
+ import { ITreeNode } from '@opensumi/ide-components';
2
+ import { MarkerSeverity, URI } from '@opensumi/ide-core-common';
3
+
4
+ export const enum OutlineSortOrder {
5
+ ByPosition,
6
+ ByName,
7
+ ByKind,
8
+ }
9
+
10
+ export interface IOutlineMarker {
11
+ startLineNumber: number;
12
+ startColumn: number;
13
+ endLineNumber: number;
14
+ endColumn: number;
15
+ severity: MarkerSeverity;
16
+ message?: string;
17
+ }
18
+
19
+ export const IOutlineDecorationService = Symbol('IOutlineDecorationService');
20
+
21
+ export interface IOutlineDecoration {
22
+ color: string;
23
+ tooltip: string;
24
+ badge: string;
25
+ }
26
+
27
+ export interface IOutlineDecorationService {
28
+ getDecoration(node: ITreeNode): IOutlineDecoration;
29
+ updateDiagnosisInfo(uri?: URI): void;
30
+ }
31
+
32
+ export const OUTLINE_VIEW_ID = 'outline-view';
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './common';