irony-mode icon indicating copy to clipboard operation
irony-mode copied to clipboard

Irony I/O task error (Windows 10, cpp file, company + company-irony)

Open astewartau opened this issue 7 years ago • 9 comments

I am very new to Emacs (I come from Atom and love Emacs a lot so far) and today I am trying to set up auto-completion for C++. I noticed there is another similar issue open already, but since I am new, I'm not sure if this is the same issue.

I am using:

  • Windows 10 64-bit
  • Emacs 25.2 x86-64
  • Also tried Emacs 24.5 i686 mingw32
  • irony-mode
  • company
  • company-irony

I have built a compile_commands.json file using CMake, which is located in ../build. My cpp file is in ../src. I believe I have set up the location of the json file correctly.

After enabling company, I get the following error when typing into a cpp file:

Irony I/O task: error in callback: (irony-server-error complete-error "failed to perform code completion" "e:/Downloads/SFML-Game/src/main.cpp" 22 7)

When I toggle-debug-on-error, I get the following:

Debugger entered--Lisp error: (irony-server-error complete-error "failed to perform code completion" "e:/Downloads/SFML-Game/src/main.cpp" 18 9)
  signal(irony-server-error (complete-error "failed to perform code completion" "e:/Downloads/SFML-Game/src/main.cpp" 18 9))
  irony-iotask-result-get([cl-struct-irony-iotask-result error nil irony-server-error (complete-error "failed to perform code completion" "e:/Downloads/SFML-Game/src/main.cpp" 18 9)])
  #[(G64301 candidates-result) "J\302\303	!!!\207" [G64301 candidates-result irony-completion--filter-candidates irony-iotask-result-get] 4](--cb-- [cl-struct-irony-iotask-result error nil irony-server-error (complete-error "failed to perform code completion" "e:/Downloads/SFML-Game/src/main.cpp" 18 9)])
  apply(#[(G64301 candidates-result) "J\302\303	!!!\207" [G64301 candidates-result irony-completion--filter-candidates irony-iotask-result-get] 4] --cb-- [cl-struct-irony-iotask-result error nil irony-server-error (complete-error "failed to perform code completion" "e:/Downloads/SFML-Game/src/main.cpp" 18 9)])
  (lambda (&rest --cl-rest--) (apply (quote #[(G64301 candidates-result) "J\302\303	!!!\207" [G64301 candidates-result irony-completion--filter-candidates irony-iotask-result-get] 4]) (quote --cb--) --cl-rest--))([cl-struct-irony-iotask-result error nil irony-server-error (complete-error "failed to perform code completion" "e:/Downloads/SFML-Game/src/main.cpp" 18 9)])
  byte-code("r\303H	>\204

My relevant .emacs init is as follows:

;; Company
(eval-after-load 'company
  '(add-to-list 'company-backends 'company-irony))

;; IRONY MODE
(add-hook 'c++-mode-hook 'irony-mode)
(add-hook 'c-mode-hook 'irony-mode)
(add-hook 'objc-mode-hook 'irony-mode)

(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)

;; Windows performance tweaks
(when (boundp 'w32-pipe-read-delay)
  (setq w32-pipe-read-delay 0))
;; Set the buffer size to 64K on Windows (from the original 4K)
(when (boundp 'w32-pipe-buffer-size)
  (setq irony-server-w32-pipe-buffer-size (* 64 1024)))

Any advice as to what is going on would be fantastic! 😃

astewartau avatar Apr 30 '17 10:04 astewartau

Is it possible to see what are the compile options? If there are "really" wrong I think it could cause this kind of error when requesting code completion.

Sarcasm avatar May 02 '17 22:05 Sarcasm

Thanks for the reply. I am not precisely sure what you're asking for when you say compile options, but perhaps the answer lies within my full CMakeLists.txt file which I am using to generate a MinGW Makefile.

cmake_minimum_required(VERSION 3.0)

SET(CMAKE_C_COMPILER gcc)
SET(CMAKE_CXX_COMPILER g++)

project(game)

include_directories(include)
link_directories(lib/mingw)

file(GLOB GAME_SRC
"src/*.cpp"
)

add_executable(
game
${GAME_SRC}
)

set_target_properties(game
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/Debug"
)

target_compile_features(game PRIVATE cxx_range_for)

set(GCC_COVERAGE_COMPILE_FLAGS "-DGLEW_STATIC")

target_link_libraries(game
libglew32.a
libopengl32.a
libsfml-main-d.a
libsfml-graphics-d.a
libsfml-audio-d.a
libsfml-system-d.a
libsfml-window-d.a
)

I am calling cmake via cmake -G "MinGW Makefiles" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON, which also generates a compile_commands.json file which contains the following:

[
{
  "directory": "E:/Downloads/SFML-Game/build",
  "command": "E:\\Development\\Tools\\MinGW\\bin\\g++.exe   @CMakeFiles/game.dir/includes_CXX.rsp   -std=gnu++11 -o CMakeFiles\\game.dir\\src\\main.cpp.obj -c E:\\Downloads\\SFML-Game\\src\\main.cpp",
  "file": "E:/Downloads/SFML-Game/src/main.cpp"
}
]

Finally, I simply build via mingw32-make.

astewartau avatar May 03 '17 07:05 astewartau

Can you show the output of running Clang on the command line?

cd E:/Downloads/SFML-Game/build
clang++ @CMakeFiles/game.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles\game.dir\src\main.cpp.obj -c E:\Downloads\SFML-Game\src\main.c

It's possible the response file is causing some issues.

Sarcasm avatar May 03 '17 08:05 Sarcasm

Sure - it is actually a .cpp file though, not a .c file. I changed it to .cpp, but I'm not sure if I should redo this with some other parameter.

E:\Downloads\SFML-Game\build>clang++ @CMakeFiles/game.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles\game.dir\src\main.cpp.obj -c E:\Downloads\SFML-Game\src\main.cpp
E:\Downloads\SFML-Game\src\main.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
         ^
Assertion failed: (t.isNull() || !t->isReferenceType()) && "Expressions can't have reference type", file D:\src\llvm_release_build_3.5.0\llvm\tools\clang\include\clang/AST/Expr.h, line 134
clang++.exe: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 3.5.0 (217039)
Target: i686-pc-windows-gnu
Thread model: posix
clang++.exe: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and associated run script.
clang++.exe: note: diagnostic msg: Error generating preprocessed source(s).

astewartau avatar May 03 '17 08:05 astewartau

It looks like Clang does not like your environment.

You can try to inline the response file, update Clang.

Sarcasm avatar May 03 '17 08:05 Sarcasm

Hi, thanks for that. I've updated to Clang 4.0, and I removed MSBuild from my PATH after realising that it could be confusing it.

The command clang++ @CMakeFiles/game.dir/includes_CXX.rsp -std=gnu++14 -o CMakeFiles\game.dir\src\main.cpp.obj -c E:\Downloads\SFML-Game\src\main.cpp now runs error-free and produces an .obj file. I had to change it to gnu++14 as well, as I got errors about 'auto' when it was on gnu++11 (error: 'auto' return without trailing return type; deduced return types are a C++14 extension).

Unfortunately, though - I'm still getting the Iron I/O task error in Emacs.

astewartau avatar May 03 '17 13:05 astewartau

Auto-complete now works as expected only when I manually change my compile_commands.json file from this:

[
{
  "directory": "E:/Development/SFML-Game/build",
  "command": "E:\\Development\\MinGW\\bin\\g++.exe   @CMakeFiles/game.dir/includes_CXX.rsp   -std=gnu++11 -o CMakeFiles\\game.dir\\src\\main.cpp.obj -c E:\\Development\\SFML-Game\\src\\main.cpp",
  "file": "E:/Development/SFML-Game/src/main.cpp"
}
]

To this:

[
{
  "directory": "E:/Development/SFML-Game/build",
  "command": "E:\\Development\\MinGW\\bin\\g++.exe -I E:/Development/Tools/SFML-Game/include -std=gnu++11 -o CMakeFiles\\game.dir\\src\\main.cpp.obj -c E:\\Development\\SFML-Game\\src\\main.cpp",
  "file": "E:/Development/SFML-Game/src/main.cpp"
}
]

What I have done here is replaced @CMakeFiles/game.dir/includes_CXX.rsp with the literal contents of the file it's referring to, which are -I E:/Development/Tools/SFML-Game/include.

I'm stoked to have irony-mode working, but it's a pain having to change my .json file each time I build. Do you know what might be happening here, given this new information?

astewartau avatar May 04 '17 07:05 astewartau

That's what I meant by:

You can try to inline the response file

I suspect the response file to be an issue, for example, irony-mode parses some compile options but does not handle response file. And for libclang, I'm not sure what is the issue.

What is the content of the response file? Can you show the whole file? Is it just this: -I E:\\Development\\SFML-Game\\include?

Sarcasm avatar May 04 '17 08:05 Sarcasm

Ah, I didn't realise that was what you meant by response file. The contents of the .rsp file are as follows (including the blank line):

-IE:/Development/SFML-Game/include 

EDIT: I just tried changing the / style to what you listed in your comment - it doesn't seem to affect the outcome.

Update: I found #338 and followed the suggestion of adding a .clang_complete file in the root directory (/src) with the contents of the includes_CXX.rsp file. I don't know why, but this has solved the problem.

This can be easily automated by performing a post-build copy and rename of the rsp file so that the .clang_complete file is always up-to-date.

Would still be interested to know why this works, or if there is a better solution.

astewartau avatar May 04 '17 08:05 astewartau