Fixed sketch service

This commit is contained in:
jbicker 2019-07-23 13:42:52 +02:00
parent cd8c138e1e
commit 75f7d3ca7c
3 changed files with 43 additions and 32 deletions

View File

@ -359,7 +359,7 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
if (fileStat) {
const sketchFiles = await this.sketches.getSketchFiles(fileStat);
sketchFiles.forEach(sketchFile => {
const uri = new URI(sketchFile);
const uri = new URI(sketchFile.uri);
this.editorManager.open(uri);
});
}

View File

@ -4,7 +4,7 @@ export const SketchesServicePath = '/services/sketches-service';
export const SketchesService = Symbol('SketchesService');
export interface SketchesService {
getSketches(fileStat?: FileStat): Promise<Sketch[]>
getSketchFiles(fileStat: FileStat): Promise<string[]>
getSketchFiles(fileStat: FileStat): Promise<FileStat[]>
}
export interface Sketch {

View File

@ -17,17 +17,19 @@ export class SketchesServiceImpl implements SketchesService {
const sketches: Sketch[] = [];
if (fileStat && fileStat.isDirectory) {
const uri = new URI(fileStat.uri);
const sketchFolderPath = uri.path.toString()
const files = fs.readdirSync(sketchFolderPath);
files.forEach(file => {
const filePath = path.join(sketchFolderPath, file);
if (this.isSketchFolder(filePath, file)) {
sketches.push({
name: file,
uri: filePath
});
}
});
const sketchFolderPath = await this.filesystem.getFsPath(uri.toString());
if (sketchFolderPath) {
const files = fs.readdirSync(sketchFolderPath);
files.forEach(file => {
const filePath = path.join(sketchFolderPath, file);
if (this.isSketchFolder(filePath, file)) {
sketches.push({
name: file,
uri: filePath
});
}
});
}
}
return sketches;
}
@ -36,30 +38,39 @@ export class SketchesServiceImpl implements SketchesService {
* Return all allowed files.
* File extensions: "c", "cpp", "h", "hh", "hpp", "s", "pde", "ino"
*/
async getSketchFiles(sketchFileStat: FileStat): Promise<string[]> {
const files: string[] = [];
async getSketchFiles(sketchFileStat: FileStat): Promise<FileStat[]> {
const files: FileStat[] = [];
const sketchUri = new URI(sketchFileStat.uri);
const sketchPath = sketchUri.path.toString();
if (sketchFileStat.isDirectory && this.isSketchFolder(sketchPath, sketchUri.displayName)) {
const sketchDirContents = fs.readdirSync(sketchPath);
sketchDirContents.forEach(fileName => {
const filePath = path.join(sketchPath, fileName);
if (fs.existsSync(filePath) &&
fs.lstatSync(filePath).isFile() &&
ALLOWED_FILE_EXTENSIONS.indexOf(path.extname(filePath)) !== -1) {
files.push(filePath);
const sketchPath = await this.filesystem.getFsPath(sketchUri.toString());
if (sketchPath) {
if (sketchFileStat.isDirectory && this.isSketchFolder(sketchPath, sketchUri.displayName)) {
const sketchDirContents = fs.readdirSync(sketchPath);
for (const i in sketchDirContents) {
const fileName = sketchDirContents[i];
const filePath = path.join(sketchPath, fileName);
if (fs.existsSync(filePath) &&
fs.lstatSync(filePath).isFile() &&
ALLOWED_FILE_EXTENSIONS.indexOf(path.extname(filePath)) !== -1) {
const fileStat = await this.filesystem.getFileStat(filePath);
if (fileStat) {
console.log("111111111111", fileStat);
files.push(fileStat);
console.log("222222222222222", files);
}
}
}
});
} else {
const sketchDir = sketchUri.path.dir;
if (this.isSketchFolder(sketchDir.toString(), sketchDir.name)) {
const sketchFolderStat = await this.filesystem.getFileStat(sketchDir.toString());
if (sketchFolderStat) {
const sketchDirContents = await this.getSketchFiles(sketchFolderStat);
files.push(...sketchDirContents);
} else {
const sketchDir = path.dirname(sketchPath);
if (sketchDir && this.isSketchFolder(sketchDir, sketchUri.path.dir.name)) {
const sketchFolderStat = await this.filesystem.getFileStat(sketchUri.path.dir.toString());
if (sketchFolderStat) {
const sketchDirContents = await this.getSketchFiles(sketchFolderStat);
files.push(...sketchDirContents);
}
}
}
}
console.log("###FILEPATH###", files);
return files;
}