Coder Social home page Coder Social logo

vscode-reasonml's Introduction

vscode-reasonml's People

Contributors

baransu avatar chenglou avatar chillee avatar davesnx avatar freebroccolo avatar gladimdim avatar glennsl avatar greenkeeperio-bot avatar huxpro avatar jchavarri avatar johannes-weber avatar jordwalke avatar khady avatar lostintangent avatar maelvls avatar mrkev avatar nadako avatar persianturtle avatar pete-murphy avatar scandiravian avatar thespyder avatar trishume 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

vscode-reasonml's Issues

Display the tail call position information in OCaml

It seems that the tail call information given by merlin is not displayed (or I missed it)

Simple test case:

let rec test () =
  if 1 + 2 = 3 then
    test ()
  else
    (<cursor>)

The displayed type is unit and I don't see tail call anywhere.

I searched a little bit and found those related commits and issues:

I tried to play with syntaxes/ocaml-hover-{type,signature}.json to make them look like the syntaxes/reason-hover-{type,signature}.json files but without success.

Regarding merlin-path mechanism

Hello @freebroccolo ,

First off, thanks for this beautiful plugin! ๐Ÿ‘

This issue is regarding the can't locate ocamlmerlin warnings. Actually I have merlin installed as well as the emacs reason-mode which works fine. But the warning keeps popping up with the vscode-reasonml extension.

It might be a trivial question but I thought that it'd be better to have this documented.

screen shot 2017-03-04 at 1 22 08 pm

Could you please help me out?

Keep the completions given by merlin in order

When merlin completion is triggered, it will return possible values at the point in a given order. This order matters because merlin will try to give the values that have the expected type first.

I don't know if the order is changed by vscode, the language server or this extension, but it would be nice to keep the values in the order given by merlin.

emacs:
image

vscode:
image

