Skip to content

Commit

Permalink
Fix problems with updating the code model (#2985)
Browse files Browse the repository at this point in the history
  • Loading branch information
elahehrashedi authored Jan 30, 2023
1 parent 2a297fd commit defb0ad
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Bug Fixes:

## 1.13.44
Bug Fixes:
- Fix problems with updating the code model. [#2980](https://github.com/microsoft/vscode-cmake-tools/issues/2980)
- Validate presets in initialization. [#2976](https://github.com/microsoft/vscode-cmake-tools/issues/2976)

## 1.13.43
Expand Down
6 changes: 3 additions & 3 deletions src/drivers/cmakeFileApiDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ export class CMakeFileApiDriver extends CMakeDriver {
}

async doConfigure(args_: string[], outputConsumer?: proc.OutputConsumer, showCommandOnly?: boolean, configurePreset?: ConfigurePreset | null, options?: proc.ExecutionOptions): Promise<number> {
const api_path = this.getCMakeFileApiPath(configurePreset?.binaryDir);
const binaryDir = configurePreset?.binaryDir ?? this.binaryDir;
const api_path = this.getCMakeFileApiPath(binaryDir);
await createQueryFileForApi(api_path);

// Dup args so we can modify them
Expand All @@ -208,7 +209,6 @@ export class CMakeFileApiDriver extends CMakeDriver {
has_gen = true;
}
}
const binaryDir = configurePreset?.binaryDir ?? this.binaryDir;
// -S and -B were introduced in CMake 3.13 and this driver assumes CMake >= 3.15
args.push(`-S${util.lightNormalizePath(this.sourceDir)}`);
args.push(`-B${util.lightNormalizePath(binaryDir)}`);
Expand Down Expand Up @@ -258,7 +258,7 @@ export class CMakeFileApiDriver extends CMakeDriver {
if (!configurePreset) {
this._needsReconfigure = false;
}
await this.updateCodeModel(configurePreset?.binaryDir);
await this.updateCodeModel(binaryDir);
}
return result.retc === null ? -1 : result.retc;
}
Expand Down
36 changes: 18 additions & 18 deletions src/projectController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,23 +266,25 @@ export class ProjectController implements vscode.Disposable {
* @returns The newly created CMakeProject backend for the given folder
*/
private async addFolder(folder: vscode.WorkspaceFolder): Promise<CMakeProject[]> {
const existing = this.getProjectsForWorkspaceFolder(folder);
if (existing) {
this.beforeAddFolderEmitter.fire(folder);
let projects: CMakeProject[] | undefined = this.getProjectsForWorkspaceFolder(folder);
if (projects) {
rollbar.error(localize('same.folder.loaded.twice', 'The same workspace folder was loaded twice'), { wsUri: folder.uri.toString() });
return existing;
}
// Load for the workspace.
const workspaceContext = DirectoryContext.createForDirectory(folder, new StateManager(this.extensionContext, folder));
const newProjects: CMakeProject[] = await ProjectController.createCMakeProjectsForWorkspaceFolder(workspaceContext);
this.folderToProjectsMap.set(folder.uri.fsPath, newProjects);
const config: ConfigurationReader | undefined = workspaceContext.config;
if (config) {
this.sourceDirectorySub.set(folder, config.onChange('sourceDirectory', async (sourceDirectories: string | string[]) => this.doSourceDirectoryChange(folder, sourceDirectories)));
this.buildDirectorySub.set(folder, config.onChange('buildDirectory', async () => this.refreshDriverSettings(folder, config.sourceDirectory)));
this.installPrefixSub.set(folder, config.onChange('installPrefix', async () => this.refreshDriverSettings(folder, config.sourceDirectory)));
this.useCMakePresetsSub.set(folder, config.onChange('useCMakePresets', async (useCMakePresets: string) => this.doUseCMakePresetsChange(folder, useCMakePresets)));
} else {
// Load for the workspace.
const workspaceContext = DirectoryContext.createForDirectory(folder, new StateManager(this.extensionContext, folder));
projects = await ProjectController.createCMakeProjectsForWorkspaceFolder(workspaceContext);
this.folderToProjectsMap.set(folder.uri.fsPath, projects);
const config: ConfigurationReader | undefined = workspaceContext.config;
if (config) {
this.sourceDirectorySub.set(folder, config.onChange('sourceDirectory', async (sourceDirectories: string | string[]) => this.doSourceDirectoryChange(folder, sourceDirectories)));
this.buildDirectorySub.set(folder, config.onChange('buildDirectory', async () => this.refreshDriverSettings(folder, config.sourceDirectory)));
this.installPrefixSub.set(folder, config.onChange('installPrefix', async () => this.refreshDriverSettings(folder, config.sourceDirectory)));
this.useCMakePresetsSub.set(folder, config.onChange('useCMakePresets', async (useCMakePresets: string) => this.doUseCMakePresetsChange(folder, useCMakePresets)));
}
}
return newProjects;
this.afterAddFolderEmitter.fire({ folder: folder, projects: projects });
return projects;
}

/**
Expand Down Expand Up @@ -427,9 +429,7 @@ export class ProjectController implements vscode.Disposable {
}
// Load a new CMake Tools instance for each folder that has been added.
for (const folder of event.added) {
this.beforeAddFolderEmitter.fire(folder);
const cmakeProjects = await this.addFolder(folder);
this.afterAddFolderEmitter.fire({ folder: folder, projects: cmakeProjects });
await this.addFolder(folder);
}
}

Expand Down

0 comments on commit defb0ad

Please sign in to comment.