mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-10 21:06:33 +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) {
|
if (fileStat) {
|
||||||
const sketchFiles = await this.sketches.getSketchFiles(fileStat);
|
const sketchFiles = await this.sketches.getSketchFiles(fileStat);
|
||||||
sketchFiles.forEach(sketchFile => {
|
sketchFiles.forEach(sketchFile => {
|
||||||
const uri = new URI(sketchFile);
|
const uri = new URI(sketchFile.uri);
|
||||||
this.editorManager.open(uri);
|
this.editorManager.open(uri);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ export const SketchesServicePath = '/services/sketches-service';
|
|||||||
export const SketchesService = Symbol('SketchesService');
|
export const SketchesService = Symbol('SketchesService');
|
||||||
export interface SketchesService {
|
export interface SketchesService {
|
||||||
getSketches(fileStat?: FileStat): Promise<Sketch[]>
|
getSketches(fileStat?: FileStat): Promise<Sketch[]>
|
||||||
getSketchFiles(fileStat: FileStat): Promise<string[]>
|
getSketchFiles(fileStat: FileStat): Promise<FileStat[]>
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Sketch {
|
export interface Sketch {
|
||||||
|
@ -17,7 +17,8 @@ export class SketchesServiceImpl implements SketchesService {
|
|||||||
const sketches: Sketch[] = [];
|
const sketches: Sketch[] = [];
|
||||||
if (fileStat && fileStat.isDirectory) {
|
if (fileStat && fileStat.isDirectory) {
|
||||||
const uri = new URI(fileStat.uri);
|
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);
|
const files = fs.readdirSync(sketchFolderPath);
|
||||||
files.forEach(file => {
|
files.forEach(file => {
|
||||||
const filePath = path.join(sketchFolderPath, file);
|
const filePath = path.join(sketchFolderPath, file);
|
||||||
@ -29,6 +30,7 @@ export class SketchesServiceImpl implements SketchesService {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return sketches;
|
return sketches;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,30 +38,39 @@ export class SketchesServiceImpl implements SketchesService {
|
|||||||
* Return all allowed files.
|
* Return all allowed files.
|
||||||
* File extensions: "c", "cpp", "h", "hh", "hpp", "s", "pde", "ino"
|
* File extensions: "c", "cpp", "h", "hh", "hpp", "s", "pde", "ino"
|
||||||
*/
|
*/
|
||||||
async getSketchFiles(sketchFileStat: FileStat): Promise<string[]> {
|
async getSketchFiles(sketchFileStat: FileStat): Promise<FileStat[]> {
|
||||||
const files: string[] = [];
|
const files: FileStat[] = [];
|
||||||
const sketchUri = new URI(sketchFileStat.uri);
|
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)) {
|
if (sketchFileStat.isDirectory && this.isSketchFolder(sketchPath, sketchUri.displayName)) {
|
||||||
const sketchDirContents = fs.readdirSync(sketchPath);
|
const sketchDirContents = fs.readdirSync(sketchPath);
|
||||||
sketchDirContents.forEach(fileName => {
|
for (const i in sketchDirContents) {
|
||||||
|
const fileName = sketchDirContents[i];
|
||||||
const filePath = path.join(sketchPath, fileName);
|
const filePath = path.join(sketchPath, fileName);
|
||||||
if (fs.existsSync(filePath) &&
|
if (fs.existsSync(filePath) &&
|
||||||
fs.lstatSync(filePath).isFile() &&
|
fs.lstatSync(filePath).isFile() &&
|
||||||
ALLOWED_FILE_EXTENSIONS.indexOf(path.extname(filePath)) !== -1) {
|
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 {
|
} else {
|
||||||
const sketchDir = sketchUri.path.dir;
|
const sketchDir = path.dirname(sketchPath);
|
||||||
if (this.isSketchFolder(sketchDir.toString(), sketchDir.name)) {
|
if (sketchDir && this.isSketchFolder(sketchDir, sketchUri.path.dir.name)) {
|
||||||
const sketchFolderStat = await this.filesystem.getFileStat(sketchDir.toString());
|
const sketchFolderStat = await this.filesystem.getFileStat(sketchUri.path.dir.toString());
|
||||||
if (sketchFolderStat) {
|
if (sketchFolderStat) {
|
||||||
const sketchDirContents = await this.getSketchFiles(sketchFolderStat);
|
const sketchDirContents = await this.getSketchFiles(sketchFolderStat);
|
||||||
files.push(...sketchDirContents);
|
files.push(...sketchDirContents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
console.log("###FILEPATH###", files);
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user