Code Monkey home page Code Monkey logo

vim-ocaml's Introduction

vim-ocaml

Vim runtime files for OCaml. These are synced periodically with the builtin support that comes with Vim. Users are recommended to use this repository directly however as it's more up to date.

Installation

Depending on your plugin manager:

Plugin 'ocaml/vim-ocaml'
NeoBundleInstall ocaml/vim-ocaml'

" or use NeoBundleLazy
NeoBundleLazy 'rgrinberg/vim-ocaml', {'autoload' : {'filetypes' :
    \ ['ocaml', 'dune', 'opam', 'oasis', 'omake', 'ocamlbuild_tags', 'sexplib']}}

History

This repo started out by @rgrinberg extracting Markus Mottl's improvements to the builtin OCaml support in Vim. Later, support for more OCaml related tools was added: dune, opam etc. Nowadays, it's maintained by a team.

vim-ocaml's People

Contributors

andreypopp avatar anmonteiro avatar c-cube avatar copy avatar dkearns avatar dundargoc avatar einars avatar emillon avatar fccm avatar hcarty avatar hogeyama avatar julow avatar jyc avatar maelan avatar mikaello avatar mmottl avatar paurkedal avatar psafont avatar rgrinberg avatar rjbou avatar seliopou avatar selliera avatar shym avatar silenc3r avatar talex5 avatar tomtomjhj avatar trefis avatar verbosemode avatar xvilka 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

Watchers

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

vim-ocaml's Issues

do not always indent after `->`

Line 103 of indent there seems to be a test for lines ending with ->, such as those found in .mli file for long signatures.

I tend to indent like this:

val f :
  foo ->
  bar ->
  baaz

but vim really wants me to indent after each arrow. Is it possible to add a configuration flag for toggling this behavior?

Provide the plugin to check the updates in the opam file

To be able to see available new versions of your dependencies. Good example on how it can be handled is Rust "crates" plugin:

https://marketplace.visualstudio.com/items?itemName=serayuzgur.crates

This is "crates", an extension for crates.io dependencies. Aims helping developers to manage dependencies while using Cargo.toml.

Features:

  • Displays the latest version of the crate next to it
  • Shows all versions (clickable) on tooltip of the crate hovered.

Would be nice to have the similar feature in this vim plugin as well, when opening opam file.

Update Single Dependency

image

Update All Dependencies (lazy mode)

image

The example Vim plugin is here: https://github.com/mhinz/vim-crates

image

Highlight types based on syntax

Currently there's a hard-coded list of built-in type names that are highlighted specially even when the name is used as an identifier. Custom type names, on the other hand, are not highlighted.

See:

screenshot_2016-07-08_00-59-50

type foo = {
  a: int;
  b: bar;
}

let string = string_of_int

errorformat won't be valid for multiline errors after ocaml 4.09

I sent a change to the OCaml compiler to change the format of the error messages ocaml/ocaml#8541. It means that messages printed by OCaml >= 4.09 won't be parsed properly by this plugin.

The change affects the messages that are on multiple lines. The message now contains the first and last lines. Also the second part of the characters section is no longer a byte offset, it is the position on the last line.

Here is an exemple.

File "robustmatch.ml", lines 33-37, characters 6-23:
 9 | ......match t1, t2, x with
10 |       | AB, AB, A -> ()
11 |       | MAB, _, A -> ()
12 |       | _,  AB, B -> ()
13 |       | _, MAB, B -> ()
Warning 8: this pattern-matching is not exhaustive.
Here is an example of a case that is not matched:
(AB, MAB, A)

Tuareg has a list of compilation messages that can be used for reference: https://github.com/Chris00/tuareg/blob/master/compilation.txt

Parentice highlighting error in vim

Image and code attached with an example. I assume it's a rule in this file:

https://github.com/rgrinberg/vim-ocaml/blob/master/syntax/ocaml.vim

but I couldn't figure out myself.

Example

