mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-10 12:56:32 +00:00
Fixed sketch service
This commit is contained in:
parent
cd8c138e1e
commit
75f7d3ca7c
@ -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);
|
||||
});
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -17,7 +17,8 @@ export class SketchesServiceImpl implements SketchesService {
|
||||
const sketches: Sketch[] = [];
|
||||
if (fileStat && fileStat.isDirectory) {
|
||||
const uri = new URI(fileStat.uri);
|
||||
const sketchFolderPath = uri.path.toString()
|
||||
const sketchFolderPath = await this.filesystem.getFsPath(uri.toString());
|
||||
if (sketchFolderPath) {
|
||||
const files = fs.readdirSync(sketchFolderPath);
|
||||
files.forEach(file => {
|
||||
const filePath = path.join(sketchFolderPath, file);
|
||||
@ -29,6 +30,7 @@ export class SketchesServiceImpl implements SketchesService {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
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();
|
||||
const sketchPath = await this.filesystem.getFsPath(sketchUri.toString());
|
||||
if (sketchPath) {
|
||||
if (sketchFileStat.isDirectory && this.isSketchFolder(sketchPath, sketchUri.displayName)) {
|
||||
const sketchDirContents = fs.readdirSync(sketchPath);
|
||||
sketchDirContents.forEach(fileName => {
|
||||
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) {
|
||||
files.push(filePath);
|
||||
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());
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user