Skip to content

Commit c0e279f

Browse files
author
Akos Kitta
committed
[win] Open sketch.
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
1 parent 75f7d3c commit c0e279f

File tree

3 files changed

+23
-30
lines changed

3 files changed

+23
-30
lines changed

arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,10 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
357357
async openSketchFiles(uri: string) {
358358
const fileStat = await this.fileSystem.getFileStat(uri);
359359
if (fileStat) {
360-
const sketchFiles = await this.sketches.getSketchFiles(fileStat);
361-
sketchFiles.forEach(sketchFile => {
362-
const uri = new URI(sketchFile.uri);
363-
this.editorManager.open(uri);
364-
});
360+
const uris = await this.sketches.getSketchFiles(fileStat);
361+
for (const uri of uris) {
362+
this.editorManager.open(new URI(uri));
363+
}
365364
}
366365
}
367366

arduino-ide-extension/src/common/protocol/sketches-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const SketchesServicePath = '/services/sketches-service';
44
export const SketchesService = Symbol('SketchesService');
55
export interface SketchesService {
66
getSketches(fileStat?: FileStat): Promise<Sketch[]>
7-
getSketchFiles(fileStat: FileStat): Promise<FileStat[]>
7+
getSketchFiles(fileStat: FileStat): Promise<string[]>
88
}
99

1010
export interface Sketch {

arduino-ide-extension/src/node/sketches-service-impl.ts

+18-24
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import URI from "@theia/core/lib/common/uri";
44
import { FileStat, FileSystem } from "@theia/filesystem/lib/common";
55
import * as fs from 'fs';
66
import * as path from 'path';
7+
import { FileUri } from "@theia/core/lib/node";
78

89
export const ALLOWED_FILE_EXTENSIONS = [".c", ".cpp", ".h", ".hh", ".hpp", ".s", ".pde", ".ino"];
910

@@ -19,16 +20,16 @@ export class SketchesServiceImpl implements SketchesService {
1920
const uri = new URI(fileStat.uri);
2021
const sketchFolderPath = await this.filesystem.getFsPath(uri.toString());
2122
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)) {
2627
sketches.push({
27-
name: file,
28-
uri: filePath
28+
name: fileName,
29+
uri: FileUri.create(filePath).toString()
2930
});
3031
}
31-
});
32+
}
3233
}
3334
}
3435
return sketches;
@@ -38,25 +39,19 @@ export class SketchesServiceImpl implements SketchesService {
3839
* Return all allowed files.
3940
* File extensions: "c", "cpp", "h", "hh", "hpp", "s", "pde", "ino"
4041
*/
41-
async getSketchFiles(sketchFileStat: FileStat): Promise<FileStat[]> {
42-
const files: FileStat[] = [];
42+
async getSketchFiles(sketchFileStat: FileStat): Promise<string[]> {
43+
const uris: string[] = [];
4344
const sketchUri = new URI(sketchFileStat.uri);
4445
const sketchPath = await this.filesystem.getFsPath(sketchUri.toString());
4546
if (sketchPath) {
4647
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) {
5050
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())
6055
}
6156
}
6257
} else {
@@ -65,13 +60,12 @@ export class SketchesServiceImpl implements SketchesService {
6560
const sketchFolderStat = await this.filesystem.getFileStat(sketchUri.path.dir.toString());
6661
if (sketchFolderStat) {
6762
const sketchDirContents = await this.getSketchFiles(sketchFolderStat);
68-
files.push(...sketchDirContents);
63+
uris.push(...sketchDirContents);
6964
}
7065
}
7166
}
7267
}
73-
console.log("###FILEPATH###", files);
74-
return files;
68+
return uris;
7569
}
7670

7771
protected isSketchFolder(path: string, name: string): boolean {

0 commit comments

Comments
 (0)