File tree Expand file tree Collapse file tree 2 files changed +21
-12
lines changed
Expand file tree Collapse file tree 2 files changed +21
-12
lines changed Original file line number Diff line number Diff line change 66 * the root directory of this source tree.
77 */
88
9- import * as pioNodeHelpers from 'platformio-node-helpers' ;
10-
119import { IS_WINDOWS , STATUS_BAR_PRIORITY_START } from '../constants' ;
10+ import { disposeSubscriptions , listCoreSerialPorts } from '../utils' ;
1211import { getProjectItemState , updateProjectItemState } from './helpers' ;
1312import ProjectTasksTreeProvider from './task-tree' ;
14- import { disposeSubscriptions } from '../utils' ;
1513import { extension } from '../main' ;
1614import path from 'path' ;
1715import vscode from 'vscode' ;
@@ -275,21 +273,14 @@ export default class ProjectTaskManager {
275273 }
276274
277275 async pickProjectPort ( ) {
278- const script = `
279- import json
280- from platformio.public import list_serial_ports
281-
282- print(json.dumps(list_serial_ports()))
283- ` ;
284- const output = await pioNodeHelpers . core . getCorePythonCommandOutput ( [ '-c' , script ] ) ;
285- const serialPorts = JSON . parse ( output . trim ( ) ) ;
276+ const serialPorts = await listCoreSerialPorts ( ) ;
286277 const pickedItem = await vscode . window . showQuickPick (
287278 [
288279 { label : 'Auto' } ,
289280 ...serialPorts . map ( ( port ) => ( {
290281 label : port . port ,
291282 description : [ port . description , port . hwid ]
292- . filter ( ( value ) => value !== 'n/a' )
283+ . filter ( ( value ) => ! ! value )
293284 . join ( ' | ' ) ,
294285 } ) ) ,
295286 { label : 'Custom...' } ,
Original file line number Diff line number Diff line change @@ -60,3 +60,21 @@ export function getIDEManifest() {
6060export function getIDEVersion ( ) {
6161 return getIDEManifest ( ) . version ;
6262}
63+
64+ export async function listCoreSerialPorts ( ) {
65+ const script = `
66+ import json
67+ from platformio.public import list_serial_ports
68+
69+ print(json.dumps(list_serial_ports()))
70+ ` ;
71+ const output = await pioNodeHelpers . core . getCorePythonCommandOutput ( [ '-c' , script ] ) ;
72+ return JSON . parse ( output . trim ( ) ) . map ( ( item ) => {
73+ for ( const key of [ 'description' , 'hwid' ] ) {
74+ if ( item [ key ] === 'n/a' ) {
75+ item [ key ] = undefined ;
76+ }
77+ }
78+ return item ;
79+ } ) ;
80+ }
You can’t perform that action at this time.
0 commit comments