Skip to content
Draft
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
2 changes: 2 additions & 0 deletions docs/release-notes/.VisualStudio/18.vNext.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Improve Find All References performance by throttling parallel typechecks. ([PR #20128](https://github.com/dotnet/fsharp/pull/20128), [PR #20695](https://github.com/dotnet/fsharp/pull/20695))
* Fix record-type Rename corrupting copy-and-update expressions, including from abstract signatures, while retaining Find All References results. ([Issue #20791](https://github.com/dotnet/fsharp/issues/20791), [PR #20797](https://github.com/dotnet/fsharp/pull/20797))
* Fixed Rename incorrectly renaming `get` and `set` keywords for properties with explicit accessors. ([Issue #18270](https://github.com/dotnet/fsharp/issues/18270), [PR #19252](https://github.com/dotnet/fsharp/pull/19252))
* Rename rewrites the `<param>`, `<paramref>`, `<typeparam>` and `<typeparamref>` tags of the renamed parameter or type parameter in the declaration's `///` comment, and document highlights include them; Find All References leaves them out. ([Issue #20630](https://github.com/dotnet/fsharp/issues/20630), [PR #20638](https://github.com/dotnet/fsharp/pull/20638))
* Fixed Find All References crash when F# project contains non-F# files like `.cshtml`. ([Issue #16394](https://github.com/dotnet/fsharp/issues/16394), [PR #19252](https://github.com/dotnet/fsharp/pull/19252))
* Avoid using `cancellableTask` in `DocumentCache`; the editor cache now uses direct `CancellationToken`-aware `task` wrappers, avoiding the background `Task.Run` offload and a larger wrapper closure from the `cancellableTask` builder. ([Issue #20268](https://github.com/dotnet/fsharp/issues/20268))
* Cache document diagnostics by version stamp, so an unchanged document is not reanalyzed on every crawler pass. ([Issue #20120](https://github.com/dotnet/fsharp/issues/20120), [PR #20121](https://github.com/dotnet/fsharp/pull/20121))
Expand All @@ -34,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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖🕵️ Renaming the local 'T rewrites make's return-type tag

module M

/// <typeparam name="T">Return element.</typeparam>
let make () : 'T option =
    let id (x: 'T) = x
    let mutable state : 'T option = None // rename this 'T to 'U
    None

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
Loading
Loading