Skip to content

Commit d12022d

Browse files
T-GroCopilotCopilot
authored
Suggest module opens for active-pattern cases (#20719)
* Stabilize active-pattern tooling and measured catalogue cache Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Separate AP tooling from the independent catalogue cache Preserve the complete source snapshot for the cache owner, remove only the cache slice, reuse editor test helpers, and prepare release notes. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Reuse current-project symbol catalogues in Visual Studio Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Link active-pattern tooling release notes to the draft PR Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Link the Visual Studio cache release note Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Fix desktop edit-test APIs and compact verified assertion recipes Preserve all completion and editor scenarios while using the net472-compatible Replace overload and existing edited-source assertions. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Separate the dependent editor layer from FCS case completion Preserve the tested complete source and exact editor export while retaining the FCS completion/catalogue changes and release note in this lower draft. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Fix catalogue cache test name resolution Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Offer valid active-pattern imports and completion edits Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Link editor release note to its dependent draft Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Wire cache reference tests through Roslyn metadata Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Validate pull requests targeting maintainer branches Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Apply referenced cache fixtures to the editor workspace Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Deduplicate qualified case imports and normalize editor fixtures Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Keep completion imports in the consuming namespace Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Consolidate the complete active-pattern feature in one draft Keep the reviewed FCS, editor and catalogue-cache histories; remove the discarded stack-only CI filter and link all release notes to PR20719. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Fix active-pattern open naming and editor placement Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Anchor compiler namespace in editor completion tests Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Correct active-pattern option test entry and preserve context guards Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Reuse identifier projection and catalogue assertion recipe Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Reject insertion candidates before selecting completed module scope Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Restore original catalogue file ending Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Create insertion naming scope once per request Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Select one Git executable in PR validation fixture Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Share active-pattern editor assertion and option recipes Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Share FCS unused-open and case-identity assertions Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Reuse insertion modes and fresh codefix test recipes Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Retry DNS failures during test-result verification Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Load HTTP dependency before typed publisher verification Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Fix CI failures after merge The main-branch publisher revert in the merge removes the Windows HTTP type-loading and macOS DNS verification failures. No additional source changes are required. Validated the full Release product build, both FCS target frameworks, all editor tests, isolated active-pattern regressions, formatting, and PR-validation Git fixtures. The extra legacy VS file-movement tests require a VS installation matching the repository 18.9 packages. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot <copilot@github.com>
1 parent a63c579 commit d12022d

21 files changed

Lines changed: 1794 additions & 127 deletions

‎docs/release-notes/.FSharp.Compiler.Service/11.0.200.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Completion: respect EditorBrowsableAttribute ([PR #20729](https://github.com/dotnet/fsharp/pull/20729))
55
* Runtime-async sequences allow awaits inside `try/with` bodies, filters and handlers, and reject overlapping `MoveNextAsync` calls. ([PR #20655](https://github.com/dotnet/fsharp/pull/20655))
66
* F# Interactive gains a JSON-RPC server mode, `--fsi-server-jsonrpc:<pipe name>`, in which a host submits interactions over a named pipe and receives structured results — diagnostics with positions, escaping exceptions, the values each interaction bound, and the session's own process id — instead of recovering them by looking for a `SERVER-PROMPT>` marker in the output text. Program output continues to flow through the redirected console streams. The pipe admits only the user running the session; `--fsi-server-client-pid:<pid>` names the host process whose exit ends the session. `FsiEvaluationSession` exposes both options as `JsonRpcServerPipeName` and `JsonRpcClientProcessId`. The mode is part of the .NET fsi only. ([PR #20396](https://github.com/dotnet/fsharp/pull/20396))
7+
* Include individual active-pattern cases from unopened modules in pattern completion. ([PR #20719](https://github.com/dotnet/fsharp/pull/20719))
78

89
### Fixed
910

‎docs/release-notes/.VisualStudio/18.vNext.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### Added
22

3+
* Suggest active-pattern cases from unopened modules and offer valid Add Open and qualification edits. ([PR #20719](https://github.com/dotnet/fsharp/pull/20719))
34
* Add maintainer-requested F# Apex Visual Studio integration tests on DartLab-1ES CloudTest, using PR pipeline definitions pinned to an explicitly requested commit SHA. ([PR #20625](https://github.com/dotnet/fsharp/pull/20625))
45
* Code-fixes for FS3888 (compiler-semantic attribute on the `.fs` but not the `.fsi`): copy the attribute into the `.fsi`, or remove it from the `.fs`. ([Issue #19560](https://github.com/dotnet/fsharp/issues/19560), [PR #19880](https://github.com/dotnet/fsharp/pull/19880))
56
* Expand `<inheritdoc/>` in IDE tooltips, completion, and signature help, inheriting XML documentation from base classes, interfaces, overridden members, and constructors. ([Issue #19175](https://github.com/dotnet/fsharp/issues/19175), [PR #19188](https://github.com/dotnet/fsharp/pull/19188))
@@ -23,6 +24,7 @@
2324
* Fix `NotSupportedException` in the memory-mapped-file optimization when copying `ReadOnlyMemory` into `MemoryMappedFileViewStream`. ([Issue #20263](https://github.com/dotnet/fsharp/issues/20263))
2425
* Reduce allocations in the VS project options reactor: the command-line options and project options caches and the mailbox reply payloads now hold struct tuples, and `IProjectSite.CompilationBinOutputPath` returns `string voption` picked with a new `Array.tryPickV`. ([PR #20413](https://github.com/dotnet/fsharp/pull/20413))
2526
* Build a single-file project's `OtherOptions` reference flags with one array comprehension instead of two `Array.ofSeq` calls and an `Array.append`. ([PR #20499](https://github.com/dotnet/fsharp/pull/20499))
27+
* Keep concurrent completion requests from mixing their suggestion lists. ([PR #20719](https://github.com/dotnet/fsharp/pull/20719))
2628
* Fix syntax coloring being lost for a whole file when one symbol resolves into metadata that could not be read. ([Issue #20269](https://github.com/dotnet/fsharp/issues/20269), [PR #20274](https://github.com/dotnet/fsharp/pull/20274))
2729
* Go To Definition into an F# project built with a path map (`DeterministicSourcePaths` or `PathMap`) opens its source instead of a generated signature: the IDE no longer applies `--pathmap` to the project options it checks with. ([PR #20470](https://github.com/dotnet/fsharp/pull/20470))
2830
* Fix completion after a closed backticked identifier on the same line. ([PR #20785](https://github.com/dotnet/fsharp/issues/20785))
@@ -31,6 +33,7 @@
3133

3234
* Rename "inline hints" to "inlay hints" in VS options for consistency with industry terminology. ([PR #19318](https://github.com/dotnet/fsharp/pull/19318))
3335
* Unused analyzers: disable in VS when file has errors ([PR #19892](https://github.com/dotnet/fsharp/pull/19892))
36+
* Reuse current-project symbol catalogues for completion and Add Open requests that share a file-check result. ([PR #20719](https://github.com/dotnet/fsharp/pull/20719))
3437
* Move to Roslyn's unified ExternalAccess library ([PR #20099](https://github.com/dotnet/fsharp/pull/20099))
3538
* Remove trailing whitespace from source files. No functional change: whitespace inside string literals and inactive `#if` regions is preserved. ([PR #20355](https://github.com/dotnet/fsharp/pull/20355))
3639
* The VS project options reactor keeps single-file and script project options in a named record instead of a five-place tuple, and its text-view subscription plumbing uses `voption` instead of `option`. ([PR #20455](https://github.com/dotnet/fsharp/pull/20455))

‎src/Compiler/Checking/NameResolution.fsi‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,5 +1009,7 @@ val GetVisibleNamespacesAndModulesAtPoint:
10091009

10101010
val IsItemResolvable: NameResolver -> NameResolutionEnv -> range -> AccessorDomain -> string list -> Item -> bool
10111011

1012+
val ItemIsUnseen: AccessorDomain -> TcGlobals -> ImportMap -> range -> allowUnseen: UnseenItems -> Item -> bool
1013+
10121014
val TrySelectExtensionMethInfoOfILExtMem:
10131015
range -> ImportMap -> TType -> TyconRef * MethInfo * ExtensionMethodPriority -> MethInfo option

‎src/Compiler/FSharp.Compiler.Service.fsproj‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,6 @@
580580
<Compile Include="Service\ServiceCompilerDiagnostics.fsi" />
581581
<Compile Include="Service\ServiceCompilerDiagnostics.fs" />
582582
<Compile Include="Service\ServiceConstants.fs" />
583-
<Compile Include="Service\ServiceDeclarationLists.fsi" />
584-
<Compile Include="Service\ServiceDeclarationLists.fs" />
585583
<Compile Include="Service\ServiceLexing.fsi" />
586584
<Compile Include="Service\ServiceLexing.fs" />
587585
<Compile Include="Service\ServiceParseTreeWalk.fsi" />
@@ -598,6 +596,8 @@
598596
<Compile Include="Service\FSharpParseFileResults.fs" />
599597
<Compile Include="Service\ServiceParsedInputOps.fsi" />
600598
<Compile Include="Service\ServiceParsedInputOps.fs" />
599+
<Compile Include="Service\ServiceDeclarationLists.fsi" />
600+
<Compile Include="Service\ServiceDeclarationLists.fs" />
601601
<Compile Include="Service\ServiceAssemblyContent.fsi" />
602602
<Compile Include="Service\ServiceAssemblyContent.fs" />
603603
<Compile Include="Service\ServiceXmlDocParser.fsi" />

‎src/Compiler/Service/FSharpCheckerResults.fs‎

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,10 +1584,15 @@ type internal TypeCheckInfo
15841584
loc,
15851585
filterCtors,
15861586
resolveOverloads,
1587-
isInRangeOperator,
1587+
completionContext: CompletionContext option,
15881588
allSymbols: unit -> AssemblySymbol list,
15891589
options: FSharpCodeCompletionOptions
15901590
) =
1591+
let isInRangeOperator =
1592+
match completionContext with
1593+
| Some CompletionContext.RangeOperator -> true
1594+
| _ -> false
1595+
15911596
let isSpread =
15921597
FindFirstNonWhitespacePosition lineStr (colAtEndOfNamesAndResidue - 1)
15931598
|> Option.exists (fun i ->
@@ -1779,6 +1784,11 @@ type internal TypeCheckInfo
17791784
&&
17801785

17811786
match x.Symbol with
1787+
| :? FSharpActivePatternCase as symbol ->
1788+
match symbol.Item, completionContext with
1789+
| Item.ActivePatternCase case, Some(CompletionContext.Pattern _) ->
1790+
not (ItemIsUnseen ad g ncenv.amap m options.AllowUnseen (Item.Value case.ActivePatternVal))
1791+
| _ -> false
17821792
| :? FSharpMemberOrFunctionOrValue as m when
17831793
m.IsConstructor && filterCtors = ResolveTypeNamesToTypeRefs
17841794
->
@@ -1849,6 +1859,16 @@ type internal TypeCheckInfo
18491859
| atStart when atStart = 0 -> 0
18501860
| otherwise -> otherwise - 1
18511861

1862+
let pos = mkPos line colAtEndOfNamesAndResidue
1863+
1864+
let completionContext =
1865+
match completionContextAtPos with
1866+
| Some(contextForPos, context) when contextForPos = pos -> context
1867+
| _ ->
1868+
parseResultsOpt
1869+
|> Option.map (fun x -> x.ParseTree)
1870+
|> Option.bind (fun parseTree -> ParsedInput.TryGetCompletionContext(pos, parseTree, lineStr))
1871+
18521872
let getDeclaredItemsNotInRangeOpWithAllSymbols () =
18531873
GetDeclaredItems(
18541874
parseResultsOpt,
@@ -1861,24 +1881,11 @@ type internal TypeCheckInfo
18611881
loc,
18621882
filterCtors,
18631883
resolveOverloads,
1864-
false,
1884+
completionContext,
18651885
getAllSymbols,
18661886
options
18671887
)
18681888

1869-
let pos = mkPos line colAtEndOfNamesAndResidue
1870-
1871-
// Look for a "special" completion context
1872-
let completionContext =
1873-
// If the completion context we have computed higher up the stack is for the same position,
1874-
// reuse it, otherwise recompute
1875-
match completionContextAtPos with
1876-
| Some(contextForPos, context) when contextForPos = pos -> context
1877-
| _ ->
1878-
parseResultsOpt
1879-
|> Option.map (fun x -> x.ParseTree)
1880-
|> Option.bind (fun parseTree -> ParsedInput.TryGetCompletionContext(pos, parseTree, lineStr))
1881-
18821889
let res =
18831890
match completionContext with
18841891
// Invalid completion locations
@@ -1923,7 +1930,7 @@ type internal TypeCheckInfo
19231930
loc,
19241931
filterCtors,
19251932
resolveOverloads,
1926-
false,
1933+
None,
19271934
(fun () -> []),
19281935
options
19291936
)
@@ -1948,7 +1955,7 @@ type internal TypeCheckInfo
19481955
loc,
19491956
filterCtors,
19501957
resolveOverloads,
1951-
false,
1958+
None,
19521959
(fun () -> []),
19531960
options
19541961
)
@@ -1970,7 +1977,7 @@ type internal TypeCheckInfo
19701977
loc,
19711978
filterCtors,
19721979
resolveOverloads,
1973-
false,
1980+
None,
19741981
(fun () -> []),
19751982
options
19761983
)
@@ -2139,11 +2146,6 @@ type internal TypeCheckInfo
21392146
// because providing generic parameters list is context aware, which we don't have here (yet).
21402147
None
21412148
| _ ->
2142-
let isInRangeOperator =
2143-
(match cc with
2144-
| Some CompletionContext.RangeOperator -> true
2145-
| _ -> false)
2146-
21472149
GetDeclaredItems(
21482150
parseResultsOpt,
21492151
lineStr,
@@ -2155,7 +2157,7 @@ type internal TypeCheckInfo
21552157
loc,
21562158
filterCtors,
21572159
resolveOverloads,
2158-
isInRangeOperator,
2160+
cc,
21592161
getAllSymbols,
21602162
options
21612163
)
@@ -2247,13 +2249,19 @@ type internal TypeCheckInfo
22472249
items
22482250

22492251
let getAccessibility item =
2250-
FSharpSymbol.Create(cenv, item).Accessibility
2252+
match item with
2253+
| Item.ActivePatternCase case -> FSharpAccessibility(case.ActivePatternVal.Accessibility)
2254+
| _ -> FSharpSymbol.Create(cenv, item).Accessibility
22512255

2252-
let currentNamespaceOrModule =
2256+
let scopeInfo =
22532257
parseResultsOpt
22542258
|> Option.map (fun x -> x.ParseTree)
2255-
|> Option.map (fun parsedInput ->
2256-
ParsedInput.GetFullNameOfSmallestModuleOrNamespaceAtPoint(mkPos line 0, parsedInput))
2259+
|> Option.map (fun parsedInput -> ParsedInput.getScopeInfo (mkPos line 0, parsedInput))
2260+
2261+
let currentNamespaceOrModule =
2262+
scopeInfo |> Option.map (fun struct (path, _) -> path)
2263+
2264+
let currentScope = scopeInfo |> Option.map (fun struct (_, scope) -> scope)
22572265

22582266
let isAttributeApplication =
22592267
match ctx with
@@ -2268,6 +2276,7 @@ type internal TypeCheckInfo
22682276
getAccessibility,
22692277
items,
22702278
currentNamespaceOrModule,
2279+
currentScope,
22712280
isAttributeApplication
22722281
))
22732282
(fun msg ->

‎src/Compiler/Service/ServiceAssemblyContent.fs‎

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ open System.Collections.Generic
1212
open Internal.Utilities.Library
1313
open FSharp.Compiler.Diagnostics
1414
open FSharp.Compiler.IO
15+
open FSharp.Compiler.NameResolution
1516
open FSharp.Compiler.Symbols
1617
open FSharp.Compiler.Syntax
1718

@@ -168,23 +169,36 @@ module AssemblyContent =
168169
UnresolvedSymbol = UnresolvedSymbol topRequireQualifiedAccessParent cleanIdents fullName ns
169170
})
170171

171-
let traverseMemberFunctionAndValues ns (parent: Parent) (membersFunctionsAndValues: seq<FSharpMemberOrFunctionOrValue>) =
172+
let createFunctionOrValue ns (parent: Parent) =
172173
let topRequireQualifiedAccessParent = parent.TopRequiresQualifiedAccess false |> Option.map parent.FixParentModuleSuffix
174+
let nearestRequireQualifiedAccessParent = parent.ThisRequiresQualifiedAccess true |> Option.map parent.FixParentModuleSuffix
173175
let autoOpenParent = parent.AutoOpen |> Option.map parent.FixParentModuleSuffix
176+
fun fullName idents (symbol: FSharpSymbol) isActivePattern ->
177+
let cleanedIdents = parent.FixParentModuleSuffix idents
178+
{ FullName = fullName
179+
CleanedIdents = cleanedIdents
180+
Namespace = ns
181+
NearestRequireQualifiedAccessParent = nearestRequireQualifiedAccessParent
182+
TopRequireQualifiedAccessParent = topRequireQualifiedAccessParent
183+
AutoOpenParent = autoOpenParent
184+
Symbol = symbol
185+
Kind = fun _ -> EntityKind.FunctionOrValue isActivePattern
186+
UnresolvedSymbol = UnresolvedSymbol topRequireQualifiedAccessParent cleanedIdents fullName ns }
187+
188+
let isPublic (symbol: FSharpSymbol) =
189+
match symbol with
190+
| :? FSharpActivePatternCase ->
191+
match symbol.Item with
192+
| Item.ActivePatternCase case -> case.ActivePatternVal.Accessibility.IsPublic
193+
| _ -> symbol.Accessibility.IsPublic
194+
| _ -> symbol.Accessibility.IsPublic
195+
196+
let traverseMemberFunctionAndValues (createSymbol: string -> ShortIdents -> FSharpSymbol -> bool -> AssemblySymbol) (membersFunctionsAndValues: seq<FSharpMemberOrFunctionOrValue>) =
174197
membersFunctionsAndValues
175198
|> Seq.filter (fun x -> not x.IsInstanceMember && not x.IsPropertyGetterMethod && not x.IsPropertySetterMethod)
176199
|> Seq.collect (fun func ->
177200
let processIdents fullName idents =
178-
let cleanedIdents = parent.FixParentModuleSuffix idents
179-
{ FullName = fullName
180-
CleanedIdents = cleanedIdents
181-
Namespace = ns
182-
NearestRequireQualifiedAccessParent = parent.ThisRequiresQualifiedAccess true |> Option.map parent.FixParentModuleSuffix
183-
TopRequireQualifiedAccessParent = topRequireQualifiedAccessParent
184-
AutoOpenParent = autoOpenParent
185-
Symbol = func
186-
Kind = fun _ -> EntityKind.FunctionOrValue func.IsActivePattern
187-
UnresolvedSymbol = UnresolvedSymbol topRequireQualifiedAccessParent cleanedIdents fullName ns }
201+
createSymbol fullName idents func func.IsActivePattern
188202

189203
[ yield! func.TryGetFullDisplayName()
190204
|> Option.map (fun fullDisplayName ->
@@ -252,9 +266,23 @@ module AssemblyContent =
252266
Namespace = ns
253267
IsModule = entity.IsFSharpModule }
254268

269+
let createValue = createFunctionOrValue ns currentParent
255270
match entity.TryGetMembersFunctionsAndValues() with
256271
| xs when xs.Count > 0 ->
257-
yield! traverseMemberFunctionAndValues ns currentParent xs
272+
yield! traverseMemberFunctionAndValues createValue xs
273+
| _ -> ()
274+
275+
match currentEntity with
276+
| Some moduleSymbol when entity.IsFSharpModule ->
277+
for case in entity.ActivePatternCases do
278+
if contentType = Full || isPublic case then
279+
let idents = Array.append moduleSymbol.CleanedIdents [| case.Name |]
280+
let symbol = createValue case.FullName idents case true
281+
let struct (_, openableNs, restIdents) =
282+
Entity.getOpenableNamespace symbol.TopRequireQualifiedAccessParent symbol.AutoOpenParent symbol.CleanedIdents
283+
yield { symbol with
284+
UnresolvedSymbol =
285+
UnresolvedSymbol None (Array.append openableNs restIdents) case.FullName (Some openableNs) }
258286
| _ -> ()
259287

260288
for e in (try entity.NestedEntities :> _ seq with _ -> Seq.empty) do
@@ -312,7 +340,7 @@ module AssemblyContent =
312340
|> List.filter (fun entity ->
313341
match contentType with
314342
| Full -> true
315-
| Public -> entity.Symbol.Accessibility.IsPublic)
343+
| Public -> isPublic entity.Symbol)
316344

317345
type EntityCache() =
318346
let dic = Dictionary<AssemblyPath, AssemblyContentCacheEntry>()

0 commit comments

Comments
 (0)