Code Monkey home page Code Monkey logo

elm-oracle's Introduction

elm-oracle

Elm Oracle intends to be a standalone program that can be used by all editor plugins to query information about a project's source code.

Installation

You need node to install and run elm-oracle.

npm install -g elm-oracle

Usage

elm-oracle FILE query
  Query for information about a token in an Elm file.

Available options:
  -h,--help                    Show this help text.

The return value will be a json array of json objects with information for each value that starts with the query string.

elm-oracle Main.elm Signal.message might return:

[
    {
        "name": "message",
        "fullName": "Signal.message",
        "href": "http://package.elm-lang.org/packages/elm-lang/core/latest/Signal#message",
        "signature": "Address a -> a -> Message",
        "comment": "Create a message that may be sent to a `Mailbox` at a later time.\n\nMost importantly, this lets us create APIs that can send values to ports\n*without* allowing people to run arbitrary tasks."
    }
]

Whereas elm-oracle Main.elm Signal.m might include Signal.mailbox, Signal.map, etc.

If elm-oracle encounters errors, it will return a json array or json objects like:

[{"error": "You did not supply a source file or query."}]

Projects that use elm-oracle

elm-oracle's People

Contributors

pbogut avatar rundis 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

elm-oracle's Issues

Elm Oracle 2.0

There are a few issues with the current elm-oracle program:

  • Requires an internet connection + time to download documentation.json files, which might not always work and currently doesn't work behind a proxy.
  • Can only use information and data provided in documentation.json files, so no file position for 'jump to navigation', etc.
  • It is currently impossible to provide insight into the user's local codebase at all, only packages in elm-stuff.
  • Every time elm-oracle is queried, it rebuilds data from scratch without using a cache.
  • Loading up a node vm for each query can be a bit slow.
  • Other functionality, like previewing docs, might make sense in a tool that is meant to provide insight into an elm codebase.
  • Parse elm files instead of downloading documentation.json files.
    • Parse module (name, comment, location)
    • Parse imports (name, alias, exposing, location)
    • Parse functions (name, type, comment, location)
    • Parse types (name, args, cases, comment, location)
    • Parse aliases (name, args, type, comment, location)
    • Filter out all private values unless they are in the user's local project.
  • Parse elm-package.json files
    • Use "source-directories" to gather the correct .elm files to parse
    • Also parse the project's elm-package.json file so we can provide data on the user's local code
  • Store gathered data in a time-accessed based cache
  • Using the cache + the imports data of the current file, generate needed data.
  • Add a daemon mode that keeps running and responds to queries
  • Add a command that will generate a docs preview of your project that can be opened in your browser
  • Using the cache, generate tags files
    • ctags
    • etags

Uncaught Error: No elm-oracle suggestions error indicated

[Enter steps to reproduce below:]

  1. Occurred while typiing name of module in new source code file in Atom Editor
  2. Typed: module FunctionBasics (Error occurred while typing name, first 2 or 3 characters)
    (note: autocomplete setting via atom-elm package (language-elm) is initiated autocomplete after two (2) characters).
    SEE Stack Trace Below

Atom Version: 1.8.0
System: Microsoft Windows 7 Enterprise
Thrown From: language-elm package, v1.5.0

Stack Trace

Uncaught Error: No elm-oracle suggestions

At /C:/Users/22711973/.atom/packages/language-elm/lib/elmOracle.js:144

Error: No elm-oracle suggestions
    at parseOutput (C:/Users/22711973/.atom/packages/language-elm/lib/elmOracle.js:125:11)
    at provideSuggestions (C:/Users/22711973/.atom/packages/language-elm/lib/elmOracle.js:27:27)
    at ChildProcess.<anonymous> (C:/Users/22711973/.atom/packages/language-elm/lib/elmOracle.js:62:9)
    at emitTwo (events.js:87:13)
    at ChildProcess.emit (events.js:172:7)
    at maybeClose (internal/child_process.js:818:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)

