ocaml / merlin

Context sensitive completion for OCaml in Vim and Emacs
https://ocaml.github.io/merlin/
MIT License
1.58k stars 233 forks source link

problems: not quite out-of-the-box but almost... #840

Closed houndofsound closed 5 years ago

houndofsound commented 6 years ago

I am having a go with merlin after patching the emacs client for cygwin under XP (emacs 24.5.1, ocaml 4.06.1 though opam) and running out-of-the-box in every other way have encountered some problems:

o introducing any deliberate error then saving yields 'no error' output through status window

from the log: ((assoc) (class . "return") (value) (notifications) (timing (assoc) (total . 32.) (query . 16.) (reader . 0.) (ppx . 0.) (typer . 16.) (error . 0.)))

o with the cursor over an identifier that is defined elsewhere in the same file and running 'merlin-type-enclosing' yields no response but highlighting constant expressions such as ints works, still no identifiers from the file or arguments to functions, standard library definitions etc...

from the log: same as above

o completion-at-point works but auto completion works only if I run auto-completion-mode (getting AC in the mode line), this despite having (setq merlin-ac-setup 'easy) in my .emacs

o merlin-locate yields "not a valid identifier" for an ident defined in the same file

from the log: ((assoc) (class . "return") (value . "Not a valid identifier") (notifications) (timing (assoc) (total . 31.) (query . 16.) (reader . 0.) (ppx . 0.) (typer . 15.) (error . 0.)))

my understanding is that for the source file being edited/viewed, merlin can use the source directly without need of -bin-annot, and needs -bin-annot for external identifiers only. since the source I am testing on is a merlin ml file that is known to be correct, I don't understand why the above functionality is faulty/missing.

any guidance welcome!

about a mentioned 'power guide' - is this the wiki?

let-def commented 6 years ago

What is your patch? How are you sending the content of the file from emacs?

Given the behavior your describe, it seems that merlin don't have access to the source code and analyze an empty file.

houndofsound commented 6 years ago

the auto AC invocation came with (setq merlin-ac-setup 'easy) put in the .emacs. the docs gave the impression of something immediately happening if the above was evaluated (C-x C-e style?).

the content of the file from emacs? I assumed it was transferring messages containing file name & locations to the server only. here's the patch:

*** src/platform/os_ipc_stub.c  2018-06-14 20:39:13.776750000 +0100
--- /cygdrive/e/tmp/merlin2/src/platform/os_ipc_stub.c  2018-07-16 11:16:30.344250000 +0100
***************
*** 118,123 ****
--- 118,129 ----
      }
    }

+ #ifdef __CYGWIN__
+   fds[0]=-1;
+   fds[1]=fd; //use the client socket
+   fds[2]=-1;
+ #else
+ 
    struct cmsghdr *cm = CMSG_FIRSTHDR(&msg);

    int *fds0 = (int*)CMSG_DATA(cm);
***************
*** 135,140 ****
--- 141,147 ----
    fds[0] = fds0[0];
    fds[1] = fds0[1];
    fds[2] = fds0[2];
+ #endif

    return recvd;
  }
*** src/frontend/ocamlmerlin.c  2018-06-26 02:18:28.937500000 +0100
--- /cygdrive/e/tmp/merlin2/src/frontend/ocamlmerlin.c  2018-07-14 18:43:22.532181700 +0100
***************
*** 623,630 ****
--- 623,669 ----
      if (ReadFile(sock, &result, 1, &dwNumberOfBytesRead, NULL) && dwNumberOfBytesRead == 1)
        err = 1;
  #else
+ #ifdef __CYGWIN__
+ 
+     char buf[2^10];
+     int res,resc,r;
+ 
+     //for one result normally then a retcode but their messages might be merged
+     do{
+       NO_EINTR(res, recv(sock, buf, sizeof(buf),0));
+       //something always expected here
+       if(res<0) unexpected_termination(argc, argv);//failwith_perror("CLIENT READ RESULT");
+ 
+       resc=res;//in case must reduce msg length for printing when retcode appended
+ 
+       //check whether more to come
+       NO_EINTR(r, recv(sock, NULL,0,MSG_DONTWAIT | MSG_PEEK));
+       //if 0 its the end (server terminated) and if -1 its the end too (server still up)
+       if(r<=0){//no data pending
+         if(r==-1 && errno!=EAGAIN && errno!=EWOULDBLOCK)
+           failwith_perror("CLIENT READ CHECK");
+         //message received in entirety so check for retcode
+         if(buf[res-1] < 10)//hack! assuming server response only contains characters 10 and above
+           res--;
+       }
+       //relay to emacs and loop round for the next read
+       ssize_t sent=0,sent_;
+       while (sent < res){
+         NO_EINTR(sent_,fwrite(buf + sent, 1,res - sent, stdout));
+         if (sent_ == -1)
+           failwith_perror("CLIENT READ TRANSCRIBE");
+         sent += sent_;
+       }
+ 
+       if(res<resc)//retcode detected, return it
+         exit(buf[res]);
+ 
+     }while(1);
+ 
+ #else
      NO_EINTR(err, read(sock, &result, 1));
  #endif
+ #endif
      if (err == 1)
        exit(result);
houndofsound commented 6 years ago

bump

let-def commented 6 years ago

The content of the file is sent on stdin. With this patch, stdin gets set to -1 and the contents of the file is never sent to the server. A workaround would be to change the protocol a bit and stream the contents of the file on the client fd.

houndofsound commented 6 years ago

ah, I assumed everything went in the initial message. thanks!

let-def commented 5 years ago

We won't have the time to fix cygwin support in the near future. Sorry.