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

Use of single quotes in linking_to_flags() on Windows can prevent compilation database from successfully loading #305

Open
tylermorganwall opened this issue Nov 19, 2024 · 0 comments

Comments

@tylermorganwall
Copy link
Contributor

The use of single quotes in linking_to_flags() does not work with clangd's compilation database on Windows, as single quotes are not correctly parsed on whatever Windows shell clangd uses to parse the command args. You can see this referenced in an related problem on the clangd repo, see this issue: clangd/clangd#1094. The single quotes are only used for the LinkingTo flags, and I noticed that the symbols that were successfully being imported corresponded to those headers in double quotes.

This function is the issue:

linking_to_flags <- function(desc) {
  linking_to <- desc$get_field("LinkingTo", default = NULL)

  if (is.null(linking_to)) {
    return("")
  }

  # Split by comma
  linking_to <- strsplit(linking_to, " *, *",)[[1]]

  # Remove version if any
  linking_to <- strsplit(linking_to, " *\\(",)
  linking_to <- vapply(linking_to, function(pkg) pkg[[1]], "")

  paths <- vapply(linking_to, function(pkg) system.file("include", package = pkg), "")
  paths <- paths[paths != ""]

  paste(paste0("-I'", paths, "'"), collapse = " ") //// This is the issue
}

To fix this, I simply replaced this line:

  paste(paste0("-I'", paths, "'"), collapse = " ") 

with an escaped quote:

  paste(paste0("-I\"", paths, "\""), collapse = " ") 

Which I have confirmed fixed the issue for my packages on Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant