@@ -104,13 +104,14 @@ async function configure(connection) {
104
104
* Refresh the environment
105
105
*
106
106
* @param {import("vscode-jsonrpc").MessageConnection } connection
107
- * @param {undefined | 'global' | 'workspace' } searchScope
107
+ * @param {undefined | { searchKind?: string } | { searchPaths?: string[] } } search Defaults to searching for all environments on the current machine.
108
+ * Have a look at the JSONRPC.md file for more information.
108
109
*/
109
- async function refresh ( connection , searchScope ) {
110
+ async function refresh ( connection , search ) {
110
111
environments . length = 0 ;
111
- const { duration } = await connection . sendRequest ( "refresh" , { searchScope } ) ;
112
- const scope = searchScope
113
- ? ` (in ${ searchScope } scope )`
112
+ const { duration } = await connection . sendRequest ( "refresh" , search ) ;
113
+ const scope = search
114
+ ? ` (in ${ JSON . stringify ( search ) } )`
114
115
: "(in machine scope)" ;
115
116
console . log (
116
117
`Found ${ environments . length } environments in ${ duration } ms ${ scope } `
@@ -122,7 +123,7 @@ async function refresh(connection, searchScope) {
122
123
*
123
124
* @param {import("vscode-jsonrpc").MessageConnection } connection
124
125
*/
125
- async function clear ( connection , searchScope ) {
126
+ async function clear ( connection ) {
126
127
await connection . sendRequest ( "clear" ) ;
127
128
}
128
129
@@ -151,41 +152,30 @@ async function resolve(connection, executable) {
151
152
}
152
153
}
153
154
154
- /**
155
- * Gets all possible information about the Python executable provided.
156
- * This will spawn the Python executable (if not already done in the past).
157
- * This must be used only if some of the information already avaialble is not sufficient.
158
- *
159
- * E.g. if a Python env was discovered and the version information is not know,
160
- * but is requried, then call this method.
161
- * If on the other hand, all of the information is already available, then there's no need to call this method.
162
- * In fact it would be better to avoid calling this method, as it will spawn a new process & consume resouces.
163
- *
164
- * @param {String } searchPath Workspace Directory, directory with environments, Python environment path or python executable.
165
- * @param {import("vscode-jsonrpc").MessageConnection } connection
166
- */
167
- async function find ( connection , searchPath ) {
168
- const environments = await connection . sendRequest ( "find" , { searchPath } ) ;
169
- console . log ( `Found ${ environments . length } environments in ${ searchPath } ` ) ;
170
- }
171
-
172
155
async function main ( ) {
173
156
const connection = await start ( ) ;
174
157
175
158
// First request to the server, to configure the server.
176
159
await configure ( connection ) ;
177
160
178
161
await refresh ( connection ) ;
179
- // Search for environments in the defined workspace folders.
180
- await refresh ( connection , "workspace" ) ;
181
162
182
163
// Search for environments in the specified folders.
183
164
// This could be a folder thats not part of the workspace and not in any known location
184
165
// I.e. it could contain environments that have not been discovered (due to the fact that its not a common/known location).
185
- await find ( connection , "/Users/user_name/temp" ) ;
166
+ await refresh ( connection , {
167
+ searchPaths : [
168
+ "/Users/user_name/temp" ,
169
+ "/Users/user_name/demo/.venv" ,
170
+ "/Users/user_name/demo/.venv/bin/python" ,
171
+ ] ,
172
+ } ) ;
186
173
// Search for environments in the specified python environment directory.
187
- await find ( connection , "/Users/user_name/demo/.venv" ) ;
188
- await find ( connection , "/Users/user_name/demo/.venv/bin" ) ;
174
+ await refresh ( connection , {
175
+ searchPaths : [ "/Users/user_name/demo/.venv/bin" , "/usr/local/bin/python3" ] ,
176
+ } ) ;
177
+ // Search for environments of a particular kind.
178
+ await refresh ( connection , { searchKind : "Conda" } ) ;
189
179
190
180
// Possible this env was discovered, and the version or prefix information is not known.
191
181
await resolve ( connection , "/usr/local/bin/python3" ) ;
0 commit comments