Commit 1fe3322
authored
feat: add optional extensionId hint to registerEnvironmentManager/registerPackageManager (microsoft#1436)
Fixes microsoft#378
## Context
When a third-party extension (e.g., `flying-sheep.hatch`) calls
`api.registerEnvironmentManager(manager)`, the python-environments
extension uses `getCallingExtension()` to determine who's calling by
walking the call stack and matching file paths against known extension
IDs.
This works in production because installed extensions have predictable
paths like
`~/.vscode/extensions/flying-sheep.hatch-1.0.0/dist/extension.js` — the
extension ID appears directly in the path.
During **F5 debugging**, the path is something like
`Z:\source\hatch-code\dist\extension.js`. There's no extension ID in
that path, so detection fails and falls back to `ms-python.python`. This
causes the manager to register as `ms-python.python:hatch` instead of
`flying-sheep.hatch:hatch`, breaking settings, package manager linking,
and anything downstream that uses the manager ID.
## Fix
Add an optional `options` parameter with an `extensionId` field to
`registerEnvironmentManager()` and `registerPackageManager()`:
```typescript
api.registerEnvironmentManager(manager, { extensionId: 'flying-sheep.hatch' });
```
## How third-party extensions use this
```typescript
// Works in both production and F5 debugging:
api.registerEnvironmentManager(manager, { extensionId: 'flying-sheep.hatch' });
api.registerPackageManager(pkgManager, { extensionId: 'flying-sheep.hatch' });
```
In production, the stack-walk succeeds and the hint is ignored. During
debugging, the hint provides the correct ID.
## Changes
- **`src/common/utils/frameUtils.ts`** — `getCallingExtension()` accepts
an optional `extensionIdHint` parameter, used as a last-resort fallback
before defaulting to `ms-python.python`. Validated against
`allExtensions()`.
- **`src/features/envManagers.ts`** — `generateId()`,
`registerEnvironmentManager()`, and `registerPackageManager()` pass the
hint through.
- **`src/features/pythonApi.ts`** — API impl forwards the `options`
parameter.
- **`src/internal.api.ts`** — `EnvironmentManagers` interface updated.
- **`src/api.ts`**, **`pythonEnvironmentsApi/src/main.ts`**,
**`examples/sample1/src/api.ts`** — Public API type definitions updated.
## Backward compatibility
This is a **non-breaking** addition. The new parameter is optional — all
existing callers (internal managers, tests, third-party extensions)
continue to work without changes. The public API has had optional
parameters added before (e.g., `CreateEnvironmentOptions` was added to
`createEnvironment()`).1 parent e7ac499 commit 1fe3322
File tree
7 files changed
+56
-19
lines changed- examples/sample1/src
- pythonEnvironmentsApi/src
- src
- common/utils
- features
7 files changed
+56
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
818 | 818 | | |
819 | 819 | | |
820 | 820 | | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
821 | 825 | | |
822 | 826 | | |
823 | 827 | | |
824 | | - | |
| 828 | + | |
825 | 829 | | |
826 | 830 | | |
827 | 831 | | |
| |||
922 | 926 | | |
923 | 927 | | |
924 | 928 | | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
925 | 933 | | |
926 | 934 | | |
927 | 935 | | |
928 | | - | |
| 936 | + | |
929 | 937 | | |
930 | 938 | | |
931 | 939 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
842 | 842 | | |
843 | 843 | | |
844 | 844 | | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
845 | 849 | | |
846 | 850 | | |
847 | 851 | | |
848 | | - | |
| 852 | + | |
849 | 853 | | |
850 | 854 | | |
851 | 855 | | |
| |||
947 | 951 | | |
948 | 952 | | |
949 | 953 | | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
950 | 958 | | |
951 | 959 | | |
952 | 960 | | |
953 | | - | |
| 961 | + | |
954 | 962 | | |
955 | 963 | | |
956 | 964 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
836 | 836 | | |
837 | 837 | | |
838 | 838 | | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
839 | 843 | | |
840 | 844 | | |
841 | 845 | | |
842 | | - | |
| 846 | + | |
843 | 847 | | |
844 | 848 | | |
845 | 849 | | |
| |||
941 | 945 | | |
942 | 946 | | |
943 | 947 | | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
944 | 952 | | |
945 | 953 | | |
946 | 954 | | |
947 | | - | |
| 955 | + | |
948 | 956 | | |
949 | 957 | | |
950 | 958 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
97 | 110 | | |
98 | 111 | | |
99 | 112 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | | - | |
| 76 | + | |
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | | - | |
123 | | - | |
| 122 | + | |
| 123 | + | |
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
| 85 | + | |
86 | 86 | | |
87 | | - | |
| 87 | + | |
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| |||
233 | 233 | | |
234 | 234 | | |
235 | 235 | | |
236 | | - | |
| 236 | + | |
237 | 237 | | |
238 | | - | |
| 238 | + | |
239 | 239 | | |
240 | 240 | | |
241 | 241 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
80 | | - | |
| 79 | + | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| |||
0 commit comments