Giter Club home page Giter Club logo

merlin's Introduction

merlin completion in vim

Merlin is an editor service that provides modern IDE features for OCaml.

Emacs and Vim support is provided out-of-the-box. To get editor support with Merlin in other editors, see this.

Easy Installation With opam

If you have a working opam installation, install Merlin running the following two commands in terminal:

opam install merlin
opam user-setup install

opam-user-setup takes care of configuring Emacs and Vim to make best use of your current install. You can also configure the editor yourself, if you prefer.

Manually Building and Installing Merlin

Since version 4.0, Merlin's repository has a dedicated branch for each version of OCaml, and the branch name consists of the concatenation of OCaml major versions and minor versions. So, for instance, OCaml 4.11.* maps to branch 411. The main branch is usually synchronised with the branch compatible with the latest (almost-)released version of OCaml.

Note: if you're using an older version of OCaml (between 4.02 and 4.10), you will want to build the 3.4 branch, although it won't contain the most recent features.

Compilation

Dependencies: ocamlfind, yojson >= 2.0.0, dune >= 2.7.

dune build -p dot-merlin-reader,merlin

Note: if you want to work on Merlin, you'll want to avoid the -p merlin to build in dev mode, with some extra warnings enabled. In that case, you'll also need an extra dependency: Menhir. We recommend that you pin it to version 20201216 which was used to generate the parser currently present in the sources.

opam pin menhir 20201216

Installation

If you haven't encountered any errors in the previous step, just run:

dune install -p dot-merlin-reader,merlin

You can pass an explicit prefix to Dune, using --prefix. It defaults to your current opam switch.

Editor Setup

To set up Emacs and Vim, you need to instruct them to run the appropriate script when an OCaml file is opened.

In the rest of the document, <SHARE_DIR> refers to the directory where Merlin data files are installed.

It will usually be:

  • printed by the command opam var share, if you used opam
  • "<prefix>/share" if you explicitly specified a prefix when configuring Merlin

Vim Setup

Makes sure that ocamlmerlin binary can be found in PATH.

The only setup needed is to have the following directory in the Vim runtime path (append this to your .vimrc):

:set rtp+=<SHARE_DIR>/merlin/vim

The default configuration can be seen in:

<SHARE_DIR>/merlin/vim/plugin/merlin.vim

After adding Merlin to Vim's runtime path, you will probably want to run :helptags <SHARE_DIR>/merlin/vim/doc to register Merlin documentation inside Vim.

A more comprehensive documentation can be found on the vim-from-scratch wiki.

Emacs Setup

Manual Setup

Merlin comes with an Emacs library (file: emacs/merlin.el) that implements a minor-mode that is supposed to be used on top of tuareg-mode.

Just add the following to your .emacs file:

(push "<SHARE_DIR>/emacs/site-lisp" load-path) ; directory containing merlin.el
(setq merlin-command "<BIN_DIR>/ocamlmerlin")  ; needed only if ocamlmerlin not already in your PATH
(autoload 'merlin-mode "merlin" "Merlin mode" t)
(add-hook 'tuareg-mode-hook #'merlin-mode)
(add-hook 'caml-mode-hook #'merlin-mode)
;; Uncomment these lines if you want to enable integration with the corresponding packages
;; (require 'merlin-iedit)       ; iedit.el editing of occurrences
;; (require 'merlin-company)     ; company.el completion
;; (require 'merlin-ac)          ; auto-complete.el completion
;; To easily change opam switches and pick the ocamlmerlin binary accordingly,
;; you can use the minor mode https://github.com/ProofGeneral/opam-switch-mode

More comprehensive documentation can be found on the emacs-from-scratch wiki.

Setup via package.el

An installable core Merlin package is available via MELPA, along with further small integration packages merlin-company, merlin-iedit, and merlin-ac, which users can install according to their needs.

Having installed the required packages, the following code in your Emacs startup file is sufficient:

(setq merlin-command "<BIN_DIR>/ocamlmerlin")  ; needed only if ocamlmerlin not already in your PATH
(add-hook 'tuareg-mode-hook #'merlin-mode)
(add-hook 'caml-mode-hook #'merlin-mode)
;; Uncomment these lines if you want to enable integration with the corresponding packages
;; (require 'merlin-iedit)       ; iedit.el editing of occurrences
;; (require 'merlin-company)     ; company.el completion
;; (require 'merlin-ac)          ; auto-complete.el completion
;; To easily change opam switches and pick the ocamlmerlin binary accordingly,
;; you can use the minor mode https://github.com/ProofGeneral/opam-switch-mode

Other Editors

Merlin only supports Vim and Emacs out-of-the-box. This section describes shortly how to get Merlin-based editor support in other editors.

Visual Studio Code

OCaml has official support for Visual Studio Code through an extension called "OCaml Platform," available in the Visual Studio Marketplace. Project source is available here. Note that it requires OCaml-LSP, an official Language Server Protocol(LSP) implementation for OCaml based on Merlin. It can be installed by running opam install ocaml-lsp-server.

Editors Without Official Support

Consider using OCaml-LSP along with your editor's plugin for LSP if there is one.

The wiki also contains pages for:

External contributors have implemented modes for more editors:

Merlin as a library

Merlin can also be used as a library. Some projects already rely on this:

  • OCaml LSP - The official OCaml's Language Server Protocol implementation

If you're building editor tools, you might also want to use Merlin as a library!

Note, however, that Merlin's public API is not stable, and we don't guarantee backward-compatibility between releases. If you're a Merlin user and depend on our public API, we recommend that you contact us or open an issue.

Next Steps

To use Merlin with a multi-file project, it is necessary to have a .merlin file, unless your project is built using Dune. Note that, in a project using Dune, user-created .merlin files will take precedence over the configuration provided by Dune to Merlin.

Read more in the wiki to learn how to make full use of Merlin in your projects.

Development of Merlin

Most of the development happens through the GitHub page.

The mailing list welcomes general questions and discussions.

Merlin Labels

Area/Emacs: Related to Emacs

Area/Vim: Related to Vim

Kind/Bug: This issue describes a problem.

Kind/Docs: This issue describes a documentation change.

Kind/Feature-Request: Solving this issue requires implementing a new feature.

Kind/To-discuss: Discussion needed to converge on a solution, often aesthetic. See mailing list for discussion.

Status/0-More-info-needed: More information is needed before this issue can be triaged.

Status/0-Triage: This issue needs triaging.

Status/1-Acknowledged: This issue has been triaged and is being investigated.

Status/2-Regression: Known workaround to be applied and tested.

Status/3-Fixed-need-test: This issue has been fixed and needs checking.

Status/4-Fixed: This issue has been fixed!

Status/5-Awaiting-feedback: This issue requires feedback on a previous fix.

You can see current areas of development in our Merlin Project Roadmaps that we keep up to date.

Contributing to Merlin

Merlin needs your help and contributions!

Reporting Issues

When you encounter an issue, please report it with as much detail as possible. A thorough bug report is always appreciated :)

Check that our issue database doesn't already include that problem/suggestion. You can click "subscribe" on issues to follow their progress and updates.

When reporting issues, please include:

  • Steps to reproduce the problem, if possible with some code triggering the issue
  • Version of the tools you are using: operating system, editor, OCaml

Try to be as specific as possible:

  • Avoid generic phrasing such as "doesn't work." Explain what is happening (editor is freezing, you got an error message, the answer is not what was expected, etc.).
  • Include the content of error messages if there are any.

If it seems relevant, also include information about your development environment:

  • The opam version and switch in use
  • Other toolchains involved (OCaml flavors, Cygwin, C compiler, shell, ...)
  • How the editor was setup

Pull Requests

Found a bug and know how to fix it? Or have a feature you can implement directly? We appreciate pull requests to improve Merlin. Please note: any significant fix should start life as an issue first.

Changelog

User-visible changes should come with an entry in the changelog under the appropriate part of the unreleased section. PR that doesn't provide an entry will fail CI check. This behavior can be overridden by using the "no changelog" label, which is used for changes that are not user-visible.

Documentation and Wiki

Help is greatly appreciated, the wiki needs love.

If the wiki didn't cover a topic and you found out the answer, updating the page or pointing out the issue will be very useful for future users.

Discussing With Other Merlin Users and Contributors

Together with commenting on issues with direct feedback and relevant information, we use the mailing list to discuss ideas and current designs/implementations. User input helps us to converge on solutions, especially those for aesthetic and user-oriented topics.

List of Contributors

We would like to thank all people who contributed to Merlin.

Main collaborators:

Contributors:

Sponsoring and Donations

We would like to thank Jane Street for sponsoring and OCaml Labs for providing support and management.

And many thanks to our Bountysource backers.

Other Acknowledgements

Distribution and configuration:

Support for other editors:

merlin's People

Contributors

3rafal avatar andreypopp avatar antalsz avatar art-w avatar asmanur avatar bcc32 avatar copy avatar dra27 avatar gasche avatar gpetiot avatar gsg avatar jonahbeckford avatar julow avatar khady avatar kit-ty-kate avatar lehy-probayes avatar let-def avatar liam923 avatar lpw25 avatar mattiase avatar misterda avatar nojb avatar pitag-ha avatar purcell avatar rgrinberg avatar trefis avatar ulugbekna avatar voodoos avatar wilfred avatar xvw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

merlin's Issues

merlin-locate often fails.

I am adding this issue just for tracking. This is a bug that I have shown to Thomas a few times.

One can ask merlin to auto-complete something following which if one were to ask merlin to jump to the location of the completed thing, it is unable to do so. It is unclear why it is unable to do that.

Have some debug information or error message such that one is able to do that. One approach to doing this is to have better debug information printed out into the debug file when MERLIN_LOG is enabled.

Opam build failure: menhirLib not found

opam install merlin fails with:

./configure --prefix /Users/gbarnett/.opam/system
make
make install
The compilation of merlin.1.0 failed.
Uninstalling merlin.1.0:
make uninstall

==== ERROR [while installing merlin.1.0] ====

opam-version 1.0.0

os darwin

command make

path /Users/gbarnett/.opam/system/build/merlin.1.0

exit-code 2

env-file /Users/gbarnett/.opam/system/build/merlin.1.0/merlin-1872ec.env

stdout-file /Users/gbarnett/.opam/system/build/merlin.1.0/merlin-1872ec.out

stderr-file /Users/gbarnett/.opam/system/build/merlin.1.0/merlin-1872ec.err

stdout

ocamlbuild -Is .,typing,parsing,utils -use-ocamlfind ocamlmerlin.native
/usr/local/bin/ocamlfind ocamlopt -I /usr/local/lib/ocaml/ocamlbuild unix.cmxa /usr/local/lib/ocaml/ocamlbuild/ocamlbuildlib.cmxa myocamlbuild_config.ml myocamlbuild.ml /usr/local/lib/ocaml/ocamlbuild/ocamlbuild.cmx -o myocamlbuild
/usr/local/bin/ocamlfind ocamldep -package menhirLib -package yojson -package findlib -modules ocamlmerlin.ml > ocamlmerlin.ml.depends

  • /usr/local/bin/ocamlfind ocamldep -package menhirLib -package yojson -package findlib -modules ocamlmerlin.ml > ocamlmerlin.ml.depends
    ocamlfind: Package `menhirLib' not found
    Command exited with code 2.

    stderr

    make: *** [ocamlmerlin.native] Error 10

Broken pipe

Merlin's pipe seems to get broken sometimes in vim. Specifically, if I run a command and then use Ctrl-C, that seems to mess up the plugin's state, and there's no way to get it back unless I restart vim.

Example to reproduce:
:!man ls
Press Ctrl-C
q (enter)
:e

Merlin should now complain about a broken pipe.

Better understanding of camlp4 extensions

merlin needs to understand camlp4 extensions. For instance, things fail in the presence of units tests where we have a "TEST =" syntax provided by pa_ounit. Soon we will have simialr extensions for micro-benchmarks.

For now, maybe one can hack in the commonly used syntax extensions. In the long term we need a better solution for this.

Global API search

Consider building a global API search. Merlin has all of the infrastructure required for this. TBD.

[emacs] feature: have merlin-show-type-at-point pick enclosing expressions, not just identifiers

caml-mode's caml-types-show-type (code here) picks the smallest expression around the point, rather than only supporting identifiers, and uses an overlay to make it visually clear of which subexpression the type is being displayed. In the example:

let test = (List.length [])

I expect C-c C-t to work when called on the leftmost parenthesis (highlight the expression and return "int") and on either braces of the empty list (highlight [] and return '_a list).

The larger point is that I expect merlin's C-c C-t to have the same feature set than caml-mode's C-c C-t command, because I don't want as an user to have to remember which one to use depending on whether I'm doing incremental checking or reading an -annot-compiled source file. I understand that some features may be painful to implement just from the typer output (eg. handling of weak polymoprhic variables as demonstrated with the empty list here), but at least the best-subexpression logic could be reused.

Unclosed comment

Lexer doesn't report unclosed / unterminated string and comments.

Support for future OCaml versions (4.01+dev for now)

Given that Merlin currently reuses and modifies part of the OCaml implementation, it is not portable across different OCaml versions. In particular, Merlin currently does not support the development version of OCaml, presently named 4.01.0+dev (in prevision for a 4.01 release in the short- to medium-term).

After the release, several different OCaml versions will be used by Merlin users, and it would be interesting to consider the implications of this in advance, instead of lagging behind a release.

  • what can go wrong if one uses 4.00-merlin with 4.01+dev?
  • what's the amount of work involved in producing a 4.01-merlin?
  • what can go wrong if one used 4.01-merlin with 4.00 source code?
  • could we have mechanisms to detect incompatible-versions situations and report them cleanly to the users, instead of just going wrong?
  • can Merlin support several versions of OCaml?

I would be personally interested in these questions (regularly having to work in an environment using development versions of OCaml), and I think they should be documented for all users in prevision for the next release.

Given the strong backward-compatibility requirements that the OCaml language imposes upon itself, I believe it should be possibly to always use the parser and type-checker of the most recent OCaml release, even for users working on code intended for older versions. Library support is however a very different question.

(PS: I categorizes this as both a "bug" and an "enhancement", because while extending Merlin to support 4.01 is a feature, the way Merlin may degrade when used on non-intended versions of OCaml is likely to be considered a bug by users.)

Various cleanups and support for completion-at-point

I recommend you try to byte-compile your file (especially with a recent enough Emacs), it will give you various warnings that are worth fixing. You can also use C-u M-x checkdoc-current-buffer to get some style recommendations (not to be obeyed blindly, but still worthwhile).

I have a patch which fixes most of those issues and adds preliminary support for completion-at-point-functions, contact me via email [email protected] if you're interested.

Different behavior from various completion modes

Often auto-complete provided by the auto-complete-mode and completion-at-point (which I think ships with emacs) behave differently. i.e. one refuses to show completion results while the other does.

It is unclear why this and is hard to reproduce. One possibility is that this maybe do the fact that different modes are sending different queries to merlin. It would be good to have debug information displayed such that one can understand why completion-at-point and auto-complete behave differently.

This sort of information might also help towards building a better auto-complete mode one day that is more customized for merlin.

[emacs] merlin-to-point should send more input to avoid false errors

The behavior of merlin-to-point is not consistent with what most users expect from experience with ProofGeneral, CoqIde, or even Caml Light or Ocaml toplevel GUIs with a "send command" option. Consider the given code:

let id (*POINT*) x = x

If I put my cursor on the comment and call C-x C-Enter, Merlin will send "let id" to the parser, resulting in a "Parse Error" that is very confusing. The behavior I expect is to send the whole phrase and succeed.

How much exactly should Merlin send? Consider the following input:

module M = struct
  let id (* POINT *) x =
    x
  let foo x = x
end

The behavior of tuareg-eval-phrase, which would be the Tuareg equivalent, is to send the smallest enclosing phrase/structure item to the toplevel, here let id x = x. The behavior of Proof General would be to send the smallest correct prefix of the whole buffer at or after the point, that is module M = struct let id x = x.

Note that merlin-check-synchronize, that is run at idle times, has a heuristic to send the whole line rather than just upto the point (it behaves much better than merlin-to-point for one-liner phrases). I intentionally defeated it here by splitting id in two lines.

The behavior I expect is ProofGeneral's one: send the shortest prefix at or after the point that the incremental parser and type-checker can manage.

N.B.: familiarity with the ProofGeneral (or CoqIde) interface is an excellent way to feel immediately familiar with Merlin's mode of action. If I want to pitch Merlin to people, I just say "it's ProofGeneral for OCaml", and they are interested. When in doubt over how an interface action should behave, I would suggest to follow that similarity and imitate its behavior.

Merlin 1.0.0 under emacs errors

contents of Messages as follows

Parsing .merlin file /home/thelema/tcam/.merlin
File mode specification error: (wrong-type-argument number-or-marker-p nil)
Toggling auto-complete-mode off; better pass an explicit argument.
Parsing .merlin file /home/thelema/tcam/.merlin
if: Wrong type argument: number-or-marker-p, nil

The result seems to be that I get no contextual completion, just any string it can find with the same prefix.

emacs: errors about auto-complete

I do not have the auto-complete package and merlin.el complains a bit:

--- /home/oandrieu/Downloads/merlin.el  2013-02-21 11:16:47.391076941 +0100
+++ /home/oandrieu/.opam/system/share/emacs/site-lisp/merlin.el 2013-02-21 11:09:54.597652168 +0100
@@ -419,7 +419,8 @@
     (requires . 3)
     ))

-(ac-define-source "merlin" merlin-ac-source)
+(when (featurep 'auto-complete)
+  (ac-define-source "merlin" merlin-ac-source))

 ;; Get the type of an element"
 (defun merlin-trim (s)
@@ -584,7 +585,8 @@
   (interactive)
   (progn
     (merlin-start-process)
-    (auto-complete-mode)
+    (when (featurep 'auto-complete)
+      (auto-complete-mode))
     (set (make-local-variable 'merlin-lock-point) (point-min))
     (set (make-local-variable 'merlin-buffer) nil)
     (set (make-local-variable 'merlin-result) nil)

[emacs] Don't override `ac-sources`

How about just add merlin-ac-source to ac-sources, instead of overriding using setq? My personal sources is ruined after loading merlin-mode.

diff --git a/emacs/merlin.el b/emacs/merlin.el
index b007f8a..a9212b1 100644
--- a/emacs/merlin.el
+++ b/emacs/merlin.el
@@ -743,7 +743,8 @@ it will print types of bigger expressions around point (it will go up the ast).
   (progn
     (merlin-start-process)
     (when (featurep 'auto-complete)
-      (auto-complete-mode))
+      (auto-complete-mode)
+      (add-to-list 'ac-sources 'merlin-ac-source))
     (set (make-local-variable 'merlin-lock-point) (point-min))
     (set (make-local-variable 'merlin-buffer) nil)
     (set (make-local-variable 'merlin-result) nil)
@@ -761,7 +762,6 @@ it will print types of bigger expressions around point (it will go up the ast).
     (set (make-local-variable 'merlin-enclosing-types) nil)
     (set (make-local-variable 'merlin-enclosing-offset) nil)
     (set (make-local-variable 'merlin-last-point-type) nil)
-    (setq ac-sources '(merlin-ac-source))
     (add-to-list 'after-change-functions 'merlin-edit)
     (set-process-query-on-exit-flag (merlin-get-process) nil)
     (merlin-parse)

In emacs, .merlin is read per buffer

When resuming an emacs session, it takes about a second for each .merlin file to be loaded, and this happens for every file in my project. Is there a way to avoid duplicating this work and/or speed up .merlin parsing?

Vim question

Hi,

I installed merlin, neocomplcache.

Merlin works in the sense that the Type* commands work.
However the type does not appear in the completions. What may have I forgotten ?

Thanks in advance!

Specify license, make original ocaml code explicit

I am thinking of MIT license. However now that I am not the only author, your advice and opinions are welcome :).

Also, it would be really nice to clarify license of original Ocaml code and satisfy QPL2 requirements. What should be done in this respect ?

Flag to include current directory

Often one wants to refer to ml and mli files from the current directory. Instead of always adding the current directory to the .merlin file, add a flag to merlin such that the current directory is included as a source directory.

Merlin refuses to refresh a module sometimes

I understand that this bug report is a little vague and hence not very useful but merlin sometimes gets into this state where it won't reload changes I've made to a particular module even though my code will compile cleanly. I.e. it will not:

  • Suggest new functions added to a module past the stage when it gets stuck
  • Will not pass the syntax check for my code (complaining about missing functions from that module)

Doing a clean rebuild of the project does not help this either. The only thing that helps is restarting vim.

I have absolutely no clue how to reproduce this reliably or what the problem could be but a :MerlinReload command that would restart the ocamlmerlin process would be a welcome addition.

Again I'm sorry for the useless bug report...

Filter on types in the emacs mode

In the emacs mode, currently filtering the dropdown only works for filtering on the identifier. Filtering on the identifier is the right default, but it would be nice if one could filter on the type also.

emacs: error in timer

Error in timer: (wrong-type-argument integer-or-marker-p nil)
Error in timer: (wrong-type-argument symbolp #)

Under emacs 24.3.50.1 (with auto-complete and using tuareg mode), I get a lot of the aforementioned error messages. Is there anything I can do to turn them off ?

Showing documentation comments

Can you scrape off the documentation comments that precede most function definitions in mli files and show these in some way -- maybe as a help tooltip.

More information in the dropdown.

Again this applies to using merlin via auto-complete-mode in emacs.

If the dropdown cannot show the whole type in the case of long types (auto complete of Async.Pipe as an example), one could have the type show up in the command buffer below. One could also show the whole type in a help tooltip. I believe auto-complete-mode has some support for help tooltips.

Syntax check dies on camlp4 quotes

I realize that that parsing camlp4 is way beyond the scope of the project but it would be nice if the syntax check failed on camlp4 a little more gracefully. For example if you use sexplib you often do something like: <:sexp_of< exn * _ t >> to get the sexp of an exception. Would be nice if this wasn't a syntax error. Maybe treat the p4 quotes like wild cards. Like failwith "" for example.

merlin type checks bad code with syntastic

Enter the following code in a buffer and a top level:

module type Foo = sig 
  type t
  val do_with_t : t -> unit
end

let any_foo t (module F : Foo) = F.do_with_t t <-- make sure no new line but end of file

Observe that the top level rejects this but merlin accepts this (at least in vim) ONLY IF there is no new line at the end of the offending statement. It's likely that it's possible to reproduce this bug with another example as well.

completion for record fields

Simple example :

type t = { x : int ; y : char }

let get_x (a : t) = a.<tab>

I would love to have x and y proposed.

emacs: location of .merlin file

The documentation in the README says that the .merlin file can be in a parent directory but apparently the emacs mode only looks for it in the current directory.

Here's a patch that attempts to address this (a bit clumsily perhaps).

--- merlin.el.orig  2013-04-03 16:10:10.689107540 +0200
+++ merlin.el   2013-04-03 12:03:03.766380582 +0200
@@ -662,8 +662,10 @@
           ))))

 ;; .merlin parsing
-(defun merlin-add-path (kind dir)
+(defun merlin-add-path (kind dir dirname)
   "Adds an item to a path in merlin"
+  (if (and dirname (not (file-name-absolute-p dir)))
+      (setq dir (concat dirname dir)))
   (merlin-send-command "path" (list "add" kind dir)))

 (defun merlin-get-packages ()
@@ -676,26 +678,32 @@
    (list (completing-read "Package to use:" (merlin-get-packages))))
   (merlin-send-command "find" (list "use" pkg)))

-(defun merlin-handle-line (buffer words)
+(defun merlin-handle-line (buffer words dirname)
   "Handles a line in a .merlin file"
   (with-current-buffer buffer
     (cond
-     ((string-equal (elt words 0) "S") (merlin-add-path "source" (elt words 1)))
-     ((string-equal (elt words 0) "B") (merlin-add-path "build" (elt words 1)))
+     ((string-equal (elt words 0) "S") (merlin-add-path "source" (elt words 1) dirname))
+     ((string-equal (elt words 0) "B") (merlin-add-path "build" (elt words 1) dirname))
      ((string-equal (elt words 0) "PKG") (merlin-use (elt words 1))))))
+(defun merlin-file-parse (fname)
+  "Parses a .merlin"
+  (message "Parsing %s" fname)
+  (setq lines nil)
+  (setq buf (current-buffer))
+  (let ((dirname (file-name-directory fname)))
+    (with-current-buffer (find-file fname)
+      (goto-char (point-min))
+      (while (not (eq (point) (point-max)))
+        (let ((words (split-string (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
+          (merlin-handle-line buf words dirname)
+          (forward-line))))
+    (switch-to-buffer buf)))
 (defun merlin-parse ()
   "Parses a .merlin"
-  (if (file-exists-p ".merlin")
-      (progn
-   (setq lines nil)
-   (setq buf (current-buffer))
-   (with-current-buffer (find-file ".merlin")
-     (goto-char (point-min))
-     (while (not (eq (point) (point-max)))
-       (let ((words (split-string (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
-         (merlin-handle-line buf words)
-         (forward-line))))
-   (switch-to-buffer buf))))
+  (cond
+   ((file-exists-p ".merlin")       (merlin-file-parse ".merlin"))
+   ((file-exists-p "../.merlin")    (merlin-file-parse "../.merlin"))
+   ((file-exists-p "../../.merlin") (merlin-file-parse "../../.merlin"))))

 ;; Idle 
 (defun merlin-idle-hook ()

Understanding the context of the cursor point

One day merlin should understand the context of the point better. More specifically it should know if:

  1. One is editing a type or an expression.

  2. The local scope of the expression. Offer locally bound variables
    in the expression.

  3. It would also be great it the type at the current point guided
    what expansion results were offered. I'd imagine that one would
    want both -- one sort of expansion that took the type of the point
    into account and one that did not.

compilation fails on openbsd

Fairly minor error in the install target due to a missing -d flag in the OpenBSD install command.

==== ERROR [while installing merlin.1.1] ====
# opam-version    1.0.1 (df84b0565f0709578c581c1dea82246688d2804f)
# os              openbsd
# command         gmake install
# path            /tmp/ocamlot/ocamlot.work.2013-06-25.74/opam-install/system/build/merlin.1.1
# compiler        system (4.01.0)
# exit-code       2
# env-file        /tmp/ocamlot/ocamlot.work.2013-06-25.74/opam-install/system/build/merlin.1.1/merlin-11568-d4902a.env
# stdout-file     /tmp/ocamlot/ocamlot.work.2013-06-25.74/opam-install/system/build/merlin.1.1/merlin-11568-d4902a.out
# stderr-file     /tmp/ocamlot/ocamlot.work.2013-06-25.74/opam-install/system/build/merlin.1.1/merlin-11568-d4902a.err
### stdout ###
ocamlbuild -Is src,src/typing,src/parsing,src/utils -use-ocamlfind ocamlmerlin.native
install -dv /tmp/ocamlot/ocamlot.work.2013-06-25.74/opam-install/system/bin
### stderr ###
install: unknown option -- v
usage: install [-bCcdpSs] [-B suffix] [-f flags] [-g group] [-m mode] [-o owner]
           source ... target ...
gmake: *** [install] Error 64

'opam install --verbose --yes merlin.1.1' failed.

OCAMLOT After 814.23s Opam_task.run "opam install --verbose --yes merlin.1.1" failed (4) in 334.80s

Sigs show up as modules.

It would be nice to see what is inside a sig such as a Floatable. Similarly it would be nice to see what is produced by a functor.

Errors in .mli files

The parser does not recognize that the file is a .mli, so it signals lots of errors that are in fact correct.

Formatting misaligned dropdowns.

When using merlin with auto-complete-mode in emacs, the dropdowns are often broken.

One way to fix the problem may be to have a configuarble lenght variable set in merlin mode. Subsequently merlin will should not send completion candidates that are longer that than the specified length.

C-c C-RET not working with in-term emacs

If I launch emacs with the -nw option (what I most always do), C-c C-RET is not working in Merlin. In fact, the minibuffer displays "C-c RET is undefined".

Thus I'm not sure if it is a merlin-related issue, or something wrong with my terminal (urxvt).
Any hint on why my C-RET is interpreted as a RET ?

vimbufsync cannot be installed

Running make install gives:

cp -R vim/merlin/* /usr/local/share/ocamlmerlin/vim/
cp -R vim/vimbufsync/* /usr/local/share/ocamlmerlin/vimbufsync/
cp: cannot stat ‘vim/vimbufsync/*’: No such file or directory

Also running submodule_sync.sh doesn't do anything.

EDIT: nvm had a dirty repository for some reason, ignore :)

incorrect imports in packed modules

If I have a subdirectory Bar/ with files a.ml and b.ml, that are to be packed into Bar.A and Bar.B, and B tries to use values from A, merlin fails to find A. Here is an archive which should demonstrate it:

$ cd test/
$ ocamlbuild foo.native
... ok...
$ vim bar/b.ml
[ask for the type of A.f returns an error]

autocomplete very slows, keeps setting the mark

When I try to autocomplete, it takes several seconds between the moment I choose a completion and the moment it is inserted. During that time, the minibuffer keeps flashing with messages. Here is what they are:

point: 373 start! 373
Mark set [2 times]
point: 387 start! 373
Mark set [2 times]
point: 396 start! 396
Mark set [2 times]
point: 395 start! 395
Mark set [2 times]
point: 394 start! 394
Mark set [2 times]
point: 393 start! 393
Mark set [2 times]
point: 392 start! 392
Mark set [2 times]
point: 391 start! 391
Mark set [2 times]
point: 390 start! 390
Mark set [2 times]
point: 389 start! 389
Mark set [2 times]
point: 388 start! 388
Mark set [4 times]

I'm using the opam installed version of Merlin.

Paths in .merlin file

Any path that goes higher than .., for example ../../bin, is misunderstood by merlin. The ..s are skipped and the path is appended to the current path. This is a real problem because merlin only goes up 2 directories to find the .merlin file. In a deep directory structure, ocamlbuild will place all the built files in a completely different hierarchy.

Ideally, one would also be able to set how high up in the tree merlin should look for the .merlin file. Still, the ../../ parsing issue should be fixed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.