@@ -104,13 +104,14 @@ async function configure(connection) {
104104 * Refresh the environment
105105 *
106106 * @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.
108109 */
109- async function refresh ( connection , searchScope ) {
110+ async function refresh ( connection , search ) {
110111 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 ) } )`
114115 : "(in machine scope)" ;
115116 console . log (
116117 `Found ${ environments . length } environments in ${ duration } ms ${ scope } `
@@ -122,7 +123,7 @@ async function refresh(connection, searchScope) {
122123 *
123124 * @param {import("vscode-jsonrpc").MessageConnection } connection
124125 */
125- async function clear ( connection , searchScope ) {
126+ async function clear ( connection ) {
126127 await connection . sendRequest ( "clear" ) ;
127128}
128129
@@ -151,41 +152,30 @@ async function resolve(connection, executable) {
151152 }
152153}
153154
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-
172155async function main ( ) {
173156 const connection = await start ( ) ;
174157
175158 // First request to the server, to configure the server.
176159 await configure ( connection ) ;
177160
178161 await refresh ( connection ) ;
179- // Search for environments in the defined workspace folders.
180- await refresh ( connection , "workspace" ) ;
181162
182163 // Search for environments in the specified folders.
183164 // This could be a folder thats not part of the workspace and not in any known location
184165 // 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+ } ) ;
186173 // 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" } ) ;
189179
190180 // Possible this env was discovered, and the version or prefix information is not known.
191181 await resolve ( connection , "/usr/local/bin/python3" ) ;
0 commit comments