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

What is company-clang--guess-pch-file trying to matching? #972

Open
xuchunyang opened this issue Apr 3, 2020 · 6 comments
Open

What is company-clang--guess-pch-file trying to matching? #972

xuchunyang opened this issue Apr 3, 2020 · 6 comments
Labels

Comments

@xuchunyang
Copy link

Hello,

I got a question about the regexp pattern used in the following:

(defsubst company-clang--guess-pch-file (file)
  (let ((dir (directory-file-name (file-name-directory file))))
    (when (equal (file-name-nondirectory dir) "Classes")
      (setq dir (file-name-directory dir)))
    (car (directory-files dir t "\\([^.]h\\|[^h]\\).pch\\'" t))))

according to https://clang.llvm.org/docs/UsersManual.html#generating-a-pch-file, the pch file looks like test.h.pch, shouldn't the filename be matched? this pattern doesn't match test.h.pch

(string-match "\\([^.]h\\|[^h]\\).pch\\'" "test.h.pch")
;; => nil
@dgutov
Copy link
Member

dgutov commented Apr 3, 2020

Good question. I don't have a good answer, and this code is 10 years old now. Maybe @nschum could remember, but probably not.

Were you looking into support for precompiled headers?

@dgutov
Copy link
Member

dgutov commented Apr 3, 2020

Judging by the commentary, though, the code is trying to distinguish between "precompiled headers" and "prefix files".

@xuchunyang
Copy link
Author

Were you looking into support for precompiled headers?

No, I notice this when I read the code to figure out how company-clang works, the initial cause is that I find company-clang can't complete symbols from cairo.h.

distinguish between "precompiled headers" and "prefix files".

I know "precompiled headers", but I don't know what's "prefix files", what the "prefix" stands for? I couldn't find the term on https://clang.llvm.org/docs/UsersManual.html, and M-x company-clang-set-prefix's docstring suggests it's for -include, however man clang's doc doesn't mention "prefix".

   -include <filename>
          Adds an implicit #include into the predefines buffer which is read before the source file is preprocessed

@dgutov
Copy link
Member

dgutov commented Apr 3, 2020

I don't really use Clang myself, so I don't have an answer to that unfortunately.

Does the documented feature related to -include make sense? Does it work, it does it need fixing?

@xuchunyang
Copy link
Author

I'm not familiar with Clang too. I don't understand the documentation.

company-clang-set-prefix is an interactive compiled Lisp function in
`company-clang.el'.

(company-clang-set-prefix &optional PREFIX)

Use PREFIX as a prefix (-include ...) file for clang completion.

maybe "a prefix file" means a c header file? I have not used this command, however, since Clang does have the -include option, so company-clang-set-prefix probably works.

@dgutov
Copy link
Member

dgutov commented Apr 5, 2020

Maybe it does, maybe it doesn't. But the intention seems to be to looks for a file that the user probably generated manually, to speed up completion.

There is some very similar logic in https://github.com/Golevka/emacs-clang-complete-async/blob/master/auto-complete-clang-async.el#L86, except in the end it uses -include-pch, and not just -include like we do.

Some time ago, Vim's clang_complete included using it as a possible optimization as well: xavierd/clang_complete@cecca90. But not the current version.

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

No branches or pull requests

2 participants