Purescript: purs ide: type information by range (like :GhcModType does)

Created on 6 Jun 2019  路  3Comments  路  Source: purescript/purescript

from https://github.com/FrigoEU/psc-ide-vim/issues/147 and https://github.com/FrigoEU/psc-ide-vim/issues/112

Having

module Main where

import Prelude

import Effect (Effect)
import Effect.Console (log)

main :: Effect Unit
main = do
  let a = 1 -- can't get type of a
  log "hi" -- but can get type of log

Expected:

when my cursor at a variable and I do :Ptype - it should show type inferred of a

Actual:

I have NO way to see the inferred type of a

it shows purs ide: no type information found for a

logs show that it tries to find type definition of a in imported modules

purescript#ide#call: command: {"params": {"currentModule": "Main", "search": "a", "filters": [{"filter": "modules", "params": {"modules"
: ["Prelude", "Main"]}}]}, "command": "type"}

Proposal:

  • extend purs ide server so it derive type of range? something like language-server does (https://microsoft.github.io/language-server-protocol/specification)
{
    start: { line: 5, character: 23 },
    end : { line 6, character : 0 }
}

N.B.

maybe someone knows other way to see the derived type of a?

Most helpful comment

proposal:

  1. when range is not selected, position of 1 char is sent to purs ide - no changes

  2. when range is selected, range is sent to purs ide - purs ide wraps selected text in hole and returns type of a hole

e.g.

user selects log "hi"

in

main :: Effect Unit
main = do
  log "hi"

purs ide internally wraps log "hi" in parenthesis, like

main :: Effect Unit
main = do
  (log "hi" :: ?what)

and returns type of hole ?what

All 3 comments

maybe someone knows other way to see the derived type of a?

You could use a hole let a = 1 :: ?what. That might fail in some situations if classes are involved though.

For a while I've thought that this would come naturally if we move to the LSP directly in purs ide - but maybe ala that range suggestion an interim step makes sense.

proposal:

  1. when range is not selected, position of 1 char is sent to purs ide - no changes

  2. when range is selected, range is sent to purs ide - purs ide wraps selected text in hole and returns type of a hole

e.g.

user selects log "hi"

in

main :: Effect Unit
main = do
  log "hi"

purs ide internally wraps log "hi" in parenthesis, like

main :: Effect Unit
main = do
  (log "hi" :: ?what)

and returns type of hole ?what

Was this page helpful?
0 / 5 - 0 ratings