Skip to content
This repository was archived by the owner on Nov 12, 2018. It is now read-only.

Commit 6947852

Browse files
committed
Type fixes
1 parent 0e59f22 commit 6947852

File tree

7 files changed

+63
-30
lines changed

7 files changed

+63
-30
lines changed

lib/alchemide/autocompleter/autocomplete.exs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
spec_to_ast = fn a,b -> Kernel.Typespec.spec_to_ast(a,b) end
22

3+
y = fn f ->
4+
fn x ->
5+
f.(fn y -> (x.(x)).(y) end)
6+
end.(fn x ->
7+
f.(fn y -> (x.(x)).(y) end)
8+
end)
9+
end
10+
11+
12+
replaceTypeGen = fn replaceType ->
13+
fn
14+
[{spec} | specs], types ->
15+
[]
16+
end
17+
end
18+
319
zipFunSpec = fn
420
(a, nil) -> a
521
(a, []) -> a
@@ -30,7 +46,7 @@ pairWithSpec = fn input, fns ->
3046
case String.contains?(input, ".") do
3147
true ->
3248
mod = Regex.replace ~r/\.\w*$/, input, ""
33-
{atom, _} = Code.eval_string("List")
49+
{atom, _} = Code.eval_string(mod)
3450
specMap = getSpec.(atom)
3551
re = ~r/\/\d+\s*$/
3652
Enum.map(fns, fn a ->
@@ -69,7 +85,7 @@ execute = fn
6985
("a", input) ->
7086
{exists, one, multi} = IEx.Autocomplete.expand(Enum.reverse(to_char_list(input)))
7187
{exists, one, pairWithSpec.(input, multi)}
72-
("s", input) -> getSpec.(String.to_atom("Elixir." <> input))
88+
("s", input) -> {"True", "" , Map.to_list getSpec.(String.to_atom("Elixir." <> input))}
7389
end
7490

7591
loop = fn(y) ->

lib/alchemide/typer/lib/typer.ex

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
defmodule Typer do
2-
def getSpec(module) do
3-
mapper = fn {{name, _arity}, types} ->
4-
specs = types
5-
|> Enum.map(&(Kernel.Typespec.spec_to_ast.(name, &1)))
6-
|> Enum.map(&Macro.to_string/1)
7-
{Atom.to_string(name), specs}
8-
end
9-
reducer = fn {k, v}, acc ->
10-
Dict.put(acc,k,v)
11-
end
122

13-
Kernel.Typespec.beam_specs(module)
14-
|> Enum.map(mapper)
15-
|> Enum.reduce(%{}, reducer)
3+
def get_type({op,ctx,args}) when is_atom(op) and is_list(ctx) and is_list(args) do
4+
165
end
6+
def get_type(a) when is_atom(a) , do: :'atom()'
7+
def get_type(a) when is_binary(a) , do: :'binary()'
8+
def get_type(a) when is_bitstring(a) , do: :'bitstring()'
9+
def get_type(a) when is_boolean(a) , do: :'boolean()'
10+
def get_type(a) when is_float(a) , do: :'float()'
11+
def get_type(a) when is_integer(a) , do: :'integer()'
12+
def get_type(a) when is_list(a) , do: :'list()'
13+
def get_type(a) when is_map(a) , do: :'map()'
14+
def get_type(a) when is_nil(a) , do: :'nil'
15+
def get_type(a) when is_number(a) , do: :'number()'
16+
def get_type(a) when is_pid(a) , do: :'pid()'
17+
def get_type(a) when is_port(a) , do: :'port()'
18+
def get_type(a) when is_reference(a) , do: :'reference()'
19+
def get_type(a) when is_tuple(a) , do: :'tuple()'
20+
def get_type(a) when is_function(a) , do: :'function()'
21+
def get_type(_), do: :'any()'
22+
1723
end

lib/alchemide/typer/test/typer_test.exs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ defmodule TyperTest do
44
test "the truth" do
55
assert 1 + 1 == 2
66
end
7-
test "expression value" do
8-
assert Typer.
7+
test "simple expression value" do
8+
assert Typer.get_type(s_to_ast("1")) == :'integer()'
9+
assert Typer.get_type(s_to_ast(":atom")) == :'atom()'
10+
end
11+
12+
def s_to_ast(string) do
13+
{:ok, ast} = Code.string_to_quoted(string)
14+
ast
915
end
1016
end

lib/autocomplete-elixir-client.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class RsenseClient
1313
editor.onDidSave (e) ->
1414
autocomplete.loadFile(e.path)
1515

16-
checkCompletion: (editor, buffer, row, column, prefix, callback) ->
16+
checkCompletion: (prefix, callback) ->
1717
#console.log "Prefix: #{prefix}"
1818
autocomplete.getAutocompletion prefix, (result) ->
1919
#console.log result

lib/autocomplete-elixir-provider.coffee

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,18 @@ class RsenseProvider
1010
@rsenseClient = new RsenseClient()
1111

1212

13-
requestHandler: (options) ->
13+
getSuggestions: (request) ->
1414
return new Promise (resolve) =>
15-
row = options.cursor.getBufferRow()
16-
col = options.cursor.getBufferColumn()
15+
row = request.bufferPosition.row
16+
col = request.bufferPosition.column
1717

18-
prefix = options.editor.getTextInBufferRange([[row ,0],[row, col]])
18+
prefix = request.editor.getTextInBufferRange([[row ,0],[row, col]])
1919
[... , prefix] = prefix.split(/[ ()]/)
2020
unless prefix then resolve([])
21-
options.prefix = prefix
2221

23-
completions = @rsenseClient.checkCompletion(options.editor,
24-
options.buffer, row, col, options.prefix, (completions) =>
25-
suggestions = @findSuggestions(options.prefix, completions)
22+
completions = @rsenseClient.checkCompletion(prefix, (completions) =>
23+
suggestions = @findSuggestions(prefix, completions)
24+
console.log suggestions
2625
return resolve() unless suggestions?.length
2726
return resolve(suggestions)
2827
)
@@ -35,8 +34,8 @@ class RsenseProvider
3534
[word, spec] = completion.name.trim().split("@")
3635
argTypes = null
3736
ret = null;
38-
if !word || !word[0] then continue
39-
if word[0] == word[0].toUpperCase() then ret = "Module"
37+
if !word || !word[0] then continue
38+
if word[0] == word[0].toUpperCase() then [ret,isModule] = ["Module",true]
4039
label = completion.spec
4140
if spec
4241
specs = spec.replace(/^\w+/,"")
@@ -61,6 +60,12 @@ class RsenseProvider
6160
snippet: if one then prefix + word else word
6261
prefix: if one then prefix else last
6362
label: if ret then ret else "any"
63+
type: if module then "method" else
64+
if func then "function" else
65+
"variable"
66+
description: spec || ret
67+
excludeLowerPriority: true
68+
6469
suggestions.push(suggestion)
6570
return suggestions
6671
return []

lib/autocomplete-elixir.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports =
1515
@rsenseProvider = new RsenseProvider()
1616

1717
provideAutocompletion: ->
18-
{providers: [@rsenseProvider]}
18+
[@rsenseProvider]
1919

2020
deactivate: ->
2121
@rsenseProvider?.dispose()

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"autocomplete.provider": {
3636
"description": "Intelligent Elixir code completion",
3737
"versions": {
38-
"1.1.0": "provideAutocompletion"
38+
"2.0.0": "provideAutocompletion"
3939
}
4040
}
4141
},

0 commit comments

Comments
 (0)