@@ -4,6 +4,7 @@ import URI from "@theia/core/lib/common/uri";
4
4
import { FileStat , FileSystem } from "@theia/filesystem/lib/common" ;
5
5
import * as fs from 'fs' ;
6
6
import * as path from 'path' ;
7
+ import { FileUri } from "@theia/core/lib/node" ;
7
8
8
9
export const ALLOWED_FILE_EXTENSIONS = [ ".c" , ".cpp" , ".h" , ".hh" , ".hpp" , ".s" , ".pde" , ".ino" ] ;
9
10
@@ -19,16 +20,16 @@ export class SketchesServiceImpl implements SketchesService {
19
20
const uri = new URI ( fileStat . uri ) ;
20
21
const sketchFolderPath = await this . filesystem . getFsPath ( uri . toString ( ) ) ;
21
22
if ( sketchFolderPath ) {
22
- const files = fs . readdirSync ( sketchFolderPath ) ;
23
- files . forEach ( file => {
24
- const filePath = path . join ( sketchFolderPath , file ) ;
25
- if ( this . isSketchFolder ( filePath , file ) ) {
23
+ const fileNames = fs . readdirSync ( sketchFolderPath ) ;
24
+ for ( const fileName of fileNames ) {
25
+ const filePath = path . join ( sketchFolderPath , fileName ) ;
26
+ if ( this . isSketchFolder ( filePath , fileName ) ) {
26
27
sketches . push ( {
27
- name : file ,
28
- uri : filePath
28
+ name : fileName ,
29
+ uri : FileUri . create ( filePath ) . toString ( )
29
30
} ) ;
30
31
}
31
- } ) ;
32
+ }
32
33
}
33
34
}
34
35
return sketches ;
@@ -38,25 +39,19 @@ export class SketchesServiceImpl implements SketchesService {
38
39
* Return all allowed files.
39
40
* File extensions: "c", "cpp", "h", "hh", "hpp", "s", "pde", "ino"
40
41
*/
41
- async getSketchFiles ( sketchFileStat : FileStat ) : Promise < FileStat [ ] > {
42
- const files : FileStat [ ] = [ ] ;
42
+ async getSketchFiles ( sketchFileStat : FileStat ) : Promise < string [ ] > {
43
+ const uris : string [ ] = [ ] ;
43
44
const sketchUri = new URI ( sketchFileStat . uri ) ;
44
45
const sketchPath = await this . filesystem . getFsPath ( sketchUri . toString ( ) ) ;
45
46
if ( sketchPath ) {
46
47
if ( sketchFileStat . isDirectory && this . isSketchFolder ( sketchPath , sketchUri . displayName ) ) {
47
- const sketchDirContents = fs . readdirSync ( sketchPath ) ;
48
- for ( const i in sketchDirContents ) {
49
- const fileName = sketchDirContents [ i ] ;
48
+ const fileNames = fs . readdirSync ( sketchPath ) ;
49
+ for ( const fileName of fileNames ) {
50
50
const filePath = path . join ( sketchPath , fileName ) ;
51
- if ( fs . existsSync ( filePath ) &&
52
- fs . lstatSync ( filePath ) . isFile ( ) &&
53
- ALLOWED_FILE_EXTENSIONS . indexOf ( path . extname ( filePath ) ) !== - 1 ) {
54
- const fileStat = await this . filesystem . getFileStat ( filePath ) ;
55
- if ( fileStat ) {
56
- console . log ( "111111111111" , fileStat ) ;
57
- files . push ( fileStat ) ;
58
- console . log ( "222222222222222" , files ) ;
59
- }
51
+ if ( ALLOWED_FILE_EXTENSIONS . indexOf ( path . extname ( filePath ) ) !== - 1
52
+ && fs . existsSync ( filePath )
53
+ && fs . lstatSync ( filePath ) . isFile ( ) ) {
54
+ uris . push ( FileUri . create ( filePath ) . toString ( ) )
60
55
}
61
56
}
62
57
} else {
@@ -65,13 +60,12 @@ export class SketchesServiceImpl implements SketchesService {
65
60
const sketchFolderStat = await this . filesystem . getFileStat ( sketchUri . path . dir . toString ( ) ) ;
66
61
if ( sketchFolderStat ) {
67
62
const sketchDirContents = await this . getSketchFiles ( sketchFolderStat ) ;
68
- files . push ( ...sketchDirContents ) ;
63
+ uris . push ( ...sketchDirContents ) ;
69
64
}
70
65
}
71
66
}
72
67
}
73
- console . log ( "###FILEPATH###" , files ) ;
74
- return files ;
68
+ return uris ;
75
69
}
76
70
77
71
protected isSketchFolder ( path : string , name : string ) : boolean {
0 commit comments