dotnet / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
3.88k stars 783 forks source link

Code completion doesn't work inside Or pattern #16055

Open auduchinok opened 1 year ago

auduchinok commented 1 year ago

Consider code completion is triggered after | in this code:

module Module

match () with
| (_ | )

Expected: types, union cases, literals, and active patterns are provided Actual: the items are not provided

This may be related to either changes in the parser or to completion filtering.

0101 commented 12 months ago

Can we have a more meaningful example? I'm a bit confused by the example expression here.

vzarytovskii commented 12 months ago

Can we have a more meaningful example? I'm a bit confused by the example expression here.

I presume this:


module Module

match () with
| (_ | <here should be an autocomplete, but there's none> )
0101 commented 12 months ago

I didn't know you could put parentheses around some cases. Is there even any point to that?

Also in this example, you already gave a _ which will match anything, so there are no meaningful completions because that branch will never be matched. And even if it was, you're matching () so there are no really meaningful completions for that.

I don't know if in the code we are looking at any of that, but still, a better example would be something where some completions would make sense. In this particular case nothing being suggested looks like a feature 😄

auduchinok commented 12 months ago

I didn't know you could put parentheses around some cases. Is there even any point to that? Also in this example, you already gave a _ which will match anything, so there are no meaningful completions because that branch will never be matched.

In test cases like this it doesn't matter if _ is matched, or if there's _ at all. It's just a minimized version of a particular language construction used in a code completion test. The example could be longer and with more identifiers:

type U =
    | A
    | B
    | C

let f (u: U) =
    match u with
    | (A | {caret}) -> ()

Here, at the {caret} position, code completion is expected to work. The minimized example shows exactly this without the noise added by additional definitions.

kerams commented 12 months ago

There's a SynPat.Wild with non-zero-length range in that exact position for some reason. It is interpreted as a real wildcard, hence no completions. Representation of incomplete constructs could do with an overhaul in the syntax tree.

You get completions as soon as you type another letter, so while this is a regression, it's nothing tragic.

auduchinok commented 12 months ago

@kerams Thanks for investigation!

Representation of incomplete constructs could do with an overhaul in the syntax tree.

I agree, we should make the pattern errors look similar to the expression ones.