module type S = 
  sig
    type t
  end

module Make(T:S) = 
struct
  let const = 5
  module type Show =
    sig
      include S
      val show : t -> string
    end
end

module Make2(T:S) : S with type t = T.t =
struct
    type t = T.t
end

module Int = struct type t = int end

module T = Make(Make2(Int))

(* No parse errors *)
module Show1 : Make(Int).Show =
  struct
      include Int
      let show = string_of_int
  end

module Foo2 : module type of Make(Make2(Int)) = Make(Make2(Int))

let const = let module M = Make(Make2(Int)) in M.const

(* Shows parse error on last parentice *)
module Show2 : Make(Make2(Int)).Show =
  struct
      module type S = sig include Make(Make2(Int)).Show end
      include Int
      let show = string_of_int
  end

Dune: support comments that start with multiple semicolons

Add support for comments that start with multiple semicolons. Patch for ftplugin/dune.vim:

diff --git a/ftplugin/dune.vim b/ftplugin/dune.vim
index 86c99c0..2ef51a7 100644
--- a/ftplugin/dune.vim
+++ b/ftplugin/dune.vim
@@ -15,6 +15,6 @@ set lisp
 
 " Comment string
 setl commentstring=;\ %s
-setl comments=:;
+setl comments=n:;
 
 setl iskeyword+=#,?,.,/

A similar change may be appropriate for ftplugin/sexplib.vim as well.

lag in vim on saving .ml file

