hotpxl / company-irony-c-headers Goto Github PK
View Code? Open in Web Editor NEWCompany mode backend for C/C++ header files with Irony
License: GNU General Public License v3.0
Company mode backend for C/C++ header files with Irony
License: GNU General Public License v3.0
Is able to show completion for projects based header files (#include "someheader.h"
) but fails to show anything on #include <
.
I wan to use company-irong-c-headers
for Arduino libraries in ~/Arduino/libraries/
Here is the structures:
~/Arduino/libraries/<sketch>/src/{*.cpp, *.h}
company-irony-c-headers hasn't seen a release on MELPA stable yet. Please consider releasing company-irony-c-headers on MELPA stable.
The company-irony-c-headers--working-dir is used to set default-directory, that must end in slash to work correctly (otherwise it ends up in parent directory). This confuses the reload of compiler output.
Fixed as follows:
(defun company-irony-c-headers--working-dir ()
"Get working directory."
(if irony--working-directory
(concat irony--working-directory "/")
default-directory))
Could you please explain in README why I need this package next to company-irony?
I can autocomplete system headers, but not project headers.
I was assuming that this plugin was going to look at the json database for compile options and pull paths from that?
Or, is it supposed to work like that already?
The post-completion action add a quote "
or tag >
even if already present, producing things like this after expansion:
#include <ios[]>
#include <iostream>[]>
[]
represents the cursor
I fixed this by pruning such options as follows:
(defun company-irony-c-headers--clean-compiler-options (options)
(cond ((null options)
nil)
((or (string-equal "-MF" (car options))
(string-equal "-MT" (car options))
(string-equal "-MQ" (car options)))
(company-irony-c-headers--clean-compiler-options (cddr options)))
((string-prefix-p "-M" (car options))
(company-irony-c-headers--clean-compiler-options (cdr options)))
(t
(cons (car options)
(company-irony-c-headers--clean-compiler-options (cdr options))))))
(defun company-irony-c-headers--user-compiler-options ()
"Get compiler options."
(company-irony-c-headers--clean-compiler-options irony--compile-options))
Hi:
I was trying to find a way to add additional include paths to company-irony-c-headers through a .dir-locals.el file or getting it to work with company-c-headers existing include flags.
Is it possible to pass in additional include paths to company-irony-c-headers for this purpose in a .dir-locals.el file or combine the two completions output from company-c-headers and company-irony-c-headers?
I have not been able to find a way to add header files using a .dir-locals file. Right now I do this in one of my emacs startup files:
; C++ Autocomplete for clang
(require 'fuzzy)
(require 'auto-complete-clang)
(require 'auto-complete)
(define-key c++-mode-map (kbd "C-S-SPC") 'ac-complete-clang)
; Use irony autocomplete for C languages
(add-hook 'c++-mode-hook 'irony-mode)
(add-hook 'c-mode-hook 'irony-mode)
(add-hook 'objc-mode-hook 'irony-mode)
;; replace the `completion-at-point' and `complete-symbol' bindings in
;; irony-mode's buffers by irony-mode's function
(defun my-irony-mode-hook ()
(define-key irony-mode-map [remap completion-at-point]
'irony-completion-at-point-async)
(define-key irony-mode-map [remap complete-symbol]
'irony-completion-at-point-async))
(add-hook 'irony-mode-hook 'my-irony-mode-hook)
(add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
(setq w32-pipe-read-delay 0)
; Use company-mode with irony
(add-hook 'irony-mode-hook 'company-irony-setup-begin-commands)
(setq company-backends (delete 'company-semantic company-backends))
; Enable completion of C/C++ headers
;; Load with `irony-mode` as a grouped backend
(require 'company-irony-c-headers)
(require 'company-c-headers)
(eval-after-load 'company
'(add-to-list
'company-backends '(company-irony-c-headers company-irony company-c-headers)))
; (add-to-list 'company-backends 'company-c-headers)
; Set autocomplete header search paths based on OS type
; NOTE: Can find the include paths with the shell command ``echo "" | g++ -v -x c++ -E -``
(cond
((string-equal system-type "windows-nt") ; any flavor of Windows
(setq ac-clang-flags
(mapcar (lambda (item)(concat "-I" item))
(split-string
"
c:/Qt/4.8.5/include
"
)))
(add-to-list 'company-c-headers-path-system "c:/Qt/4.8.5/include")
)
((string-equal system-type "gnu/linux")
)
((string-equal system-type "darwin") ; Mac
)
)
; Use tab-completion with no delay
(setq company-idle-delay 0.5)
(define-key c-mode-map [(control tab)] 'company-complete)
(define-key c++-mode-map [(control tab)] 'company-complete)
But when I hit C-tab, I only get the completions coming from company-irony-c-headers (i.e.stdlib stuff like string, vector), and not company-c-headers (i.e. QtCore, QtGui). Is there a way I can combine both backend completion results so that company-complete shows them all? If I run company-c-headers manually, the completions show up, so I know at least the candidates themselves are being loaded, they're just not being combined with the candidates in company-complete for some reason.
Additionally, I was trying to set the include paths for company-c-headers using a .dir-locals.el file instead of hardcoding it in my emacs startup script, like so:
((c++-mode (eval setq company-clang-arguments (append
company-clang-arguments
'("-I C:/Qt/4.8.5/include")))))
But this doesn't seem to have any effect whatsoever when I attempt to use company-c-headers; it doesn't show me the completions from Qt.
For some reason auto-completing headers is not replacing the initial # but adding another one as apart of the autocomplete.
For example typing "#in" and accepting any of the autocomplete suggestions results in "##include <>"
how do I fix this?
Hello,
I noticed that completion does not work if without .clang_complete file in working directory.
So I looked at company-irony-c-headers.el source and found some useless code in function of company-irony-c-headers-reload-compiler-output.
< in 89 >
(when (and company-irony-c-headers--compiler-executable
(company-irony-c-headers--working-dir))
I think conditional branching by (company-irony-c-headers--working-dir) cause the problem.
< in 94 >
(let ((uco (company-irony-c-headers--user-compiler-options))
(dco (company-irony-c-headers--default-compiler-options))
(default-directory (company-irony-c-headers--working-dir)))
The variable of default-directory isn't use in company-irony-c-headers-reload-compiler-output.
So I removed these useless code then completion working perfectly without .clang_complete file in working directory.
Could you apply this modification if there is no problem?
Sorry for my bad English. Thank you.
Hello,
After a simple test it seems to work nicely.
I noticed one thing. Company triggers the completion after company-minimum-prefix-length
(3 characters by default). It would be nice to to trigger the completion automatically after a '/' though.
So if I ask for:
#include <boost/[]>
Completion should be triggered automatically.
This is achievable via company's prefix
return value, see https://github.com/company-mode/company-mode/blob/c6af7d29ef7b8d2b6b4800151511ead26c521532/company.el#L346-L347
Hello,
Is it possible as in company-c-headers
to add user directories for the completion ?
(add-to-list 'company-irony-c-headers-user-path '"/home/...")
(add-to-list 'company-irony-c-headers-user-path '"/home/...")
(add-to-list 'company-irony-c-headers-user-path '"/home/...")
Thanks !
Hello.
Assume we have some files:
SomeClass.h
SomeClass.cpp
main.cpp
I would like to unclude SomeClass.h into main.cpp, so:
main.cpp:
SomeClass.cpp
SomeClass.h
First candidate is .cpp file, but in 99% cases I would like to include .h, .hpp, .inl and other files, but not .cpp.
I think this is due to 'sort' function, and 'c' is smaller than 'h', right?
Is there any way to customize sorting behavior?
Thank you a lot!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.