microsoft / microsoft/vscode-cmake-tools

Plugin doesn't handle `cmake.sourceDirectory` changes properly

Open
#4,203 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Feature: settings
Dominant language
TypeScript
Stars
1.7k
Forks
546
Avg merge
2d 16h
Merged PRs (30d)
32

Description

Brief Issue Summary

I have a workspace structure that looks like this:

.
├── cmake-simple-demo
│   └── CMakeLists.txt
├── cmake-simple-demo_copy
│   └──  CMakeLists.txt
└──  cmake-simple-demo_copy_1
    └──  CMakeLists.txt

When VSCode is first opened, the CMake view is not listed under "Open View" and many CMake commands are missing. This is to be expected, since the default value of cmake.sourceDirectory is ${workspaceFolder}, but there is no CMakeLists file there. However, when I give the preference a value, the commands are still missing, and the CMake view is still not listed. They only show once I reload the IDE.

A related issue: when there is only 1 path in the cmake.sourceDirectory array, the path and name of the folder is automatically assumed to be the workspace folder, which is not always true.

Image

Related again: when there is an array of directories in the array, and one new entry is added, the path and name of the folder is also assumed to be the workspace folder. This is fixed on reload, and also does not occur if more than 1 entry is added at once.

Image

CMake Tools Diagnostics

Debug Log

Additional Information

I did some preliminary digging. The second issue is caused by this line: https://github.com/microsoft/vscode-cmake-tools/blob/main/src/projectController.ts#L279. It should instead always return this.sourceDir.

The last issue is caused by this line: https://github.com/microsoft/vscode-cmake-tools/blob/main/src/projectController.ts#L279. The parameter value only includes the newly added values, hence why checking for length > 1 is incorrect.

I wanted to make sure there weren't any edge cases I was missing making these changes. For example, CMakeProject.folderPath has a comment that says "For single-project folders, this is the WorkspaceFolder for historical reasons." I haven't looked at the first issue yet.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/projectController.ts around line 279 and review the CMakeProject.folderPath comment about single-project folders. Reproduce changing cmake.sourceDirectory from an invalid default and adding one directory at a time, then verify the CMake view and commands update without reloading and folder paths remain correct. Check the related project-controller behavior for edge cases before defining the fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, typescript
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.