Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/release-notes/.FSharp.Compiler.Service/11.0.200.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Completion: respect EditorBrowsableAttribute ([PR #20729](https://github.com/dotnet/fsharp/pull/20729))
* 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))
* 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))
* A parameter or type parameter named in a `<param>`, `<paramref>`, `<typeparam>` or `<typeparamref>` tag of its declaration's XML doc is reported as a `RelatedSymbolUseKind.XmlDocParameter` use, found through the new `XmlDoc.LineRanges` and `XmlDoc.GetRefs`. `AllInCode` leaves these out and `AllInCodeAndDocs` includes them; `All` is obsolete and means `AllInCode`, also for callers compiled against it. ([Issue #20630](https://github.com/dotnet/fsharp/issues/20630), [Issue #15134](https://github.com/dotnet/fsharp/issues/15134), [PR #20637](https://github.com/dotnet/fsharp/pull/20637))
* `FSharpCheckFileResults.GetUsesOfSymbolInFile` and `GetSemanticClassification` have an overload whose `relatedSymbolKinds` is a struct option (`voption`). The overloads that take a `RelatedSymbolUseKind option` are obsolete and stay for binary compatibility; a call that passes `?relatedSymbolKinds` an `option` has to pass a `voption` instead. ([PR #20637](https://github.com/dotnet/fsharp/pull/20637))
* Include individual active-pattern cases from unopened modules in pattern completion. ([PR #20719](https://github.com/dotnet/fsharp/pull/20719))

### Fixed
Expand Down
1 change: 1 addition & 0 deletions docs/release-notes/.VisualStudio/18.vNext.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* `FSharpProjectSnapshot`: source files and referenced projects are arrays instead of lists. ([PR #20875](https://github.com/dotnet/fsharp/pull/20875))
* Rename "inline hints" to "inlay hints" in VS options for consistency with industry terminology. ([PR #19318](https://github.com/dotnet/fsharp/pull/19318))
* Unused analyzers: disable in VS when file has errors ([PR #19892](https://github.com/dotnet/fsharp/pull/19892))
* Use `RelatedSymbolUseKind.AllInCode` in place of the now obsolete `All`. No functional change. ([PR #20637](https://github.com/dotnet/fsharp/pull/20637))
* 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))
* Move to Roslyn's unified ExternalAccess library ([PR #20099](https://github.com/dotnet/fsharp/pull/20099))
* 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))
Expand Down
17 changes: 17 additions & 0 deletions src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,22 @@ module TcRecdUnionAndEnumDeclarations =

let checkXmlDocs = cenv.diagnosticOptions.CheckXmlDocs
let xmlDoc = xmldoc.ToXmlDoc(checkXmlDocs, Some names)

match parent with
| Parent tcref ->
let fieldCandidates () =
let candidates = ImmutableArrayBuilder.create rfields.Length

rfields
|> List.iteri (fun i f ->
if not f.rfield_name_generated then
candidates.Add(struct (f.LogicalName, Item.UnionCaseField (UnionCaseInfo (thisTyInst, UnionCaseRef (tcref, id.idText)), i))))

candidates.ToImmutable()

ReportXmlDocRefUses cenv.tcSink xmlDoc fieldCandidates (fun () -> ImmutableArray.empty)
| ParentNone -> ()

let attrs, getFinalAttrs, _ = TcAttributesCanFail cenv env AttributeTargets.UnionCaseDecl synAttrs
let unionCase = Construct.NewUnionCase id rfields recordTy attrs xmlDoc vis

Expand Down Expand Up @@ -2927,6 +2943,7 @@ module EstablishTypeDefinitionCores =

let checkXmlDocs = cenv.diagnosticOptions.CheckXmlDocs
let xmlDoc = xmlDoc.ToXmlDoc(checkXmlDocs, Some paramNames )
ReportXmlDocRefUses cenv.tcSink xmlDoc (fun () -> ImmutableArray.empty) (fun () -> XmlDocTyparCandidates checkedTypars)
Construct.NewTycon
(cpath, id.idText, id.idRange, vis, visOfRepr, TyparKind.Type, LazyWithContext.NotLazy checkedTypars,
xmlDoc, preferPostfix, preEstablishedHasDefaultCtor, hasSelfReferentialCtor, lmodTy)
Expand Down
11 changes: 11 additions & 0 deletions src/Compiler/Checking/CheckIncrementalClasses.fs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,17 @@ let TcImplicitCtorInfo_Phase2A(cenv: cenv, env, tpenv, tcref: TyconRef, vis, att
let checkXmlDocs = cenv.diagnosticOptions.CheckXmlDocs
let xmlDoc = xmlDoc.ToXmlDoc(checkXmlDocs, Some paramNames)
let ctorVal = MakeAndPublishVal cenv env (Parent tcref, false, ModuleOrMemberBinding, ValInRecScope isComplete, ctorValScheme, attribs, xmlDoc, None, false)

let ctorParameters () =
let candidates = ImmutableArrayBuilder.create ctorArgs.Length

for v in ctorArgs do
candidates.Add(struct (v.LogicalName, Item.Value(mkLocalValRef v)))

candidates.MoveToImmutable()

ReportXmlDocRefUses cenv.tcSink xmlDoc ctorParameters (fun () -> ImmutableArray.empty)
ReportXmlDocRefUses cenv.tcSink tcref.Deref.XmlDoc ctorParameters (fun () -> ImmutableArray.empty)
ctorValScheme, ctorVal

let thisVal =
Expand Down
39 changes: 38 additions & 1 deletion src/Compiler/Checking/Expressions/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11535,6 +11535,7 @@ and TcNormalizedBinding declKind (cenv: cenv) env tpenv overallTy safeThisValOpt
| NormalizedBinding(vis, kind, isInline, isMutable, attrs, xmlDoc, _, valSynData, pat, NormalizedBindingRhs(spatsL, _, rhsExpr), _, debugPoint) ->
let (SynValData(memberFlags = memberFlagsOpt)) = valSynData
let mBinding = pat.Range
let outerTpenv = tpenv

let isClassLetBinding =
match declKind, kind with
Expand Down Expand Up @@ -11757,6 +11758,36 @@ and TcNormalizedBinding declKind (cenv: cenv) env tpenv overallTy safeThisValOpt
if isFixed then TcAndBuildFixedExpr cenv env (overallPatTy, rhsExprChecked, overallExprTy, mBinding)
else rhsExprChecked

let parameterCandidates () =
let candidates = ImmutableArrayBuilder.create 4

let rec addLambdaBinders expr =
match stripDebugPoints expr with
| Expr.Lambda (_, _, _, vs, body, _, _) ->
for v in vs do
if not (v.IsMemberThisVal || v.IsCtorThisVal || v.IsCompilerGenerated) then
candidates.Add(struct (v.LogicalName, Item.Value(mkLocalValRef v)))

addLambdaBinders body
| _ -> ()

addLambdaBinders rhsExprChecked
candidates.ToImmutable()

let typarCandidates () =
let (UnscopedTyparEnv outer) = outerTpenv
let (UnscopedTyparEnv inner) = tpenv

XmlDocTyparCandidates
(seq {
yield! declaredTypars
for KeyValue(name, typar) in inner do
if not (outer.ContainsKey name) then
yield typar
})

ReportXmlDocRefUses cenv.tcSink xmlDoc parameterCandidates typarCandidates

match apinfoOpt with
| Some (apinfo, apOverallTy, m) ->
let activePatResTys = NewInferenceTypes g apinfo.ActiveTags
Expand Down Expand Up @@ -13660,9 +13691,14 @@ let private PublishArguments (cenv: cenv) (env: TcEnv) vspec (synValSig: SynValS
|> Seq.collect (fun x -> x ||> Seq.zip)
|> Seq.choose (fun (synArgInfo, argInfo) -> synArgInfo.Ident |> Option.map (pair argInfo))

let parameters = ImmutableArrayBuilder.create 4

for (argTy, argReprInfo), ident in argData do
let item = Item.OtherName (Some ident, argTy, Some argReprInfo, None, ident.idRange)
CallNameResolutionSink cenv.tcSink (ident.idRange, env.NameEnv, item, emptyTyparInst, ItemOccurrence.Binding, env.AccessRights)
parameters.Add(struct (ident.idText, item))

parameters.ToImmutable()

let TcAndPublishValSpec (cenv: cenv, env, containerInfo: ContainerInfo, declKind : DeclKind, memFlagsOpt, tpenv, synValSig) =

Expand Down Expand Up @@ -13751,7 +13787,8 @@ let TcAndPublishValSpec (cenv: cenv, env, containerInfo: ContainerInfo, declKind

let vspec = MakeAndPublishVal cenv env (altActualParent, true, declKind, ValNotInRecScope, valscheme, attrs, xmlDoc, literalValue, isGeneratedEventVal)

PublishArguments cenv env vspec synValSig allDeclaredTypars.Length
let parameters = PublishArguments cenv env vspec synValSig allDeclaredTypars.Length
ReportXmlDocRefUses cenv.tcSink xmlDoc (fun () -> parameters) (fun () -> XmlDocTyparCandidates generalizedTypars)

assert(vspec.InlineInfo = inlineFlag)

Expand Down
65 changes: 57 additions & 8 deletions src/Compiler/Checking/NameResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
/// Name environment and name resolution
module internal FSharp.Compiler.NameResolution

open System
open System.Collections.Generic
open System.Collections.Immutable

open Internal.Utilities.Collections
open Internal.Utilities.Library
Expand Down Expand Up @@ -33,6 +35,7 @@ open FSharp.Compiler.TypedTree
open FSharp.Compiler.TypedTreeBasics
open FSharp.Compiler.TypedTreeOps
open FSharp.Compiler.TypeHierarchy
open FSharp.Compiler.Xml

#if !NO_TYPEPROVIDERS
open FSharp.Compiler.TypeProviders
Expand Down Expand Up @@ -2328,7 +2331,7 @@ type TcResolutions
capturedExprTypes: ResizeArray<TType * NameResolutionEnv * AccessorDomain * range>,
capturedNameResolutions: ResizeArray<CapturedNameResolution>,
capturedMethodGroupResolutions: ResizeArray<CapturedNameResolution>,
capturedRelatedSymbolUses: ResizeArray<range * Item * RelatedSymbolUseKind>) =
capturedRelatedSymbolUses: ResizeArray<struct (range * Item * RelatedSymbolUseKind)>) =

static let empty = TcResolutions(ResizeArray 0, ResizeArray 0, ResizeArray 0, ResizeArray 0, ResizeArray 0)

Expand All @@ -2340,7 +2343,9 @@ type TcResolutions

member _.CapturedMethodGroupResolutions = capturedMethodGroupResolutions

member _.CapturedRelatedSymbolUses = capturedRelatedSymbolUses
member _.CapturedRelatedSymbolUsesInCode =
capturedRelatedSymbolUses
|> Seq.filter (fun struct (_, _, kind: RelatedSymbolUseKind) -> RelatedSymbolUseKind.AllInCode.HasFlag kind)

static member Empty = empty

Expand All @@ -2351,12 +2356,14 @@ type TcSymbolUseData =
DisplayEnv: DisplayEnv
Range: range }

let allAsCompiledIntoOlderCallers = enum<RelatedSymbolUseKind> 0x7FFFFFFF

/// Represents container for all name resolutions that were met so far when typechecking some particular file
///
/// This is a memory-critical data structure - allocations of this data structure and its immediate contents
/// is one of the highest memory long-lived data structures in typical uses of IDEs. Not many of these objects
/// are allocated (one per file), but they are large because the allUsesOfAllSymbols array is large.
type TcSymbolUses(g, capturedNameResolutions: ResizeArray<CapturedNameResolution>, capturedRelatedSymbolUses: ResizeArray<range * Item * RelatedSymbolUseKind>, formatSpecifierLocations: (range * int)[]) =
type TcSymbolUses(g, capturedNameResolutions: ResizeArray<CapturedNameResolution>, capturedRelatedSymbolUses: ResizeArray<struct (range * Item * RelatedSymbolUseKind)>, formatSpecifierLocations: (range * int)[]) =

let toSymbolUseData (cnr: CapturedNameResolution) =
{ ItemWithInst = cnr.ItemWithInst; ItemOccurrence = cnr.ItemOccurrence; DisplayEnv = cnr.DisplayEnv; Range = cnr.Range }
Expand All @@ -2371,14 +2378,19 @@ type TcSymbolUses(g, capturedNameResolutions: ResizeArray<CapturedNameResolution

let relatedSymbolUses =
capturedRelatedSymbolUses
|> ResizeArray.mapToSmallArrayChunks (fun (m, item, kind) ->
|> ResizeArray.mapToSmallArrayChunks (fun struct (m, item, kind) ->
struct ({ ItemWithInst = { Item = item; TyparInstantiation = emptyTyparInst }; ItemOccurrence = ItemOccurrence.Use; DisplayEnv = DisplayEnv.Empty g; Range = m }, kind))

let capturedRelatedSymbolUses = ()
do capturedRelatedSymbolUses // don't capture this!

member _.GetUsesOfSymbol(item, ?relatedSymbolKinds: RelatedSymbolUseKind) =
let kinds = defaultArg relatedSymbolKinds RelatedSymbolUseKind.None
member _.GetUsesOfSymbol(item, [<Struct>] ?relatedSymbolKinds: RelatedSymbolUseKind) =
let kinds =
match relatedSymbolKinds with
| ValueSome kinds when kinds = allAsCompiledIntoOlderCallers -> RelatedSymbolUseKind.AllInCode
| ValueSome kinds -> kinds
| ValueNone -> RelatedSymbolUseKind.None

[| for symbolUseChunk in allUsesOfSymbols do
for symbolUse in symbolUseChunk do
if protectAssemblyExploration false (fun () -> ItemsAreEffectivelyEqual g item symbolUse.ItemWithInst.Item) then
Expand All @@ -2402,7 +2414,7 @@ type TcResultsSinkImpl(tcGlobals, ?sourceText: ISourceText) =
let capturedExprTypings = ResizeArray<_>()
let capturedNameResolutions = ResizeArray<CapturedNameResolution>()
let capturedMethodGroupResolutions = ResizeArray<CapturedNameResolution>()
let capturedRelatedSymbolUses = ResizeArray<range * Item * RelatedSymbolUseKind>()
let capturedRelatedSymbolUses = ResizeArray<struct (range * Item * RelatedSymbolUseKind)>()
let capturedOpenDeclarations = ResizeArray<OpenDeclaration>()
let capturedFormatSpecifierLocations = ResizeArray<_>()

Expand Down Expand Up @@ -2514,7 +2526,7 @@ type TcResultsSinkImpl(tcGlobals, ?sourceText: ISourceText) =

member sink.NotifyRelatedSymbolUse(m, item, kind) =
if allowedRange m then
capturedRelatedSymbolUses.Add((m, item, kind))
capturedRelatedSymbolUses.Add(struct (m, item, kind))

member sink.NotifyOpenDeclaration openDeclaration =
capturedOpenDeclarations.Add openDeclaration
Expand Down Expand Up @@ -2651,6 +2663,43 @@ let CallRelatedSymbolSink (sink: TcResultsSink) (m: range, item: Item, kind: Rel
| None -> ()
| Some currentSink -> currentSink.NotifyRelatedSymbolUse(m, item, kind)

let XmlDocTyparCandidates (typars: seq<Typar>) =
typars
|> Seq.map (fun tp -> struct (tp.Name, Item.TypeVar(tp.Name, tp)))
|> ImmutableArray.ofSeq

let ReportXmlDocRefs
(currentSink: ITypecheckResultsSink)
(docRefs: ImmutableArray<XmlDocRef>)
(parameters: ImmutableArray<struct (string * Item)>)
(typars: ImmutableArray<struct (string * Item)>)
=
for docRef in docRefs do
let candidates =
match docRef.Kind with
| XmlDocRefKind.Param
| XmlDocRefKind.ParamRef -> parameters
| XmlDocRefKind.TypeParam
| XmlDocRefKind.TypeParamRef -> typars

for struct (name, item) in candidates do
if String.Equals(name, docRef.Text, StringComparison.Ordinal) then
currentSink.NotifyRelatedSymbolUse(docRef.Range, item, RelatedSymbolUseKind.XmlDocParameter)

let inline ReportXmlDocRefUses
(sink: TcResultsSink)
(doc: XmlDoc)
([<InlineIfLambda>] parameters: unit -> ImmutableArray<struct (string * Item)>)
([<InlineIfLambda>] typars: unit -> ImmutableArray<struct (string * Item)>)
=
match sink.CurrentSink with
| Some currentSink when doc.NonEmpty ->
let docRefs = doc.GetRefs()

if not docRefs.IsEmpty then
ReportXmlDocRefs currentSink docRefs (parameters ()) (typars ())
| _ -> ()

/// Report a specific expression typing at a source range
let CallExprHasTypeSink (sink: TcResultsSink) (m: range, nenv, ty, ad) =
match sink.CurrentSink with
Expand Down
24 changes: 22 additions & 2 deletions src/Compiler/Checking/NameResolution.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module internal FSharp.Compiler.NameResolution

open System.Collections.Immutable

open Internal.Utilities.Library
open FSharp.Compiler.AccessibilityLogic
open FSharp.Compiler.AttributeChecking
Expand All @@ -15,6 +17,7 @@ open FSharp.Compiler.Text
open FSharp.Compiler.TypedTree
open FSharp.Compiler.TypedTreeOps
open FSharp.Compiler.TcGlobals
open FSharp.Compiler.Xml

exception NoConstructorsAvailableForType of TType * DisplayEnv * range

Expand Down Expand Up @@ -442,7 +445,7 @@ type internal TcResolutions =
member CapturedMethodGroupResolutions: ResizeArray<CapturedNameResolution>

/// Related symbol uses reported via NotifyRelatedSymbolUse
member CapturedRelatedSymbolUses: ResizeArray<range * Item * RelatedSymbolUseKind>
member CapturedRelatedSymbolUsesInCode: seq<struct (range * Item * RelatedSymbolUseKind)>

/// Represents the empty set of resolutions
static member Empty: TcResolutions
Expand All @@ -459,7 +462,7 @@ type TcSymbolUseData =
type internal TcSymbolUses =

/// Get all the uses of a particular item within the file
member GetUsesOfSymbol: item: Item * ?relatedSymbolKinds: RelatedSymbolUseKind -> TcSymbolUseData[]
member GetUsesOfSymbol: item: Item * [<Struct>] ?relatedSymbolKinds: RelatedSymbolUseKind -> TcSymbolUseData[]

/// All the uses of all items within the file
member AllUsesOfSymbols: TcSymbolUseData[][]
Expand Down Expand Up @@ -655,6 +658,23 @@ val internal RegisterUnionCaseTesterForProperty: TcResultsSink -> identRange: ra
/// Report a related symbol use at a source range (does not affect colorization or symbol info)
val internal CallRelatedSymbolSink: TcResultsSink -> range * Item * RelatedSymbolUseKind -> unit

val internal XmlDocTyparCandidates: typars: seq<Typar> -> ImmutableArray<struct (string * Item)>

val internal ReportXmlDocRefs:
currentSink: ITypecheckResultsSink ->
docRefs: ImmutableArray<XmlDocRef> ->
parameters: ImmutableArray<struct (string * Item)> ->
typars: ImmutableArray<struct (string * Item)> ->
unit

/// Report the names in a declaration's XML doc that name its parameters or type parameters as related uses of them
val inline internal ReportXmlDocRefUses:
sink: TcResultsSink ->
doc: XmlDoc ->
[<InlineIfLambda>] parameters: (unit -> ImmutableArray<struct (string * Item)>) ->
[<InlineIfLambda>] typars: (unit -> ImmutableArray<struct (string * Item)>) ->
unit

/// Report a specific name resolution at a source range
val internal CallExprHasTypeSink: TcResultsSink -> range * NameResolutionEnv * TType * AccessorDomain -> unit

Expand Down
10 changes: 8 additions & 2 deletions src/Compiler/Checking/RelatedSymbolUse.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@ type RelatedSymbolUseKind =
| UnionCaseTester = 1
/// Record type via copy-and-update expression (e.g., { r with ... } → RecordType)
| CopyAndUpdateRecord = 2
/// All related symbol kinds
| All = 0x7FFFFFFF
/// Parameter or type parameter named by a param, paramref, typeparam or typeparamref tag of the XML doc
| XmlDocParameter = 4
Comment thread
T-Gro marked this conversation as resolved.
Resolved
/// Every kind but XmlDocParameter
| AllInCode = 3
/// Every kind, XmlDocParameter included
| AllInCodeAndDocs = 7
/// The same as AllInCode
| [<System.Obsolete("Use AllInCode, which this equals, or AllInCodeAndDocs.")>] All = 3
Loading
Loading