(I never know if I should report the issues on this repo or in the ocaml-language-server one, let me know if it's not at the good place)

refmt integration

I think it would be nice to provide formatOnSave powered by refmt.
Made a local extension which does the job. If you want, I can submit a PR which integrates this
into vscode-reasonml.

Fix colors for OCaml syntax highlighting

Some of the default scopes have probably changed since I last tested.

  • fix constructors
  • fix function and module names
  • fix record fields

Here is what it should look like with the Dark+ theme:

ocaml

show parameter hints in application contexts

Details here. It's more difficult in our case though because we don't have the enclosing parentheses.

I think that in order to implement this we will need to do some traversals of the syntax tree so that we can find the head of the application. There are a few ways one could do this using a combination of enclosing, shape, and type enclosing commands but it might just be easier and faster to do the traversal without merlin. Basically, given a position, search backward until the scope boundary is found and record the distance in nodes from the origin; this should be enough to reconstruct the rest.

Problems go stale

Often problems picked up by merlin in one file is fixed by altering a different file, but this isn't picked up so the problems go stale. This is particularly annoying if you delete a file that had problems associated with it. Then you're pretty much screwed and have to restart vscode to fix it.

And of course the opposite is true as well. Changes in one file might cause errors in other files that merlin doesn't pick up.

But in general, thanks for awesome work!

Add a way to support the project

I am very happy with this extension and I would like to support your work. I could be nice to have a bountysource like merlin or another way to contribute. I would be happy to give some money to support you.

Add an option to disable the code lens

Sometimes I would like to disable the code lens. I think we could have a configuration option and a command to turn it on and off either locally or globally.

highlight expressions on hover

The current default behavior is to show subtle highlighting of identifiers on hover. However, this doesn't really mesh well with the position info which is supposed to indicate whether an expression is in a tail (call) position.

What happens is that when you hover over the head term of an application, it will report position: normal, which is fine, but a little bit surprising. You only see the position: tail if you hover slightly in front of the head term but now you don't see anything highlighted in the buffer because there is no identifier under the cursor. What should happen is the entire application should be highlighted.

tldr: the highlighting extents on hover should be calculated by merlin from the shape of the expression at the cursor position rather than being calculated by the editor based on identifiers.

Overeager pipe insertion

I've discovered several problems with it:

  1. Enter after using a pipe operator will insert a pipe followed by a blank space on the new line, so you'll have to press backspace to remove the blank space before finishing the pipe operator.
  2. It ignores semicolons and inserts a pipe on new lines anyway
  3. With vim mode and the cursor positioned in the middle of a line that starts with a pipe, pressing "o" will insert a new line starting with a pipe. This is very unexpected, as "o" should always insert a blank line.

I think there's more, but they've slipped my mind. I'll update this when I come across them.

Get syntax error information from refmt

Merlin doesn't provide very good Reason syntax error information; in particular the location of the error is often way off. The positional information from refmt is way better, so I think it would make sense to implement a linter which sends the code to refmt upon change, and displays any errors. You can see how sublime-reason uses refmt as a linter here: https://github.com/chenglou/sublime-reason/blob/master/Reason.py#L77-L95

If what I'm saying sounds good, I'm happy to have a go at implementing it. I've already put up a similar PR for atom-reason-refmt

Example of unhelpful syntax error info (the error is on line 6 but the Invalid token error points to line 8):
screen shot 2017-06-04 at 5 06 42 pm

better completion for objects

Currently completion for object methods only seems to work once you start typing a method name after #. This isn't as useful as completion for records because you need to know at least the first character of the method name.

This seems to be an issue with merlin although I'm not sure why. However, we should be able to work around it by detecting when # is typed and first reconstructing the initial list of methods from the inferred type.

cache codelens when switching editors

Since we're now watching files in order to maintain the symbol index we might as well exploit that for other scenarios too. One easy thing we could do is avoid recomputing the codelens items when switching editors unless the underlying document has been modified.

Add module name expansion during completion

Since version 2.1, merlin has this "smart" completion feature:

    - "smart" (a.k.a "do what I mean") completion:
          `L.m` will expand to `List.map ; List.m... ; ListLabels.map ; ...` if
          `L` doesn't exist.

I don't know if this could be added in this extension of in the ocaml-language-server. But it's a nice feature to have.

Emacs:
image

VScode:
image

merlin status indicator for buffers

This would provide some visual indication as to whether or not the language server can provide advanced features for the current buffer. We also could make the indicator into a clickable widget.

Support code formatting for OCaml

I believe there is support of code formatting for reason using refmt. I would like to have the support of ocp-indent for the OCaml code. With the possibility to format all the document, only my selection or only one line.

I wonder if this should be done in this extension or if it's better to have a new extension for ocp-indent.

question: how to utilize reason.path.rtop?

Great plugin!!

I assume reason.path.rtop is to hook VSCode / ReasonML to REPL functionality, and set it to my rtop, but cannot figure out how to use it. Could not find suitable forum to ask this question ...

Lessons learned

This is sort of an open-ended question, but I am curious if you might summarize (if you haven't already somewhere) some of the key points to keep in mind for creating a VS Code extension like this.

If I were to create an extension like this for another language, what would be a good starting point? What would be some best practices to follow, or pitfalls to avoid?

Thanks for any direction you might suggest and for your work on this extension!

Update Reason syntax

Relevant to #47.

  • punned arguments

@chenglou what other stuff has changed since the highlighter was submitted for inclusion into linguist for github?

complete syntax highlighting

Remaining tasks:

  • Reason
    • classes and objects
      • class
      • copies
      • inherit
      • initializers
      • private methods
      • recursive classes
      • self reference
      • virtual methods
    • patterns
      • polymorphic variant wildcards
    • terms
      • coercions
      • string indexing
    • types
      • subtyping
  • OCaml
    • for
    • labels
    • list literals
    • objects
    • while

use signature from annotation or interface files for codelens

Right now we just use the signature reported from merlin at the point of definition. Most of the time this is okay but it can lead to less than optimal results for fancier types involving lots of polymorphic variants or first-class modules.

Probably the right way to do this is to gather and store the signatures from annotations and interfaces files in the symbol index so we can retrieve them quickly. Then we would modify the codelens feature to first check the index and only query merlin if no results are found.

switch to a priority queue for pending tasks

Some features potentially make a lot of calls to merlin in rapid succession and/or take a long time (relatively speaking) to complete. Examples of this are the codelens feature and diagnostic refreshing for the entire workspace (currently disabled). Find all references for workspace is another one since it will need to do searching and reverse lookups.

In order to keep the more interactive features like hover, outline, and code splitting responsive while these other features are executing, we should really be using a priority queue instead of just running everything in a straight sequence.

Autocomplete is a bit too aggressive

One particularly annoying example is when typing semicolon followed (slowly) by enter, it will insert some random identifier. This is of course done on the end of most lines of code, so it happens quite often.

load project error

events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at exports._errnoException (util.js:1022:11)
    at WriteWrap.afterWrite [as oncomplete] (net.js:804:14)
[Error - 10:14:56 AM] Connection to server got closed. Server will not be restarted.

I installed reason/merlin/merlin-extend via opam, it is in PATH

No definition found ...

I'm not entirely sure this is an issue with vscode-reason, but I'm also not sure where else to look. I am starting a project with the reason-react-example code found here. One of the files looks like this:

module PageReason = {
  include ReactRe.Component.JsProps;
  type props = {message: string, extraGreeting: option string};
  let name = "PageReason";
  let render {props} => {
    let greeting =
      switch props.extraGreeting {
      | None => "How are you?"
      | Some g => g
      };
    <div> <MyBannerRe show=true message=(props.message ^ " " ^ greeting) /> </div>
  };
  /* extraGreeting is optional, which means the JS side might pass in a null or undefined */
  type jsProps = Js.t {. message : string, extraGreeting : Js.null_undefined string};
  let jsPropsToReasonProps =
    Some (
      fun jsProps => {
        message: jsProps##message,
        extraGreeting: Js.Null_undefined.to_opt jsProps##extraGreeting
      }
    );
};

include ReactRe.CreateComponent PageReason;

let createElement ::message ::extraGreeting=? => wrapProps {message, extraGreeting};

I am trying to understand where the Js variable is coming from, what it does etc. but jump to definition is not working on it, instead it says no definition found. This is also true of the MyBannerRe component, which is in a sibling file.

Any help would be appreciated. Thank you!!

adjust codelens refreshing

An issue with the current codelens behavior is that all of the codelenses for items in a local module are refreshed together, which means that if one of the items has a syntax error, the others collapse until it is fixed. If you have a lot of short single line definitions together and are doing a lot of editing, this effect can be slightly annoying.

We can't actually refresh the items individually due to the way merlin works here (afaik), so what we need to do instead is have some sort of caching of the items. Then, if there is a syntax error from editing, we just continue to show the last good codelens data for the other items until all of the diagnostics are resolved.

However, getting this to work is a little bit trickier than it first seems. I tried doing it in a naive way earlier and it sort of worked but the behavior wasn't consistent. I think the issue was that when codelenses are resolved (in the second phase), the change isn't necessarily propagated back to something holding on to the original CodeLens. If this is indeed the case, we can work around it by building a map and associating a unique id with each codelens and manually doing the update. It's possible that some other event was interfering with the caching though. Need to do more testing.

Another alternative which would be easier but less useful would be to simply disable codelens refreshing for whatever the current item is with respect to the cursor position (followed back up to the associated top-level node). But in order to make this work I think we'd have to listen for some other events too so it may end up being messier in the end.

fix hovers for items in modules

This really needs some work in the Reason support both in how the highlighting for signatures is selected (in order to deal with ambiguity) and in what gets shown in the hover.

Support for connected rtop session.

Hi @freebroccolo

So far the extension works like magic ๐Ÿ‘

I do have two issues,

  1. How to compile ReasonML code from the editor?
  2. Are there any plans to add support for "send to repl" kind of funcionality?

Add jump to enclosing fun, let, module or match

This is a feature request

In merlin mode for emacs, there is a function to jump to enclosing fun, let, module or match, which is very convenient. I would love to have it in vscode too.

In addition, it could be nice to display somewhere those information (in which enclosing fun, let, module, match, the cursor currently is), maybe in the status bar.

https://github.com/ocaml/merlin/blob/master/doc/dev/PROTOCOL.md#jump--target-string--position-position

Not present in the old protocol doc, but the command is available. I think it is something like ["jump", "fun let module match", "at", POSITION]

(defun merlin/jump (&optional target)
  "Jump to the TARGET"
  (let ((result (merlin/send-command
                  (list 'jump (if (equal target "") "fun let module match" target)
                        'at (merlin/unmake-point (point))))))
    (unless result
      (error "Not found. (Check *Messages* for potential errors)"))
    (unless (listp result)
      (error result))
    result))
C-c C-j runs the command merlin-jump, which is an interactive Lisp
function in `merlin.el'.

It is bound to C-c C-j.

(merlin-jump &optional TARGET)

Jump to enclosing fun, let, module or match.

Any combination of the above may be entered, separated by spaces, ex.:

fun let or module or module fun match

Empty string defaults to jumping to all these.

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.