Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PaddType throws no information found, but pulp server inferring declaration fine #113

Closed
srghma opened this issue Oct 14, 2017 · 13 comments
Closed

Comments

@srghma
Copy link

srghma commented Oct 14, 2017

No description provided.

@kritzcreek
Copy link
Collaborator

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.

@srghma
Copy link
Author

srghma commented Oct 14, 2017

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.

@srghma srghma changed the title add :GhcModTypeInsert (Insert type of expression into previous line) PSCIDEaddTypeAnnotation, PSCIDEapplySuggestion throws error "not enough arguments" Oct 14, 2017
@srghma srghma changed the title PSCIDEaddTypeAnnotation, PSCIDEapplySuggestion throws error "not enough arguments" PaddType throws no information found, but pulp server inferring declaration fine Oct 14, 2017
@kritzcreek
Copy link
Collaborator

Maybe @coot can help here? I'm not using the VIM plugin currently.

@kritzcreek
Copy link
Collaborator

It looks like #99 might be related.

@coot
Copy link
Collaborator

coot commented Oct 17, 2017

I'll take a look somewhere this week, thanks for the report.

@srghma
Copy link
Author

srghma commented Oct 18, 2017

@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

@kritzcreek
Copy link
Collaborator

kritzcreek commented Oct 18, 2017

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.

@srghma
Copy link
Author

srghma commented Oct 18, 2017

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

@kritzcreek
Copy link
Collaborator

@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.

@srghma
Copy link
Author

srghma commented Oct 18, 2017

@kritzcreek yes, plugin does this here

Thanks, very helpful, I'll made fix soon)

srghma pushed a commit to srghma/psc-ide-vim that referenced this issue Oct 19, 2017
srghma pushed a commit to srghma/psc-ide-vim that referenced this issue Oct 19, 2017
@srghma
Copy link
Author

srghma commented Oct 19, 2017

@kritzcreek made pr, can someone check

@andreasthoelke
Copy link

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

coot pushed a commit to coot/psc-ide-vim that referenced this issue Dec 14, 2017
@coot coot closed this as completed in 6c78b38 Dec 14, 2017
@coot
Copy link
Collaborator

coot commented Dec 14, 2017

Let me know if this fixed the issue for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants