PaddType throws `no information found`, but pulp server inferring declaration fine
Closed this issue ยท 13 comments
This is implemented for top level declarations, through the compiler warnings. Quoting the README.md
file:
nm <buffer> <silent> <leader>s :<C-U>call PSCIDEapplySuggestion()<CR>
nm <buffer> <silent> <leader>a :<C-U>call PSCIDEaddTypeAnnotation()<CR>
One of these two functions will work if you call them on a compiler warning for a missing type signature.
aha..I didnt know what they do because they are not working for me
its saying
E119: Not enough arguments for function: PSCIDEapplySuggestion
E119: Not enough arguments for function: PSCIDEaddTypeAnnotation
So instead of them I am using this maps
" type annotation
nmap <buffer><silent> <localleader>at :<C-U>PaddType<CR>
" suggestion
nmap <buffer><silent> <localleader>ap :<C-U>Papply<CR>
but they are not working too
In file
module Main where
import Prelude
import Data.Array as Array
import Data.Foldable (sum)
isMultiple :: Int -> Boolean
isMultiple n = mod n 3 == 0 || mod n 5 == 0
answerA min max = sum $ Array.filter isMultiple $ Array.range min max
PaddType says no type information found
, and Papply says no suggestions found
but pulp server
in other tmux pane inferring types fine
Compiling Main
Warning found:
in module Main
at src/Main.purs line 11, column 1 - line 11, column 67
No type declaration was provided for the top-level declaration of answerA.
It is good practice to provide type declarations as a form of documentation.
The inferred type of answerA was:
Int -> Int -> Int
in value declaration answerA
See https://github.com/purescript/documentation/blob/master/errors/MissingTypeDeclaration.md for more information,
or to contribute content related to this warning.
Maybe @coot can help here? I'm not using the VIM plugin currently.
It looks like #99 might be related.
I'll take a look somewhere this week, thanks for the report.
@coot would be greatly appreciated
however I have tried to fix it myself and found that this is due to purs ide
responds on
{"params": {"currentModule": "Main", "search": "answerA", "filters": [{"filter": "modules", "params": {"modules": ["Prelude", "Data.Array"]}}]}, "command": "type"}
with empty {"result":[],"resultType":"success"}
example
~/projects/pulp-test ๎ฐ ๎ master ๎ฐ purs ide client -p 4242
{"command":"rebuild","params": {"file": "/home/bjorn/projects/pulp-test/src/Main.purs"}}
{"result":[{"suggestion":{"replaceRange":{"startLine":11,"endLine":11,"startColumn":1,"endColumn":1},"replacement":"answerA :: Int -> Int -> Int\n\n"},"moduleName":"Main","errorLink":"https://github.com/purescript/documentation/blob/master/errors/MissingTypeDeclaration.md","errorCode":"MissingTypeDeclaration","message":" No type declaration was provided for the top-level declaration of answerA.\n It is good practice to provide type declarations as a form of documentation.\n The inferred type of answerA was:\n\n Int -> Int -> Int\n\n\nin value declaration answerA\n","filename":"/home/bjorn/projects/pulp-test/src/Main.purs","position":{"startLine":11,"endLine":11,"startColumn":1,"endColumn":67}}],"resultType":"success"}
~/projects/pulp-test ๎ฐ ๎ master ๎ฐ purs ide client -p 4242
{"params": {"currentModule": "Main", "search": "answerA", "filters": [{"filter": "modules", "params": {"modules": ["Prelude", "Data.Array"]}}]}, "command": "type"}
{"result":[],"resultType":"success"}
also does someone know why request above without filters
is not valid command?
~/projects/pulp-test ๎ฐ ๎ master ๎ฐ purs ide client -p 4242
{"params": {"search": "answerA"}, "command": "type"}
{"result":"Error parsing Command.","resultType":"error"}
P.S.
purs 0.11.6
test-repo
The filters parameter was not optional before purescript/purescript#3040. Just pass an empty array for now.
The editor plugins don't use the type command to provide the type signatures. They use suggestions on the compilation warnings instead: https://github.com/purescript/purescript/blob/71fc308a53bf89678c1e1d4a242cc01561d556d1/src/Language/PureScript/Errors/JSON.hs#L26-L34
EDIT:
The reason it doesn't return a result for "filters": [{"filter": "modules", "params": {"modules": ["Prelude", "Data.Array"]}}]
is because answerA
is not defined in Prelude
or Data.Array
.
The editor plugins don't use the type command to provide the type signatures. They use suggestions on the compilation warnings instead: https://github.com/purescript/purescript/blob/71fc308a53bf89678c1e1d4a242cc01561d556d1/src/Language/PureScript/Errors/JSON.hs#L26-L34
I didnt get it, psc-ide-vim sends request with "command": "type"
to purs ide
on :PaddType
, there is something wrong?
I know fix for this issue:
substitute current filter parameters with module name of searched function
example:
~/projects/pulp-test ๎ฐ ๎ master ๎ฐ purs ide client -p 4242
{"params": {"search": "answerA", "filters": [{"filter": "modules", "params": {"modules": ["Main"]}}]}, "command": "type"}
{"result":[{"exportedFrom":["Main"],"identifier":"answerA","definedAt":{"start":[11,1],"name":"/home/bjorn/projects/pulp-test/src/Main.purs","end":[11,67]},"expandedType":"Int โ Int โ Int","module":"Main","documentation":null,"type":"Int โ Int โ Int"}],"resultType":"success"}
P.S. currentModule: "Main"
has no influence
@BjornMelgaard That's new to me :) I didn't know the VIM plugin does it this way. The compiler already emits suggestions for these, so I figured the plugin could just use those.
currentModule
has a different use, in that it allows you to see module-private functions after a successful rebuild. So you'll also want to specify currentModule if you want to give type signatures to private functions.
@kritzcreek yes, plugin does this here
Thanks, very helpful, I'll made fix soon)
@kritzcreek made pr, can someone check
The underlying issue that the current module needs to be added to the filter modules list (i.e. {"modules": ["Main", "Prelude",
or the filter needs to be empty ('filters': []
) is also affecting Ptype
and PSCIDEtype
as I have come across in #122 .
I'd therefore suggest to change s:getType
instead of PSCIDEaddTypeAnnotation
like so:
function! s:getType(ident, filterModules, cb)
let currentModule = purescript#ide#utils#currentModule()
if a:filterModules
let [ident, qualifier] = purescript#ide#utils#splitQualifier(a:ident)
let imports = purescript#ide#import#listImports(currentModule, qualifier, "")
let modules = map(copy(imports), {key, val -> val["module"]})
let filters = [purescript#ide#utils#modulesFilter( add(modules, currentModule) )]
else
let filters = []
endif
call purescript#ide#utils#debug('PSCIDE s:getType currentModule: ' . currentModule, 3)
call purescript#ide#call(
\ { 'command': 'type'
\ , 'params':
\ { 'search': ident
\ , 'filters': filters
\ , 'currentModule': currentModule
\ }
\ },
\ 'Failed to get type info for: ' . a:ident,
\ 0,
\ {resp -> a:cb(resp)}
\ )
endfunction
Let me know if this fixed the issue for you.