hi, recently i have noticed laggy behavior when editing a small to medium sized dune project in vim. i tried to debug it by using :profile start profile.log , profile func *. i then performed :w then i broke the last line in this function:

    let add_products config =
      let open Config in
      function
      | Empty  -> ()
      | Single m' -> add config m'
      | Pair (m',m'') -> (* inserted line break *)
        add config m'; add config m''

when i then :w again, i get a lag of a few seconds. my final profile.log has the following suspicious section:

FUNCTION  OMLetFoldLevel()
    Defined: ~/.vim/plugins/vim-ocaml/ftplugin/ocaml.vim:176
Called 23281 times
Total time:  17.862757
 Self time:   2.871963

count  total (s)   self (s)
                            
                              " This is for not merging blank lines around folds to them
23281              0.096067   if getline(a:l) !~ '\S'
  805              0.000996     return -1
22476              0.010256   endif
                            
                              " We start folds for modules, classes, and every toplevel definition
22476              0.242120   if getline(a:l) =~ '^\s*\%(\<val\>\|\<module\>\|\<class\>\|\<type\>\|\<method\>\|\<initializer\>\|\<inherit\>\|\<exception\>\|\<external\>\)'
  224              0.001100     exe 'return ">' (indent(a:l)/s:i)+1 '"'
22252              0.011305   endif
                            
                              " Toplevel let are detected thanks to the indentation
22252  15.161066   0.170272   if getline(a:l) =~ '^\s*let\>' && indent(a:l) == s:i+s:topindent(a:l)
 1238              0.007322     exe 'return ">' (indent(a:l)/s:i)+1 '"'
21014              0.010320   endif
                            
                              " We close fold on end which are associated to struct, sig or object.
                              " We use syntax information to do that.
21014              0.145205   if getline(a:l) =~ '^\s*end\>' && synIDattr(synID(a:l, indent(a:l)+1, 0), "name") != "ocamlKeyword"
   39              0.000091     return (indent(a:l)/s:i)+1
20975              0.009617   endif
                            
                              " Folds end on ;;
20975              0.078737   if getline(a:l) =~ '^\s*;;'
   16              0.000060     exe 'return "<' (indent(a:l)/s:i)+1 '"'
20959              0.009870   endif
                            
                              " Comments around folds aren't merged to them.
20959              1.727391   if synIDattr(synID(a:l, indent(a:l)+1, 0), "name") == "ocamlComment"
 4184              0.004404     return -1
16775              0.007958   endif
                            
16775              0.013879   return '='

i don't understand why function should be called that often? this is the function with the biggest time budget in the profile.

i am using ocp-indent and the ALE plugin, where i set

" use ale to fix trailing spaces in ocaml
let g:ale_fixers = {
			\ 'ocaml': ['trim_whitespace', 'remove_trailing_lines' ]
			\}

to trim whitespace.

jbuild file support

May be as simple as making sure jbuilder's sexpression files are treated as lisp.

Upstream project to vim

Can this project be upstreamed to vim? At the moment the Vim and Neovim runtime are missing 108a5cb, which causes lisp to be set globally once a dune file is opened. This creates a bad out-of-the-box experience for vim users who write OCaml but do not opt into using this plugin to get the latest OCaml vim features.

Upstream some changes

In the files that are already in the mainline [neo]vim.

Moreover, since Dune takes over the world it makes sense to add also the corresponding syntax highlight to the mainline.

  • runtime/syntax/ocaml.vim
  • runtime/ftdetect/ocaml.vim
  • runtime/ftplugin/ocaml.vim
  • runtime/syntax/dune.vim
  • runtime/ftdetect/dune.vim
  • runtime/ftplugin/dune.vim

errorformat file path relative to dune-workspace root

in multi-project dune workspace with nested directories error messages from compiler are relative to root of dune-workspace, not to the current working directory. It would be nice if ocaml.vim could resolve them correctly.
e.g. dune-workspace is in ~/project and my cwd is ~/project/a/b then error will mention file "a/b/c.ml" and vim "go to error" does not work..

dune.inc files not handled

dune.inc files are not handled. Not sure if such name are a just a convention, or if such extension is expected. It looks like include would accept any filename.

bad coloring of module types

module Make : functor(X: Ord) -> sig
  module Bar : module type of Make(X)

  val x : int
  val y : int
end

looks like this (ie the whole signature of the module is red):
2022-10-20-105709_409x175_scrot

Could we revert the syntax file to the old version? The recent changes look nicer on some parts of OCaml, but they are really broken on a lot of module-related syntax. I think "first, do no harm" would be a sound policy here.

indentation of dune-project files

i get this indentation:

(lang dune 1.10)
(generate_opam_files true)

	(name "extract_codes")
	(maintainers "nils@localhost")
	(package
	 (name "extract_codes")
	 (synopsis "bla")
	 (description "bla bla")
	 (depends
		(gen (> 0.5))
		(containers (>= 2.5 ))
		(yojson (>= 1.7.0))
		(csv (>= 2.2))))

which seems odd. is this intended? the file type is recognized as dune-project, correctly. or is this not a vim-ocaml issue? i also have the plugin ocp-indent-vim installed.

ocaml toplevel filetype

i often write scratch script files that contain code snippets for use in utop. i copy-and-paste these files, or more conveniently, i use vim-slime to automatically pipe the snippets to utop running within tmux. this is a convenient code-block evaluation setup.

utop also writes its own history to such script file when using #utop_save.

it would be nice if vim-ocaml could provide an ocaml-toplevel filetype for such script files. the only (afaics) change to the regular ocaml filetype would be to allow toplevel directives #require, #help, #pwd and so on as valid syntax.

afaik, there is no standard file extension for toplevel script files; the user would have to set the filetype manually i fear.

Unable to detect location

In this output, vim is unable to capture the locations of the error in the quickfix window:

|| File "src/dune_rules/workspace.ml", line 329, characters 63-67:
|| 329 |            Some (Build_context.create ~name ~host:(Some native.name)))
||                                                                      ^^^^
|| Error: Unbound record field name
|| File "src/dune_rules/context.ml", line 619, characters 8-21:
|| 619 |       ; build_context
||               ^^^^^^^^^^^^^
|| Error: This expression has type
||          dune_project_version:Dune_lang.Syntax.Version.t -> Build_context.t
||        but an expression was expected of type Build_context.t

cc @Julow

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.