Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to open source file outside workspaceFolder from project outline #1504

Closed
bobbrow opened this issue Oct 22, 2020 · 11 comments
Closed
Labels
Milestone

Comments

@bobbrow
Copy link
Member

bobbrow commented Oct 22, 2020

hi @bobbrow, I am using 1.4.2 CMake Tools on macOS, but the issue is still there:

Unable to open 'main.cpp': Unable to read file '/Users/admin/Projects/A/console/Users/admin/Projects/A/src/main.cpp' (Error: Unable to resolve non-existing file '/Users/admin/Projects/A/console/Users/admin/Projects/A/src/main.cpp').

The project structure looks like:

A $ tree -L 2 .
.
├── README.md
├── console
│   ├── build
│   └── CMakeLists.txt
├── src
│   └── main.cpp
└── third-party

with this simple setup:

set(MAIN_SOURCE_DIR "../src")

file(GLOB_RECURSE CPP_HEADERS ${MAIN_SOURCE_DIR}/*.hpp)
file(GLOB_RECURSE CPP_SOURCES ${MAIN_SOURCE_DIR}/*.cpp)

add_executable(
    A
    ${CPP_HEADERS}
    ${CPP_SOURCES}
)

As you can see, the error reports a path with <CMakeLists Dir>+<Absolute Source Path>, which is duplicate and totally wrong.

'/Users/admin/Projects/A/console/Users/admin/Projects/A/src/main.cpp'

Platform and Versions
Operating System:macOS
CMake Version:3.18.4
VSCode Version:1.50.1
CMake Tools Extension Version: 1.4.2
Compiler/Toolchain: Clang 11

Originally posted by @mutoo in #1254 (comment)

@bobbrow
Copy link
Member Author

bobbrow commented Oct 22, 2020

@mutoo, can you provide a little more information for us? Which folder in the structure you shared is the ${workspaceFolder}? I tried opening both console and src after replicating your folder structure, but am unable to repro on Windows. I'll try again on Linux (I don't have a mac to try right now).

@bobbrow bobbrow added bug a bug in the product Feature: Project Outline View more info needed More info is needed from the community for us to properly triage and investigate. labels Oct 22, 2020
@mutoo
Copy link

mutoo commented Oct 23, 2020

@bobbrow, the ${workspaceFolder} is the console /Users/admin/Projects/A/console.

@tvb377
Copy link

tvb377 commented Oct 27, 2020

Me too:
I have a folder structure where two source folders are on the same level.
One of them contains the CMakeLists.txt and adds sources also from its sibling.

CMake Tools somehow understands that some source files are located together in another folder, and in the explorer subsumes them in a separate tree entry underneath the target.
But already in the explorer a wrong path to the folder appears: apparently relative to the build directory, but after .... "\Users\name" gets prepended.
When I try to open a file of the library dir (the one not containing CMakeLists.txt), I get the message:
Unable to open 'byte_to_hex.c': Unable to read file 'c:\Users\name\Users\name\srclocal\avrlib\byte_to_hex.c' (Error: Unable to resolve non-existing file 'c:\Users\name\Users\name\srclocal\avrlib\byte_to_hex.c').
image

Also, the file names communicated to intellisense seem to be wrong.

As you can see, this is on Windows.

@bobbrow bobbrow removed the more info needed More info is needed from the community for us to properly triage and investigate. label Oct 31, 2020
@k0pernicus
Copy link

k0pernicus commented Nov 6, 2020

Hi everyone,
I have the exact same issue than @bobbrow (EDIT: sorry, it was @mutoo).

If I don't make any mistake, we are following a tutorial to create a sort of graphic engine on multiple platforms, using C++ and SDL: https://marcelbraghetto.github.io/a-simple-triangle/2019/03/02/part-02/

In this part, the author shows how to configure it's own VSCode instance using Cmake and Cmake Tools (vector-of-bool version, not from microsoft), but following the steps VSCode + extensions does not follow the rules and create another full path inside the current workspace folder.

I expect that the configuration of the extensions change, or something we missed, because using the scripts on the console directly works, check the code directly and build the binary.

Setup:

  • macOS Catalina 10.15.7
  • VSCode 1.50.1
  • CMake (twxs) version 0.0.17
  • CMake Tools (Microsoft) version 1.5.0

@srpax
Copy link

srpax commented Nov 7, 2020

Hi @bobbrow, I also have this problem. I'm also using SDL like @k0pernicus, but I'm not following a tutorial (i.e. issue produced organically). For example, I might have a file structure like:

EDIT: Updated this tree to reflect actual file structure since it may matter.

C:\Users\spaxt\
├── SDL2-2.0.12\
│   └── include\
│       └── SDL.h
└── project-ember\
    ├── include\
    │   └── MbrWindow.h (#includes SDL.h)
    └── CMakeLists.txt 

The add_library/add_executable call in CMakeLists could be using a relative or absolute path of SDL.h, and I still get the follow situation:
(Ember is the name of my project)
image
Ok, that doesn't look bad, but the part of the path you can't see is "C:\Users", so the whole path resolves as:
C:\Users\Users\spaxt\SDL2-2.0.12\include\SDL.h

Obviously C:\Users\Users doesn't exist:
image

EDIT: Added relevant CMakeLists.txt content showing how I obtain the SDL.h path:

# SDL2 variables
set(SDL_DIR ${PROJECT_SOURCE_DIR}/../SDL2-2.0.12)
set(SDL_PUBLIC_HEADER ${SDL_DIR}/include/SDL.h)
...
add_library(Ember SHARED ${EMBER_HEADER_FILES} ${EMBER_SOURCE_FILES} ${SDL_PUBLIC_HEADER})

Setup:

  • Visual Studio Code 1.50.1
  • CMake (twxs) version 0.0.17
  • CMake Tools (Microsoft) version 1.5.1
  • Other Extensions:
    image

@Dyronix
Copy link

Dyronix commented Apr 18, 2021

Would it be possible to receive a patch for this fix, it is blocking our entire workflow ... We have to switch IDE in order to edit our source files and switch back to run the CMake configuration.

A workaround would also do the trick.

@sleiner
Copy link
Contributor

sleiner commented Apr 28, 2021

I too would be very happy to have this fixed. If there is anything I can do to help, please reach out @bobbrow :-)

@bobbrow
Copy link
Member Author

bobbrow commented Apr 28, 2021

Thanks for the offer @sleiner! If you have a repro and can debug the extension as it's building the tree view, that would help us get the information we need to understand the bug. Contribution doc

The line I would set a breakpoint on is here:

item.command = {

I suspect that the item.resourceUri is incorrect in this case.

@sleiner
Copy link
Contributor

sleiner commented Apr 28, 2021

Thanks for the helpful hint 😊 I actually came up with something that fixes the problem (at least on my Mac with a very simple project). I'll test it with a much larger project at work tomorrow 👍🏻

andreeis pushed a commit that referenced this issue May 5, 2021
* Fix paths of target sources outside the workspace

For more details, see:
#1504

* Add test for source files outside of workspace root

Co-Authored-By: Elson Wei <elson.wei@gmail.com>

Co-authored-by: Elson Wei <elson.wei@gmail.com>
Co-authored-by: Bob Brown <bobbrow@users.noreply.github.com>
@andreeis
Copy link
Contributor

andreeis commented May 5, 2021

@sleiner, your contribution is in 👍. If all goes according to plans, we should release CMake Tools 1.7.2 tomorrow. Until then, here's a vsix with your change, if needed: https://github.com/microsoft/vscode-cmake-tools/actions/runs/814930130.

@sleiner
Copy link
Contributor

sleiner commented May 6, 2021

Thanks, you two 🙌🏻

andreeis added a commit that referenced this issue May 6, 2021
* Fix typo in CMakePresets.json schema (#1809)

MinSizRel => MinSizeRel

* update version to 1.7.2

* Localize an error message

* Added counts for presets (#1819)

* override the locale when querying compiler versions (#1824)

* Adopt new localization process (#1831)

* Fix Operator Precedence when Getting Code Page (#1808)

The replacing should happen after the "??" operator.

Fixes #1615

Co-authored-by: Andreea Isac <48239328+andreeis@users.noreply.github.com>

* If we have both "-DCMAKE_GENERATOR:STRING=" and the generator from (#1753)

toolchain, prefre using "-DCMAKE_GENERATOR:STRING=", as
"-DCMAKE_GENERATOR:STRING=" can be defined by different cmake-variants.yaml

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>

Co-authored-by: Andreea Isac <48239328+andreeis@users.noreply.github.com>

* Use stricter type checks in presets expansion (#1818)

* Use stricter type checks in presets expansion

* Resolving comments

Co-authored-by: Andreea Isac <48239328+andreeis@users.noreply.github.com>

* Fix paths of target sources outside the workspace (#1816)

* Fix paths of target sources outside the workspace

For more details, see:
#1504

* Add test for source files outside of workspace root

Co-Authored-By: Elson Wei <elson.wei@gmail.com>

Co-authored-by: Elson Wei <elson.wei@gmail.com>
Co-authored-by: Bob Brown <bobbrow@users.noreply.github.com>

* CHANGELOG updates for 1.7.2 (#1837)

Co-authored-by: BlueC0re <bluec0re@users.noreply.github.com>
Co-authored-by: Bob Brown <bobbrow@users.noreply.github.com>
Co-authored-by: Bob Brown (DEVDIV) <bobbrow@microsoft.com>
Co-authored-by: xisui-MSFT <44103947+xisui-MSFT@users.noreply.github.com>
Co-authored-by: Colen Garoutte-Carson <49173979+Colengms@users.noreply.github.com>
Co-authored-by: Huang, Zhaoquan <zhaoquan2008@hotmail.com>
Co-authored-by: Yonggang Luo <luoyonggang@gmail.com>
Co-authored-by: Simon Leiner <sleiner@users.noreply.github.com>
Co-authored-by: Elson Wei <elson.wei@gmail.com>
@andreeis andreeis closed this as completed May 6, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
8 participants