-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33aef26
commit c4df7ba
Showing
6 changed files
with
86 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,50 @@ | ||
defmodule NextLS.SignatureHelp do | ||
@moduledoc false | ||
|
||
import NextLS.DB.Query | ||
|
||
alias GenLSP.Enumerations.MarkupKind | ||
alias GenLSP.Structures.MarkupContent | ||
alias GenLSP.Structures.ParameterInformation | ||
alias GenLSP.Structures.SignatureHelp | ||
alias GenLSP.Structures.SignatureInformation | ||
alias NextLS.ASTHelpers | ||
alias NextLS.DB | ||
|
||
def fetch(file, {line, col}, db, _logger) do | ||
code = File.read!(file) | ||
|
||
{mod, func} = | ||
ASTHelpers.Functions.get_function_name_from_params(code, line, col) | ||
|
||
query = | ||
~Q""" | ||
SELECT | ||
* | ||
FROM | ||
symbols | ||
WHERE | ||
symbols.module = ? | ||
AND symbols.name = ?; | ||
""" | ||
|
||
args = [Enum.map_join(mod, ".", &Atom.to_string/1), Atom.to_string(func)] | ||
|
||
symbol = DB.query(db, query, args) | ||
|
||
result = | ||
case symbol do | ||
nil -> | ||
alias NextLS.Definition | ||
|
||
def fetch(file, {line, col}, db) do | ||
case Definition.fetch(file, {line, col}, db) do | ||
nil -> | ||
nil | ||
|
||
[] -> | ||
nil | ||
|
||
[[_, _mod, _file, type, label, params, _line, _col | _] | _] = _definition -> | ||
if type in ["def", "defp"] do | ||
term_params = | ||
:erlang.binary_to_term(params) | ||
|
||
code_params = | ||
term_params | ||
|> Macro.to_string() | ||
|> String.replace_prefix("[", "(") | ||
|> String.replace_suffix("]", ")") | ||
|
||
params_info = | ||
term_params | ||
|> Enum.map(&Macro.to_string/1) | ||
|> Enum.map(fn name -> | ||
%ParameterInformation{ | ||
label: name | ||
} | ||
end) | ||
|
||
%SignatureHelp{ | ||
signatures: [ | ||
%SignatureInformation{ | ||
label: "#{label}#{code_params}", | ||
parameters: params_info | ||
} | ||
] | ||
} | ||
else | ||
nil | ||
|
||
[] -> | ||
nil | ||
|
||
[[_, _mod, file, type, label, params, line, col | _] | _] = _definition -> | ||
if type in ["def", "defp"] do | ||
code_params = params |> :erlang.binary_to_term() |> Macro.to_string() |> dbg() | ||
|
||
signature_params = | ||
params | ||
|> :erlang.binary_to_term() | ||
|> Enum.map(fn {name, _, _} -> | ||
%ParameterInformation{ | ||
label: Atom.to_string(name) | ||
} | ||
end) | ||
|> dbg() | ||
|
||
%SignatureHelp{ | ||
signatures: [ | ||
%SignatureInformation{ | ||
label: "#{label}.#{code_params}", | ||
documentation: "need help", | ||
parameters: signature_params | ||
# active_parameter: 0 | ||
} | ||
] | ||
# active_signature: 1, | ||
# active_parameter: 0 | ||
} | ||
else | ||
nil | ||
end | ||
end | ||
|
||
result | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters