error with cgo completion on macOS
nhooyr opened this issue · 3 comments
nhooyr commented
My settings are as follows:
let g:deoplete#sources#go#gocode_binary = $GOPATH.'/bin/gocode'
let g:deoplete#sources#go#use_cache = 1
let g:deoplete#sources#go#json_directory = '~/.cache/deoplete/go/$GOOS_$GOARCH'
let g:deoplete#sources#go#auto_goos = 1
let g:deoplete#sources#go#cgo = 1
let g:deoplete#sources#go#cgo#libclang_path = '/Library/Developer/CommandLineTools/usr/lib/libclang.dylib'
When trying to complete this file (cursor is |
):
package main
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Cocoa
#import <Cocoa/Cocoa.h>
int pbcopy(const char *data) {
@autoreleasepool {
[[NSPasteboard generalPasteboard] declareTypes:[NSArray arrayWithObject:NSPasteboardTypeString] owner:nil];
[[NSPasteboard generalPasteboard] setString:[NSString stringWithUTF8String: data] forType:NSPasteboardTypeString];
}
return 0;
}
*/
import "C"
// copy byte
// C.pbcopy((*C.char)(unsafe.Pointer(&append(s.Bytes(), '\x00')[0])))
import (
"flag"
"log"
"net/url"
"path/filepath"
"time"
"github.com/fsnotify/fsnotify"
)
var dir = flag.String("dir", "/Users/nhooyr/dropbox", "directory to monitor")
func main() {
C.|
w, err := fsnotify.NewWatcher()
if err != nil {
log.Fatal(err)
}
defer w.Close()
for {
err = w.Add(*dir)
if err != nil {
log.Println("could not add, trying again...")
time.Sleep(1 * time.Second)
continue
}
log.Println("watching", *dir)
for {
select {
case event := <-w.Events:
log.Println("event:", event)
f := filepath.Base(event.Name)
if f[0] != '.' && event.Op != fsnotify.Chmod && event.Op != fsnotify.Remove {
l := (&url.URL{Scheme: "https", Host: "aubble.com", Path: f}).String()
C.pbcopy(C.CString(l))
log.Println("copied link", l)
}
case err := <-w.Errors:
log.Println("error:", err)
}
}
}
}
I get the following error
[deoplete] Traceback (most recent call last):
[deoplete] File "/Users/nhooyr/.cache/dein/.cache/init.vim/.dein/rplugin/python3/deoplete/deoplete.py", line 98, in gather_results
[deoplete] ctx['candidates'] = source.gather_candidates(ctx)
[deoplete] File "/Users/nhooyr/.cache/dein/repos/github.com/zchee/deoplete-go/rplugin/python3/deoplete/sources/deoplete_go.py", line 135, in gather_candidates
[deoplete] return self.cgo_completion(self.buffer)
[deoplete] File "/Users/nhooyr/.cache/dein/repos/github.com/zchee/deoplete-go/rplugin/python3/deoplete/sources/deoplete_go.py", line 202, in cgo_completion
[deoplete] self.cgo_inline_source
[deoplete] File "/Users/nhooyr/.cache/dein/repos/github.com/zchee/deoplete-go/rplugin/python3/deoplete/sources/deoplete_go/cgo.py", line 100, in complete
[deoplete] fname, cgo_flags, unsaved_files=files, options=options
[deoplete] File "/Users/nhooyr/.cache/dein/repos/github.com/zchee/deoplete-go/rplugin/python3/deoplete/clang/clang/cindex.py", line 2322, in parse
[deoplete] self)
[deoplete] File "/Users/nhooyr/.cache/dein/repos/github.com/zchee/deoplete-go/rplugin/python3/deoplete/clang/clang/cindex.py", line 2440, in from_source
[deoplete] raise TranslationUnitLoadError("Error parsing translation unit.")
[deoplete] clang.cindex.TranslationUnitLoadError: Error parsing translation unit.
[deoplete] Could not get completions from: go. Use :messages for error details.
zchee commented
@nhooyr Sorry for the delay.
I was hardcoded clang -x
flag to c
at
https://github.com/zchee/deoplete-go/blob/master/rplugin/python3/deoplete/sources/deoplete_go/cgo.py#L78
So, maybe caused by can't parses -x objective-c
(or duplicate -x
flag).
But it is just impression of seeing the sample code. I have not tested it. will debug it.
Thanks!
zchee commented
nhooyr commented
Works now, thanks!