Skip to content

Commit d510516

Browse files
committed
Fix an issue when selected working environment was ignored when rebuilding project index
1 parent bae66c1 commit d510516

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

src/project/indexer.js

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,18 @@ export default class ProjectIndexer {
3131
this.subscriptions = [];
3232
this.dirWatchSubscriptions = [];
3333

34+
this._activeEnvName = undefined;
3435
this._rebuildTimeout = undefined;
3536
this._updateDirWatchersTimeout = undefined;
3637
this._inProgress = false;
3738

3839
this.setupWatchers();
3940
}
4041

42+
setActiveEnv(name) {
43+
this._activeEnvName = name;
44+
}
45+
4146
requestRebuild() {
4247
if (this._rebuildTimeout) {
4348
clearTimeout(this._rebuildTimeout);
@@ -48,31 +53,33 @@ export default class ProjectIndexer {
4853
);
4954
}
5055

51-
rebuild(envName) {
56+
rebuild() {
5257
if (this._inProgress || !ProjectIndexer.isPIOProjectSync(this.projectDir)) {
5358
return;
5459
}
5560
return this.options.withProgress(async () => {
5661
this._inProgress = true;
5762
try {
5863
await new Promise((resolve, reject) => {
59-
const args = [
60-
'init',
61-
'--ide',
62-
this.options.ide,
63-
'--project-dir',
64-
this.projectDir,
65-
];
66-
if (envName) {
67-
args.push('--environment', envName);
64+
const args = ['init', '--ide', this.options.ide];
65+
if (this._activeEnvName) {
66+
args.push('--environment', this._activeEnvName);
6867
}
69-
runPIOCommand(args, (code, stdout, stderr) => {
70-
if (code === 0) {
71-
resolve();
72-
} else {
73-
reject(new Error(stderr));
68+
runPIOCommand(
69+
args,
70+
(code, stdout, stderr) => {
71+
if (code === 0) {
72+
resolve();
73+
} else {
74+
reject(new Error(stderr));
75+
}
76+
},
77+
{
78+
spawnOptions: {
79+
cwd: this.projectDir,
80+
},
7481
}
75-
});
82+
);
7683
});
7784
} catch (err) {
7885
console.warn(err);
@@ -132,13 +139,13 @@ export default class ProjectIndexer {
132139

133140
async fetchWatchDirs() {
134141
const scriptLines = [
135-
'import os',
142+
'import json, os',
136143
'from platformio.project.config import ProjectConfig',
137144
'c = ProjectConfig()',
138145
'libdeps_dir = c.get_optional_dir("libdeps")',
139146
'watch_dirs = [c.get_optional_dir("globallib"), c.get_optional_dir("lib"), libdeps_dir]',
140147
'watch_dirs.extend(os.path.join(libdeps_dir, d) for d in (os.listdir(libdeps_dir) if os.path.isdir(libdeps_dir) else []) if os.path.isdir(os.path.join(libdeps_dir, d)))',
141-
'print(":".join(watch_dirs))',
148+
'print(json.dumps(watch_dirs))',
142149
];
143150
const output = await proc.getCommandOutput(
144151
await core.getCorePythonExe(),
@@ -149,7 +156,7 @@ export default class ProjectIndexer {
149156
},
150157
}
151158
);
152-
return output.trim().split(':');
159+
return JSON.parse(output.trim());
153160
}
154161

155162
dispose() {

0 commit comments

Comments
 (0)