Commit 06a02df
feat: offer inline-script env setup as an unresolved-import quick fix
The only discovery surface for PEP 723 inline-script environment setup was
a CodeLens, and codeLens.ts hides it whenever the document is dirty. At the
moment a user types `import requests` and sees a red squiggle, the CodeLens
is gone, so users who do not already know about PEP 723 never find the
feature.
Register a CodeActionProvider that offers "Set up this script's Python
environment" when an unresolved-import diagnostic sits in a `.py` file that
declares a `# /// script` block and has no inline-script environment yet.
The provider parses the in-memory buffer, so it works while dirty, and the
command handler saves the document before setup because the environment
manager reads metadata from disk.
Gates run cheapest-first, before any parsing, because provideCodeActions can
fire on cursor movement: feature flag, then a matching diagnostic, then the
routing key, then shouldRoute, and only then the header parse.
Diagnostics are matched on `code` only, never `source` (Pyrefly-backed
Pylance reports its source as the literal "pylance + pyrefly"). Pyright, Ty,
Pyrefly and mypy dialects are all covered, including the {value, target}
object form of Diagnostic.code. reportMissingModuleSource is included
deliberately, unlike in Pylance's own isMissingImportDiagnostic: a stub
without source means the package is not installed, which setup fixes.
The action deliberately leaves `diagnostics` and `isPreferred` unset. Setup
installs the block's declared dependencies verbatim and may not resolve the
import at all, so the action must not claim to fix the diagnostic or
pre-empt a real import fix. The title promises environment setup, nothing
more.
Setup also now seeds routing metadata after saving a dirty document. Without
it a just-typed block goes from no metadata to an identity while `create`
runs, which setUpInlineScriptEnvironment reads as a concurrent edit and
silently skips the association. The companion-extension prompt moves out of
the setup try block so a failure there is no longer reported to the user as
a setup failure.
The feature stays behind the internal python-envs.inlineScripts.enabled
flag, so none of this is user-visible yet.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>1 parent a48cf3a commit 06a02df
5 files changed
Lines changed: 553 additions & 16 deletions
File tree
- src
- common
- features/inlineScript
- test/features/inlineScript
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
29 | 35 | | |
30 | 36 | | |
31 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 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 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| |||
86 | 88 | | |
87 | 89 | | |
88 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
89 | 102 | | |
90 | | - | |
| 103 | + | |
91 | 104 | | |
92 | 105 | | |
93 | | - | |
94 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
95 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
96 | 126 | | |
97 | | - | |
| 127 | + | |
98 | 128 | | |
99 | 129 | | |
| 130 | + | |
100 | 131 | | |
101 | 132 | | |
102 | | - | |
| 133 | + | |
| 134 | + | |
103 | 135 | | |
104 | 136 | | |
105 | 137 | | |
| |||
112 | 144 | | |
113 | 145 | | |
114 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
115 | 152 | | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
| 153 | + | |
122 | 154 | | |
123 | 155 | | |
124 | 156 | | |
125 | 157 | | |
126 | 158 | | |
127 | 159 | | |
128 | 160 | | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
129 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
130 | 172 | | |
131 | 173 | | |
132 | 174 | | |
| |||
314 | 356 | | |
315 | 357 | | |
316 | 358 | | |
317 | | - | |
318 | | - | |
319 | | - | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
320 | 363 | | |
321 | 364 | | |
322 | 365 | | |
323 | 366 | | |
| 367 | + | |
324 | 368 | | |
325 | 369 | | |
326 | 370 | | |
| |||
0 commit comments