Skip to content

Commit d5b3c7d

Browse files
author
Akos Kitta
committed
fix: use sketch file path instead of folder
let the frontend's workspace service handle the error Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent 18dc12a commit d5b3c7d

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

arduino-ide-extension/src/browser/contributions/open-sketch-files.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ export class OpenSketchFiles extends SketchContribution {
7373
}
7474
} catch (err) {
7575
// This happens when the user gracefully closed IDE2, all went well
76-
// but the main sketch file or the sketch folder was modified and when user restarts the IDE2
77-
// the sketch path is not valid anymore. (#964)
76+
// but the main sketch file or was modified outside of IDE2 and user restarts the IDE2
77+
// the workspace path still exists, but the sketch path is not valid anymore. (#964)
7878
if (SketchesError.InvalidName.is(err)) {
7979
const movedSketch = await this.promptMove(err);
8080
if (!movedSketch) {

arduino-ide-extension/src/electron-main/theia/electron-main-application.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from '@theia/core/electron-shared/electron';
99
import { fork } from 'child_process';
1010
import { AddressInfo } from 'net';
11-
import { join, dirname, isAbsolute, resolve } from 'path';
11+
import { join, isAbsolute, resolve } from 'path';
1212
import { promises as fs, Stats } from 'fs';
1313
import { MaybePromise } from '@theia/core/lib/common/types';
1414
import { ElectronSecurityToken } from '@theia/core/lib/electron-common/electron-token';
@@ -86,7 +86,7 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
8686
return this.launch({
8787
secondInstance: false,
8888
argv: this.processArgv.getProcessArgvWithoutBin(process.argv),
89-
cwd
89+
cwd,
9090
});
9191
}
9292

@@ -158,11 +158,11 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
158158
/**
159159
* The `path` argument is valid, if accessible and either pointing to a `.ino` file,
160160
* or it's a directory, and one of the files in the directory is an `.ino` file.
161-
* The resolved filesystem path is pointing to the sketch folder to open in IDE2.
161+
*
162162
* If `undefined`, `path` was pointing to neither an accessible sketch file nor a sketch folder.
163163
*
164-
* The sketch folder name and sketch file name can be different. This method is not that strict.
165-
* The `path` must be an absolute path.
164+
* The sketch folder name and sketch file name can be different. This method is not sketch folder name compliant.
165+
* The `path` must be an absolute, resolved path.
166166
*/
167167
private async isValidSketchPath(path: string): Promise<string | undefined> {
168168
let stats: Stats | undefined = undefined;
@@ -178,14 +178,16 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
178178
return undefined;
179179
}
180180
if (stats.isFile() && path.endsWith('.ino')) {
181-
return dirname(path);
181+
return path;
182182
}
183183
try {
184184
const entries = await fs.readdir(path, { withFileTypes: true });
185-
if (
186-
entries.some((entry) => entry.isFile() && entry.name.endsWith('.ino'))
187-
) {
188-
return path;
185+
const sketchFilename = entries
186+
.filter((entry) => entry.isFile() && entry.name.endsWith('.ino'))
187+
.map(({ name }) => name)
188+
.sort((left, right) => left.localeCompare(right))[0];
189+
if (sketchFilename) {
190+
return join(path, sketchFilename);
189191
}
190192
} catch (err) {
191193
throw err;

0 commit comments

Comments
 (0)