@@ -44,17 +44,23 @@ function discoverSketchesInFolder(folder: WorkspaceFolder): string[] {
4444 const sketchPaths : string [ ] = [ ] ;
4545 if ( folder . uri . scheme === 'file' ) {
4646 const folderPath = folder . uri . fsPath ;
47- const candidateSketchFilePaths = globbySync ( [ '**/*.{ino,pde}' , '!hardware/**' , '!libraries/**' ] , { cwd : folderPath } ) ;
47+ const candidateSketchFilePaths = globbySync ( [ '**/*.{ino,pde}' , '!hardware/**' , '!libraries/**' ] , { cwd : folderPath , absolute : true } ) ;
4848 // filter out nested sketches
4949 candidateSketchFilePaths . sort ( ( left , right ) => left . length - right . length ) ;
5050 console . log ( 'workspace folder URI: ' + folder . uri . toString ( ) , JSON . stringify ( candidateSketchFilePaths ) ) ;
51- for ( const candidateSketchFilePath of candidateSketchFilePaths ) {
52- const relative = path . relative ( folderPath , candidateSketchFilePath ) ;
51+ for ( const sketchFilePath of candidateSketchFilePaths ) {
52+ const relative = path . relative ( folderPath , sketchFilePath ) ;
5353 if ( ! relative ) {
5454 continue ;
5555 }
5656 const segments = relative . split ( path . sep ) ;
5757 if ( segments . length < 2 ) {
58+ if ( path . dirname ( sketchFilePath ) === folderPath && ( path . basename ( folderPath ) + '.ino' === path . basename ( sketchFilePath ) || path . basename ( folderPath ) + '.pde' === path . basename ( sketchFilePath ) ) ) {
59+ const sketchPath = path . join ( sketchFilePath , '..' ) ;
60+ if ( ! sketchPaths . includes ( sketchPath ) && sketchPaths . every ( otherSketchPath => ! sketchFilePath . startsWith ( otherSketchPath ) ) ) {
61+ sketchPaths . push ( sketchPath ) ;
62+ }
63+ } ;
5864 continue ;
5965 }
6066 const sketchName = segments [ segments . length - 2 ] ;
@@ -65,8 +71,8 @@ function discoverSketchesInFolder(folder: WorkspaceFolder): string[] {
6571 if ( sketchFileExtension !== '.ino' && sketchFileExtension !== '.pde' ) {
6672 continue ;
6773 }
68- const sketchPath = path . join ( folderPath , ... segments , '..' ) ;
69- if ( ! sketchPaths . includes ( sketchPath ) && sketchPaths . every ( otherSketchPath => ! sketchPath . startsWith ( otherSketchPath ) ) ) {
74+ const sketchPath = path . join ( sketchFilePath , '..' ) ;
75+ if ( ! sketchPaths . includes ( sketchPath ) && sketchPaths . every ( otherSketchPath => ! sketchFilePath . startsWith ( otherSketchPath ) ) ) {
7076 sketchPaths . push ( sketchPath ) ;
7177 }
7278 }
@@ -244,8 +250,16 @@ export function activate(context: ExtensionContext) {
244250 if ( ! sketch ) {
245251 return ;
246252 }
247- if ( ! getOrCreateContext ( sketch ) ) {
248- vscode . window . showErrorMessage ( `Could not location sketch under ${ sketch } ` ) ;
253+ if ( ! sketchContexts . has ( sketch ) ) {
254+ const sketches = sortedSketches ( ) ;
255+ if ( ! sketches . includes ( sketch ) ) {
256+ vscode . window . showErrorMessage ( `Could not location sketch under ${ sketch } ` ) ;
257+ } else {
258+ sketchContexts . set ( sketch , {
259+ crashCount : 0 ,
260+ mutex : new Mutex ( )
261+ } ) ;
262+ }
249263 }
250264 }
251265 context . subscriptions . push (
@@ -340,6 +354,7 @@ export function activate(context: ExtensionContext) {
340354 }
341355 } ) ,
342356 ) ;
357+ sortedSketches ( ) ;
343358 vscode . workspace . textDocuments . forEach ( didOpenTextDocument ) ;
344359 useIde2Path ( ) ;
345360}
0 commit comments