Skip to content

Commit 4224294

Browse files
committed
Improve handling of "platformio.ini" changes
1 parent 47658df commit 4224294

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

src/project/observer.js

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export default class ProjectObserver {
2929
this._indexer = undefined;
3030
this._projectTasks = new ProjectTasks(this.projectDir, this.options.ide);
3131
this._updateDirWatchersTimeout = undefined;
32-
this._previousSelectedEnv = Object.create(null);
3332
this._selectedEnv = undefined;
3433
this._apiConfigChangedTimeout = undefined;
3534

@@ -52,6 +51,7 @@ export default class ProjectObserver {
5251

5352
activate() {
5453
console.info('Activating project', this.projectDir);
54+
this.requestRebuild();
5555
}
5656

5757
deactivate() {
@@ -84,16 +84,12 @@ export default class ProjectObserver {
8484
return delayed ? this._indexer.requestRebuild() : this._indexer.rebuild();
8585
}
8686

87-
async switchProjectEnv(name, { delayedRebuildIndex = false } = {}) {
87+
async switchProjectEnv(name) {
8888
const validNames = (await this.getConfig()).envs();
8989
if (!validNames.includes(name)) {
9090
name = undefined;
9191
}
9292
this._selectedEnv = name;
93-
if (this._previousSelectedEnv !== this._selectedEnv || delayedRebuildIndex) {
94-
this._previousSelectedEnv = this._selectedEnv;
95-
this.rebuildIndex({ delayed: delayedRebuildIndex });
96-
}
9793
}
9894

9995
getSelectedEnv() {
@@ -147,17 +143,10 @@ export default class ProjectObserver {
147143
this._config = undefined;
148144
// reset to `undefined` if env was removed from conf
149145
this.resetCache();
150-
// rebuildIndex
151-
this.switchProjectEnv(this._selectedEnv, { delayedRebuildIndex: true });
152146
this.requestUpdateDirWatchers();
153147
if ((this.options.api || {}).onDidChangeProjectConfig) {
154-
if (this._apiConfigChangedTimeout) {
155-
clearTimeout(this._apiConfigChangedTimeout);
156-
this._apiConfigChangedTimeout = undefined;
157-
}
158-
this._apiConfigChangedTimeout = setTimeout(
159-
() => this.options.api.onDidChangeProjectConfig(this.projectDir),
160-
(ProjectIndexer.AUTO_REBUILD_DELAY + 1) * 1000
148+
this.options.api.onDidChangeProjectConfig(
149+
path.join(this.projectDir, 'platformio.ini')
161150
);
162151
}
163152
}

0 commit comments

Comments
 (0)