Skip to content

Commit

Permalink
Add GetTypeOfExpression, GetExpressionDisplayContext
Browse files Browse the repository at this point in the history
  • Loading branch information
auduchinok committed May 11, 2023
1 parent 02a5732 commit a3fb799
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Compiler/Service/FSharpCheckerResults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,18 @@ type internal TypeCheckInfo
member scope.IsRelativeNameResolvableFromSymbol(cursorPos: pos, plid: string list, symbol: FSharpSymbol) : bool =
scope.IsRelativeNameResolvable(cursorPos, plid, symbol.Item)

member scope.TryGetExpressionType(range) =
sResolutions.CapturedExpressionTypings
|> Seq.tryFindBack (fun (_, _, _, m) -> equals m range)
|> Option.map (fun (ty, _, _, _) -> FSharpType (cenv, ty))

member scope.GetExpressionDisplayContext(range) =
sResolutions.CapturedExpressionTypings
|> Seq.tryFindBack (fun (_, _, _, m) -> equals m range)
|> Option.map (fun (_, q, _, _) -> FSharpDisplayContext(fun _ -> q.DisplayEnv))



/// Get the auto-complete items at a location
member _.GetDeclarations(parseResultsOpt, line, lineStr, partialName, completionContextAtPos, getAllEntities) =
let isSigFile = SourceFileImpl.IsSignatureFile mainInputFileName
Expand Down Expand Up @@ -2887,6 +2899,16 @@ type FSharpCheckFileResults

member _.DependencyFiles = dependencyFiles

member _.GetTypeOfExpression(range: range) =
match details with
| None -> None
| Some(scope, _) -> scope.TryGetExpressionType(range)

member _.GetExpressionDisplayContext(range: range) =
match details with
| None -> None
| Some(scope, _) -> scope.GetExpressionDisplayContext(range)

member _.GetAllUsesOfAllSymbolsInFile(?cancellationToken: CancellationToken) =
match details with
| None -> Seq.empty
Expand Down
3 changes: 3 additions & 0 deletions src/Compiler/Service/FSharpCheckerResults.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ type public FSharpCheckFileResults =
/// in the documentation for compiler service.
member DependencyFiles: string[]

member GetTypeOfExpression: range -> FSharpType option
member GetExpressionDisplayContext: range -> FSharpDisplayContext option

/// <summary>Get the items for a declaration list</summary>
///
/// <param name="parsedFileResults">
Expand Down

0 comments on commit a3fb799

Please sign in to comment.