@pooder/core 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/index.d.mts +196 -21
- package/dist/index.d.ts +196 -21
- package/dist/index.js +718 -157
- package/dist/index.mjs +707 -156
- package/package.json +1 -1
- package/src/command.ts +10 -10
- package/src/context.ts +22 -17
- package/src/contribution/index.ts +12 -12
- package/src/contribution/points.ts +27 -3
- package/src/contribution/registry.ts +118 -118
- package/src/disposable.ts +3 -3
- package/src/extension.ts +177 -164
- package/src/index.ts +338 -145
- package/src/run-test-full.ts +98 -98
- package/src/service.ts +191 -11
- package/src/services/CommandService.ts +79 -79
- package/src/services/ConfigurationService.ts +107 -107
- package/src/services/ToolRegistryService.ts +41 -0
- package/src/services/ToolSessionService.ts +213 -0
- package/src/services/WorkbenchService.ts +187 -8
- package/src/services/index.ts +23 -1
- package/src/services/tokens.ts +27 -0
- package/src/test-extension-full.ts +79 -79
package/src/extension.ts
CHANGED
|
@@ -1,164 +1,177 @@
|
|
|
1
|
-
import { ExtensionContext } from "./context";
|
|
2
|
-
import { Contribution, ContributionPointIds } from "./contribution";
|
|
3
|
-
import Disposable from "./disposable";
|
|
4
|
-
import CommandService from "./services/CommandService";
|
|
5
|
-
import { ConfigurationService } from "./services";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (pointId === ContributionPointIds.
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
if (
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
1
|
+
import { ExtensionContext } from "./context";
|
|
2
|
+
import { Contribution, ContributionPointIds } from "./contribution";
|
|
3
|
+
import Disposable from "./disposable";
|
|
4
|
+
import CommandService from "./services/CommandService";
|
|
5
|
+
import { ConfigurationService } from "./services";
|
|
6
|
+
import ToolRegistryService from "./services/ToolRegistryService";
|
|
7
|
+
import {
|
|
8
|
+
COMMAND_SERVICE,
|
|
9
|
+
CONFIGURATION_SERVICE,
|
|
10
|
+
TOOL_REGISTRY_SERVICE,
|
|
11
|
+
} from "./services";
|
|
12
|
+
|
|
13
|
+
interface ExtensionMetadata {
|
|
14
|
+
name: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface Extension {
|
|
18
|
+
id: string;
|
|
19
|
+
metadata?: Partial<ExtensionMetadata>;
|
|
20
|
+
|
|
21
|
+
activate(context: ExtensionContext): void;
|
|
22
|
+
deactivate(context: ExtensionContext): void;
|
|
23
|
+
contribute?(): Record<string, any[]>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
class ExtensionRegistry extends Map<string, Extension> {}
|
|
27
|
+
|
|
28
|
+
class ExtensionManager {
|
|
29
|
+
private readonly context: ExtensionContext;
|
|
30
|
+
private extensionRegistry: ExtensionRegistry = new ExtensionRegistry();
|
|
31
|
+
private extensionDisposables: Map<string, Disposable[]> = new Map();
|
|
32
|
+
|
|
33
|
+
constructor(context: ExtensionContext) {
|
|
34
|
+
this.context = context;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
register(extension: Extension) {
|
|
38
|
+
if (this.extensionRegistry.has(extension.id)) {
|
|
39
|
+
console.warn(
|
|
40
|
+
`Plugin "${extension.id}" already registered. It will be overwritten.`,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Initialize disposables for this extension
|
|
45
|
+
this.extensionDisposables.set(extension.id, []);
|
|
46
|
+
const disposables = this.extensionDisposables.get(extension.id)!;
|
|
47
|
+
|
|
48
|
+
// Process declarative contributions
|
|
49
|
+
if (extension.contribute) {
|
|
50
|
+
for (const [pointId, items] of Object.entries(extension.contribute())) {
|
|
51
|
+
if (Array.isArray(items)) {
|
|
52
|
+
items.forEach((item, index) => {
|
|
53
|
+
const contributionId =
|
|
54
|
+
item.id ||
|
|
55
|
+
(item.command
|
|
56
|
+
? item.command
|
|
57
|
+
: `${extension.id}.${pointId}.${index}`);
|
|
58
|
+
const contribution: Contribution = {
|
|
59
|
+
id: contributionId,
|
|
60
|
+
metadata: {
|
|
61
|
+
extensionId: extension.id,
|
|
62
|
+
...item?.metadata,
|
|
63
|
+
},
|
|
64
|
+
data: item,
|
|
65
|
+
};
|
|
66
|
+
const disposable = this.context.contributions.register(
|
|
67
|
+
pointId,
|
|
68
|
+
contribution,
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
// Track contribution registration to unregister later
|
|
72
|
+
disposables.push(disposable);
|
|
73
|
+
|
|
74
|
+
const dispose = this.collectContribution(pointId, contribution);
|
|
75
|
+
if (dispose) {
|
|
76
|
+
disposables.push(dispose);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
this.extensionRegistry.set(extension.id, extension);
|
|
85
|
+
this.context.eventBus.emit("extension:register", extension);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.error(
|
|
88
|
+
`Error in onCreate hook for plugin "${extension.id}":`,
|
|
89
|
+
error,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
extension.activate(this.context);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error(
|
|
97
|
+
`Error in onActivate hook for plugin "${extension.id}":`,
|
|
98
|
+
error,
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
console.log(`Plugin "${extension.id}" registered successfully`);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
collectContribution(pointId: string, item: any): Disposable | undefined {
|
|
106
|
+
// If registering configurations, update ConfigurationService defaults
|
|
107
|
+
if (pointId === ContributionPointIds.CONFIGURATIONS) {
|
|
108
|
+
const configService = this.context.services.get<ConfigurationService>(
|
|
109
|
+
CONFIGURATION_SERVICE,
|
|
110
|
+
);
|
|
111
|
+
configService?.initializeDefaults([item.data]);
|
|
112
|
+
}
|
|
113
|
+
if (pointId === ContributionPointIds.COMMANDS && item.data.handler) {
|
|
114
|
+
const commandService =
|
|
115
|
+
this.context.services.get<CommandService>(COMMAND_SERVICE)!;
|
|
116
|
+
|
|
117
|
+
return commandService.registerCommand(item.id, item.data.handler);
|
|
118
|
+
}
|
|
119
|
+
if (pointId === ContributionPointIds.TOOLS) {
|
|
120
|
+
const toolRegistry = this.context.services.get<ToolRegistryService>(
|
|
121
|
+
TOOL_REGISTRY_SERVICE,
|
|
122
|
+
);
|
|
123
|
+
if (!toolRegistry) return;
|
|
124
|
+
return toolRegistry.registerTool(item.data);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
unregister(name: string) {
|
|
129
|
+
const extension = this.extensionRegistry.get(name);
|
|
130
|
+
if (!extension) {
|
|
131
|
+
console.warn(`Plugin "${name}" not found.`);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
extension.deactivate(this.context);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
console.error(`Error in deactivate for plugin "${name}":`, error);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Dispose all resources associated with this extension
|
|
142
|
+
const disposables = this.extensionDisposables.get(name);
|
|
143
|
+
if (disposables) {
|
|
144
|
+
disposables.forEach((d) => d.dispose());
|
|
145
|
+
this.extensionDisposables.delete(name);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
this.extensionRegistry.delete(name);
|
|
149
|
+
console.log(`Plugin "${name}" unregistered`);
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
enable(name: string) {
|
|
154
|
+
const extension = this.extensionRegistry.get(name);
|
|
155
|
+
if (!extension) {
|
|
156
|
+
console.warn(`Plugin "${name}" not found.`);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
disable(name: string) {
|
|
162
|
+
const extension = this.extensionRegistry.get(name);
|
|
163
|
+
if (!extension) {
|
|
164
|
+
console.warn(`Plugin "${name}" not found.`);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
update() {}
|
|
170
|
+
|
|
171
|
+
destroy() {
|
|
172
|
+
const extensionNames = Array.from(this.extensionRegistry.keys());
|
|
173
|
+
extensionNames.forEach((name) => this.unregister(name));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export { Extension, ExtensionMetadata, ExtensionRegistry, ExtensionManager };
|