Skip to content

Commit 80f9e17

Browse files
committed
optimize project load
1 parent 684b182 commit 80f9e17

3 files changed

Lines changed: 40 additions & 17 deletions

File tree

src/EIDEProject.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,8 @@ class SourceRootList implements SourceProvider {
371371
// val: SourceRootInfo
372372
private srcFolderMaps: Map<string, SourceRootInfo>;
373373

374-
private isAutoSearchIncPath: boolean;
375-
private isAutoSearchObjFile: boolean;
374+
private isAutoSearchIncPath: boolean = false;
375+
private isAutoSearchObjFile: boolean = false;
376376

377377
on(event: 'dataChanged', listener: (event: SourceChangedEvent) => void): void;
378378
on(event: any, listener: (arg: any) => void): void {
@@ -383,8 +383,6 @@ class SourceRootList implements SourceProvider {
383383
this.project = _project;
384384
this._event = new events.EventEmitter();
385385
this.srcFolderMaps = new Map();
386-
this.isAutoSearchIncPath = SettingManager.GetInstance().isAutoSearchIncludePath();
387-
this.isAutoSearchObjFile = SettingManager.GetInstance().isAutoSearchObjFile();
388386
}
389387

390388
isAutoSearchObjectFile(): boolean {
@@ -393,6 +391,9 @@ class SourceRootList implements SourceProvider {
393391

394392
load(notEmitEvt?: boolean) {
395393

394+
this.isAutoSearchIncPath = SettingManager.GetInstance().isAutoSearchIncludePath();
395+
this.isAutoSearchObjFile = SettingManager.GetInstance().isAutoSearchObjFile();
396+
396397
this.DisposeAll();
397398

398399
// load source folders from filesystem
@@ -961,6 +962,20 @@ export abstract class AbstractProject implements CustomConfigurationProvider, Pr
961962
envFile.Write(cont.join(os.EOL));
962963
}
963964
}
965+
966+
// add some compatiable settings for old project
967+
{
968+
const workspaceConfig = this.GetWorkspaceConfig();
969+
const settings = workspaceConfig.config.settings;
970+
971+
// auto search includePath and libPath for old ver project
972+
if (this.oldProjectVersion &&
973+
compareVersion('3.3', this.oldProjectVersion) > 0) { // old ver < 3.3
974+
settings['EIDE.SourceTree.AutoSearchIncludePath'] = true;
975+
settings['EIDE.SourceTree.AutoSearchObjFile'] = true;
976+
workspaceConfig.Save(true); // save it now
977+
}
978+
}
964979
}
965980
}
966981

@@ -1826,6 +1841,7 @@ export abstract class AbstractProject implements CustomConfigurationProvider, Pr
18261841

18271842
protected isNewProject?: boolean | undefined;
18281843
protected isOldVersionProject?: boolean | undefined;
1844+
protected oldProjectVersion?: string | undefined;
18291845

18301846
protected async BeforeLoad(wsFile: File): Promise<void> {
18311847

@@ -1842,6 +1858,7 @@ export abstract class AbstractProject implements CustomConfigurationProvider, Pr
18421858
conf.version = EIDE_CONF_VERSION;
18431859
eideFile.Write(JSON.stringify(conf));
18441860
this.isOldVersionProject = true;
1861+
this.oldProjectVersion = prj_version;
18451862
}
18461863
}
18471864

