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

Does auto-completion on pipe operator only worked for type t in Module? #792

Closed
Mng12345 opened this issue Jul 4, 2023 · 10 comments
Closed

Comments

@Mng12345
Copy link

Mng12345 commented Jul 4, 2023

See the gif screen-shot below:
mnggiflab-compressed-from-screen-recorder-2023_07_0417_44_03
The example code is here:

type m = {
  name: string,
  age: int,
}

module M1 = {
  type t = m

  let getName = (m: t): string => {
    m.name
  }
}

module M2 = {
  type t = m

  type m = m
  let getAge = (m: t): int => {
    m.age
  }

  let getAge2 = (m: m): int => {
    m.age
  }
}

type m2 = M2.m

type m3 = M2.t

let m1: m = {
  age: 1,
  name: "m",
}

let m2: m2 = {
  age: 1,
  name: "m",
}

let m3: m3 = {
  age: 1,
  name: "m",
}

envrionment info: rescript v10.1.2 rescript-vscode v1.18.0
I have debugged the analysis, the auto completion for m-> walked into this switch, the variable pathRev is an empty list, is auto completion for normal type (not type t of a module) not considered for now?
image

@zth
Copy link
Collaborator

zth commented Jul 5, 2023

This is about resolving type aliases. When resolving type aliases, we stop at t specifically because we interpret that as an intention that t is the main type of a module.

For types that aren't aliases, you'll get completions from the full module.

@Mng12345
Copy link
Author

Mng12345 commented Jul 6, 2023

So, if a type t alias some type m, then the auto-completion of a variable a(assume it's type is annotated with m) should be considered the same as type t. This form of auto-completion is usable in other languages like Scala (this is called implicit class, i think we can make the same effect in ide). I think this is very useful, you can just define a type m, and alias it in two or three and more different module if the business need, then you can get the auto-completions of all the function of different modules. This feature would be very cool!

@Mng12345
Copy link
Author

Mng12345 commented Jul 6, 2023

Another point i think is also very useful is auto completion of aliased module, if a type t is defined in module LongPath.M, and you aliased the module LongPath.M in current scope with module M, the auto-completion of variable a with type LongPath.M.t should be replaced by module M not LongPath.M. The module System of ReScript and OCaml is very flexible, may be the ide editor limited it's power as the Short aliased module would not trigger auto completion for now.

@fhammerschmidt
Copy link
Member

I think aliased record types should expand as well, except if they are private. Currently, I copy a lot of type definitions over to have autocomplete. This does not feel right.

@zth
Copy link
Collaborator

zth commented Oct 16, 2023

Can you write a few examples of what that means and what the trade offs would be?

@fhammerschmidt
Copy link
Member

fhammerschmidt commented Oct 17, 2023

I created a failing test here: #834
The weird thing is, it should work according to #557, but doesn't

@zth
Copy link
Collaborator

zth commented Oct 17, 2023

Sorry but I still don't understand the problem. That failing test is for a hover, but here you're talking about autocomplete. And this issue is about pipe autocompletion specifically. Could you clarify exactly what the problem(s) are and how they relate to this issue (pipe completion)?

@Mng12345
Copy link
Author

@zth Hi, i think @fhammerschmidt means that when we define a type a which is aliased to a type t, t is defined in a module, the pipe completion of variables with type t are worked, but not worked with type a.

@fhammerschmidt
Copy link
Member

Sorry for hijacking this issue, and for using hover and autocomplete synonymous. I tested autocomplete and it works for aliased records (I thought it does not), but not hover.

@Mng12345
Copy link
Author

Wow! This is worked now!!!
image

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

3 participants