Commands

  4x -4:47.1.0 window:increase-font-size (ol.tree-view.full-menu.list-tree.has-collapsable-children.focusable-panel)
     -4:15 editor:newline (atom-text-editor.editor.is-focused)
     -4:13.3.0 core:move-up (atom-text-editor.editor.is-focused)
  3x -4:12.9.0 core:move-right (atom-text-editor.editor.is-focused)
     -4:12 core:move-left (atom-text-editor.editor.is-focused)
     -4:11.6.0 editor:newline (atom-text-editor.editor.is-focused)
     -4:10.8.0 core:move-down (atom-text-editor.editor.is-focused)
     -4:10.3.0 core:backspace (atom-text-editor.editor.is-focused)
     -4:09.4.0 core:move-up (atom-text-editor.editor.is-focused)
     -4:08.9.0 core:move-right (atom-text-editor.editor.is-focused)
     -4:07.4.0 editor:newline (atom-text-editor.editor.is-focused)
     -4:02.7.0 core:backspace (atom-text-editor.editor.is-focused)
  3x -3:59.6.0 editor:newline (atom-text-editor.editor.is-focused)
     -2:33.6.0 core:move-right (atom-text-editor.editor.is-focused)
  2x -2:33.3.0 editor:newline (atom-text-editor.editor.is-focused)

Config

{
  "core": {
    "themes": [
      "atom-dark-ui",
      "atom-dark-syntax"
    ]
  },
  "language-elm": {
    "elmOraclePath": "C:\\Users\\22711973\\AppData\\Roaming\\npm\\elm-oracle",
    "minCharsForAutocomplete": 2
  }
}

Installed Packages

# User
atom-language-rust, v0.8.0
autocomplete-go, v1.1.0
builder-go, v1.0.0
go-config, v1.2.1
go-get, v1.0.3
go-plus, v4.1.0
gofmt, v1.1.6
gometalinter-linter, v1.1.0
gorename, v1.0.2
ink, v0.4.4
julia-client, v0.4.7
language-elm, v1.5.0
language-julia, v0.6.0
language-rust, v0.4.6
latex-completions, v0.3.1
linter, v1.11.14
linter-rust, v0.4.6
navigator-godef, v1.0.3
rust-api-docs-helper, v0.5.1
tester-go, v1.0.4
tool-bar, v1.0.0
uber-juno, v0.1.1

# Dev
No dev packages

Enable completion without specifying a file

What would it take to make this work without a FILE argument, e.g. to provide completion in a repl?
I see you use the file's imports. In the case of a the repl, we don't know what's been imported. Maybe a new :special in elm-repl could list all current imports.

Auto-complete for imports

module Foo.Bar exposing (..)
...

Given the file above, it would be nice if typing the code below, hinted at the existence of Bar

import Foo.|

Support for Elm 0.19

When elm install has been run for a project with the current Elm 0.19 alpha, elm-oracle does not see its installed dependencies, and outputs this error:

[{"error":"Dependencies file is missing. Perhaps you need to run `elm-package install`?"}]

Looks like there is some work to be done if elm-oracle is to support the next version of Elm.

Install Fails on Mac

$ npm install -g elm-oracle
~/.asdf/installs/node/6.2.0/.npm/bin/elm-oracle -> ~/.asdf/installs/node/6.2.0/.npm/lib/node_modules/elm-oracle/bin/elm-oracle

[email protected] postinstall /.asdf/installs/node/6.2.0/.npm/lib/node_modules/elm-oracle
/.asdf/installs/node/6.2.0/.npm/lib/node_modules/.hooks/postinstall
No such plugin
npm ERR! Darwin 15.4.0
npm ERR! argh "
/.asdf/installs/node/6.2.0/bin/node" "
/.asdf/installs/node/6.2.0/bin/npm" "install" "-g" "elm-oracle"
npm ERR! node v6.2.0
npm ERR! npm v3.8.9
npm ERR! code ELIFECYCLE

npm ERR! [email protected] postinstall: ~/.asdf/installs/node/6.2.0/.npm/lib/node_modules/.hooks/postinstall
npm ERR! Exit status 1

elm-oracle doesn't parse multiline imports

If we have a file like this

import Html
    as Hahatml

