swiftlang / sourcekit-lsp

Language Server Protocol implementation for Swift and C-based languages
Apache License 2.0
3.29k stars 272 forks source link

SourceKit-LSP seems to ignore `CXXSettings.unsafeFlags` #609

Closed mikolasstuchlik closed 1 year ago

mikolasstuchlik commented 2 years ago

I have set up a simple project using hand-built C++ library.

I have added custom C++ header search paths outside of the Package directory using CXXSettings.unsafeFlags as follows:

cxxSettings: [.unsafeFlags(["-I\(llvmIncludePath)"])],

but SourceKit-LSP ignores those include search paths. I have also tried to add those paths to the Swift Plugin for VSCode provided by SSWG, but this didn't work either.

@ahoppen asked me to try it out on the most recent DEVELOPMENT snapshot of the Swift Toolchain, but it didn't work either. On top of that, the clangd started to consume more and more cpu% and I was forced to kill it.

This issue was discussed on https://forums.swift.org/t/sourcekit-lsp-seems-to-ignore-cxxsettings-unsafeflags/59503

ahoppen commented 2 years ago

rdar://98370922

ahoppen commented 2 years ago

It appears that we aren’t passing compiler arguments that are provided in Package.swift to clangd.

svanimpe commented 1 year ago

I came across this issue and I'm wondering if it's also the cause for my issue.

I'm trying to use a C library with Swift on Windows. Since the headers aren't installed in a global location, and pkg-config isn't available, I've added .unsafeFlags(["-IpathToIncludeDir"]) to the swiftSettings for my target in Package.swift.

The target now builds fine, but in the editor, I cannot click through to the definition of an imported C function, and the return types always show <<error type>>.

Screenshot

On macOS and Linux, this works fine, I'm assuming because it can find the headers through pkg-config instead?

Is this the same issue, or should I open a new one?

compnerd commented 1 year ago

What version of swift are you using? Anything older the latest main snapshot would be too old for Windows at least. But, if it is the right version, then it should be the same issue.

svanimpe commented 1 year ago

Ah sorry, I'm using the 5.7 release.

ahoppen commented 1 year ago

Hi @mikolasstuchlik, sorry for only getting back to this now. I just tried reproducing the issue and was unable to. Here’s what I tried.

Are you still seeing the issue? If yes, could you attach a project that reproduces the issue for you?

mikolasstuchlik commented 1 year ago

Hello @ahoppen. Unfortunately, I have forgot why I've run into this issue. I will look through my archive and let you know if I find something.

mikolasstuchlik commented 1 year ago

I have read the original thread on the Forums. The issue was manifesting when I've attempted to manually include header files of locally built library PCL. I have been using Swift 5.6.1 at the time, which was ignoring said flags. However, I have been asked to DEVELOPMENT-SNAPSHOT-2022-08-06 which also failed.

I will need to build PCL again and I will let you know once I have results.

ahoppen commented 1 year ago

Sorry for the delay on my side. This would have been a lot easier if I had gotten back to you earlier. I really appreciate that you’re giving it another try.

mikolasstuchlik commented 1 year ago

I would like to let you know, that I've been on vacation last week. I will look at the issue next week.

mikolasstuchlik commented 1 year ago

TL;DR I can confirm, that the issue no longer manifests on

swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)
Target: x86_64-apple-macosx13.0

I have cloned pcl 1.13.1. I have tried to clone, configure and edit https://github.com/mikolasstuchlik/RunPCL which is the same project, where I've observed the issue.

The SourceKit-LSP in VSCide works as expected (albeit with considerable delay) and no longers spawns endless clangd tasks.

I consider this ticket solved.

ahoppen commented 1 year ago

Great. Thanks for verifying.