@@ -2492,14 +2509,14 @@ class EIDEProject extends AbstractProject {
24922509
// register cfg watcher
24932510
this.onSrcExtraOptionsChanged('changed'); // notify cpptools update now
24942511

2495-
// update workspace settings
2512+
// init settings for new project
24962513
if (this.isNewProject) {
24972514

24982515
const workspaceConfig = this.GetWorkspaceConfig();
24992516
const settings = workspaceConfig.config.settings;
25002517

25012518
// --- eide settings
2502-
2519+
// TODO
25032520

25042521
// --- vscode settings
25052522

src/EIDETypeDefine.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,16 @@ export abstract class Configuration<ConfigType = any, EventType = any> {
137137
private _eventCache: EventItem[];
138138
protected _event: events.EventEmitter;
139139

140-
protected eideJsonFile: File;
140+
protected cfgFile: File;
141141
protected watcher: FileWatcher;
142142

143+
protected isDelUnknownKeysWhenLoad: boolean = true;
144+
143145
constructor(configFile: File, type?: ProjectType) {
144146
this._event = new events.EventEmitter();
145147
this._eventMergeFlag = false;
146148
this._eventCache = [];
147-
this.eideJsonFile = configFile;
149+
this.cfgFile = configFile;
148150
this.FILE_NAME = configFile.name;
149151
this.watcher = new FileWatcher(configFile, false);
150152
this.watcher.on('error', (err) => GlobalEvent.emit('error', err));
@@ -154,8 +156,8 @@ export abstract class Configuration<ConfigType = any, EventType = any> {
154156

155157
public load(): Configuration<ConfigType, EventType> {
156158

157-
if (this.eideJsonFile.IsFile()) {
158-
this.InitConfig(this.eideJsonFile.Read());
159+
if (this.cfgFile.IsFile()) {
160+
this.InitConfig(this.cfgFile.Read());
159161
} else {
160162
this.Save(true);
161163
}
@@ -168,7 +170,7 @@ export abstract class Configuration<ConfigType = any, EventType = any> {
168170
}
169171

170172
GetFile(): File {
171-
return this.eideJsonFile;
173+
return this.cfgFile;
172174
}
173175

174176
Watch() {
@@ -221,9 +223,11 @@ export abstract class Configuration<ConfigType = any, EventType = any> {
221223
const _configFromFile: any = (typeof json === 'string') ? this.Parse(json) : json;
222224

223225
// clear invalid property
224-
for (const key in (<any>_configFromFile)) {
225-
if ((<any>this.config)[key] === undefined) {
226-
_configFromFile[key] = undefined;
226+
if (this.isDelUnknownKeysWhenLoad) {
227+
for (const key in (<any>_configFromFile)) {
228+
if ((<any>this.config)[key] === undefined) {
229+
_configFromFile[key] = undefined;
230+
}
227231
}
228232
}
229233

@@ -237,7 +241,7 @@ export abstract class Configuration<ConfigType = any, EventType = any> {
237241
}
238242

239243
Save(force?: boolean): void {
240-
this.eideJsonFile.Write(this.ToJson());
244+
this.cfgFile.Write(this.ToJson());
241245
}
242246

243247
protected afterInitConfigData() {
@@ -399,7 +403,7 @@ export class ProjectConfiguration<T extends BuilderConfigData>
399403

400404
super(eideJsonFile, type);
401405

402-
this.rootDir = new File(NodePath.dirname(this.eideJsonFile.dir));
406+
this.rootDir = new File(NodePath.dirname(this.cfgFile.dir));
403407

404408
this.project = {
405409
getRootDir: () => this.rootDir,
@@ -1352,6 +1356,8 @@ export interface WorkspaceConfig {
13521356

13531357
export class WorkspaceConfiguration extends Configuration<WorkspaceConfig> {
13541358

1359+
isDelUnknownKeysWhenLoad = false;
1360+
13551361
protected readTypeFromFile(configFile: File): ProjectType | undefined {
13561362
return undefined;
13571363
}

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ async function checkAndInstallBinaries(forceInstall?: boolean): Promise<boolean>
437437
// try fetch update after 5sec delay
438438
if (localVersion) {
439439
setTimeout(async (curLocalVersion: string) => {
440-
const done = await tryUpdateBinaries(binFolder, curLocalVersion);
440+
const done = await tryUpdateBinaries(binFolder, curLocalVersion, true); // no prompt
441441
if (!done) {
442442
const msg = `Update eide-binaries failed, please restart vscode to try again !`;
443443
const sel = await vscode.window.showErrorMessage(msg, 'Restart', 'Cancel');

0 commit comments

Comments
 (0)