elm-oracle *file* Haha returns []. If the same statement is in a single line it works as intended and returns appropriate results.

Auto-completion not always provided

Hi,
I'm using Emacs and Elm-Mode which depends on elm-oracle and Company mode for ac. I have not tried other plugins with other editors, and could also be that Elm 0.17 is still relatively new.

I am not seeing all possible results for obvious things like Html.App. I see Html.a, Html.Attribute, Html.Events, etc. But is the current branch not up-to-date?

I want to know if it's an issue for me or an issue for this package. Thanks.

Edit: Crap, this might be related to #18 as I'm still new to Elm.
Edit2: For some reason, the auto complete is for Html.App is now working...no clue why, but now I know it's prolly something on my end.

HTTP_PROXY settings

elm-oracle doesn't use ENV proxy settings.

Problem seems to be generic for node http.request, in this case in the rest client.
Any hope to solve this issue?

W/O with transparent proxy on linux.
sudo iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to-destination IP:PORT

FileNotFoundError: [Errno 2] No such file or directory: 'elm-oracle'

Not sure why this happens. Basically when I open Sublime Text for the first time it works. But then when I open it again (usually with subl .) and I open a .elm file, this is what I get in the console:

Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 333, in on_activated_async
    callback.on_activated_async(v)
  File "/Users/simone/Library/Application Support/Sublime Text 3/Packages/Elm Language Support/elm_show_type.py", line 226, in on_activated_async
    view_load(view)
  File "/Users/simone/Library/Application Support/Sublime Text 3/Packages/Elm Language Support/elm_show_type.py", line 210, in view_load
    load_from_oracle(view.file_name())
  File "/Users/simone/Library/Application Support/Sublime Text 3/Packages/Elm Language Support/elm_show_type.py", line 184, in load_from_oracle
    stderr=subprocess.PIPE, shell=shell)
  File "./subprocess.py", line 824, in __init__
  File "./subprocess.py", line 1448, in _execute_child
FileNotFoundError: [Errno 2] No such file or directory: 'elm-oracle'

I've installed elm-oracle with npm install -g elm-oracle and it's in my $PATH:

$ which elm-oracle
/Users/simone/.nvm/versions/node/v5.1.0/bin/elm-oracle
$ echo $PATH
/Users/simone/.nvm/versions/node/v5.1.0/bin /usr/local/bin /usr/bin /bin /usr/sbin /sbin

Any idea why this would happen or how I can fix it?

Code intelligence

Hi there!

I was thinking it'd be fun to take a shot at adding code intelligence (or local project autocomplete) support to Elm-Oracle. I dug into the code a bit this morning to see how the completions are generated for modules, and learned that you're using the output from the documentation generator to drive autocomplete.

I played with the idea of having elm-oracle generate docs for whatever Elm project is being worked on at the moment, and then use those to provide autocomplete suggestions, but in order for any docs to be generated at all, proper docstrings must be written, and all documented modules must be exported in elm-package.json, which renders that approach impractical for most work-in-progress development.

So I'm wondering what a better approach would be. If only Elm were self-hosted, parts of the compiler could be used to parse source files and build an AST. From that point autocomplete wouldn't be hard (I don't think), but it's not self-hosted. So in order to be able to use parts of the compiler (I don't even know that this is possible, just making assumptions here), at least part of elm-oracle would need to be written in Haskell.

Alternately, one could write an elm parser package in Elm, to take in Elm source files, and spit out some sort of AST. That sounds like a big project (though interesting!). But, would it be worth it?

A nice thing about that last idea is that an AST generator for Elm written in Elm could be useful in more cases than just autocomplete. It could be used to write a package for doing codemods on Elm code, for example.

Those are my thoughts. Any input?

Added to Atom Editor!

Hey all, just wanted to thank you for the awesome little repo :) I've added support for Elm-Oracle to the Elm-Language package for atom! It's still in PR, but figured I'd let you all know.

It's still in PR, hoping to get some feedback on it and merge soon! Should I make a PR on this repo that links to the atom-elm package in the README when it's merged?

edubkendo/atom-elm#9

Thanks again!
Brian

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.