Skip to content

Commit 3b294c4

Browse files
author
Don Syme
committed
remove text snapshot objects, is-text-changed callbacks and async behaviour of CheckFileResults
2 parents 67d47c1 + 8669a13 commit 3b294c4

11 files changed

Lines changed: 220 additions & 260 deletions

File tree

src/fsharp/service/FSharpCheckerResults.fs

Lines changed: 78 additions & 114 deletions
Large diffs are not rendered by default.

src/fsharp/service/FSharpCheckerResults.fsi

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace FSharp.Compiler.SourceCodeServices
44

5+
6+
open System.Threading
57
open FSharp.Compiler
68
open FSharp.Compiler.AbstractIL.IL
79
open FSharp.Compiler.AbstractIL.Internal.Library
@@ -117,13 +119,12 @@ type public FSharpCheckFileResults =
117119
/// <param name="getAllEntities">
118120
/// Function that returns all entities from current and referenced assemblies.
119121
/// </param>
120-
/// <param name="hasTextChangedSinceLastTypecheck">
121-
/// If text has been used from a captured name resolution from the typecheck, then
122-
/// callback to the client to check if the text has changed. If it has, then give up
123-
/// and assume that we're going to repeat the operation later on.
124-
/// </param>
125-
/// <param name="userOpName">An optional string used for tracing compiler operations associated with this request.</param>
126-
member GetDeclarationListInfo : ParsedFileResultsOpt:FSharpParseFileResults option * line: int * lineText:string * partialName: PartialLongName * ?getAllEntities: (unit -> AssemblySymbol list) * ?hasTextChangedSinceLastTypecheck: (obj * range -> bool) -> Async<FSharpDeclarationListInfo>
122+
member GetDeclarationListInfo :
123+
ParsedFileResultsOpt:FSharpParseFileResults option *
124+
line: int *
125+
lineText:string *
126+
partialName: PartialLongName *
127+
?getAllEntities: (unit -> AssemblySymbol list) -> FSharpDeclarationListInfo
127128

128129
/// <summary>Get the items for a declaration list in FSharpSymbol format</summary>
129130
///
@@ -143,13 +144,13 @@ type public FSharpCheckFileResults =
143144
/// <param name="getAllEntities">
144145
/// Function that returns all entities from current and referenced assemblies.
145146
/// </param>
146-
/// <param name="hasTextChangedSinceLastTypecheck">
147-
/// If text has been used from a captured name resolution from the typecheck, then
148-
/// callback to the client to check if the text has changed. If it has, then give up
149-
/// and assume that we're going to repeat the operation later on.
150-
/// </param>
151-
/// <param name="userOpName">An optional string used for tracing compiler operations associated with this request.</param>
152-
member GetDeclarationListSymbols : ParsedFileResultsOpt:FSharpParseFileResults option * line: int * lineText:string * partialName: PartialLongName * ?getAllEntities: (unit -> AssemblySymbol list) * ?hasTextChangedSinceLastTypecheck: (obj * range -> bool) -> Async<FSharpSymbolUse list list>
147+
member GetDeclarationListSymbols:
148+
ParsedFileResultsOpt:FSharpParseFileResults option *
149+
line: int *
150+
lineText:string *
151+
partialName: PartialLongName *
152+
?getAllEntities: (unit -> AssemblySymbol list)
153+
-> FSharpSymbolUse list list
153154

154155
/// <summary>Compute a formatted tooltip for the given location</summary>
155156
///
@@ -158,8 +159,13 @@ type public FSharpCheckFileResults =
158159
/// <param name="lineText">The text of the line where the information is being requested.</param>
159160
/// <param name="names">The identifiers at the location where the information is being requested.</param>
160161
/// <param name="tokenTag">Used to discriminate between 'identifiers', 'strings' and others. For strings, an attempt is made to give a tooltip for a #r "..." location. Use a value from FSharpTokenInfo.Tag, or FSharpTokenTag.Identifier, unless you have other information available.</param>
161-
/// <param name="userOpName">An optional string used for tracing compiler operations associated with this request.</param>
162-
member GetStructuredToolTipText : line:int * colAtEndOfNames:int * lineText:string * names:string list * tokenTag:int -> Async<FSharpStructuredToolTipText>
162+
member GetStructuredToolTipText :
163+
line:int *
164+
colAtEndOfNames:int *
165+
lineText:string *
166+
names:string list *
167+
tokenTag:int
168+
-> FSharpStructuredToolTipText
163169

164170
/// <summary>Compute a formatted tooltip for the given location</summary>
165171
///
@@ -168,17 +174,15 @@ type public FSharpCheckFileResults =
168174
/// <param name="lineText">The text of the line where the information is being requested.</param>
169175
/// <param name="names">The identifiers at the location where the information is being requested.</param>
170176
/// <param name="tokenTag">Used to discriminate between 'identifiers', 'strings' and others. For strings, an attempt is made to give a tooltip for a #r "..." location. Use a value from FSharpTokenInfo.Tag, or FSharpTokenTag.Identifier, unless you have other information available.</param>
171-
/// <param name="userOpName">An optional string used for tracing compiler operations associated with this request.</param>
172-
member GetToolTipText : line:int * colAtEndOfNames:int * lineText:string * names:string list * tokenTag:int -> Async<FSharpToolTipText>
177+
member GetToolTipText : line:int * colAtEndOfNames:int * lineText:string * names:string list * tokenTag:int -> FSharpToolTipText
173178

174179
/// <summary>Compute the Visual Studio F1-help key identifier for the given location, based on name resolution results</summary>
175180
///
176181
/// <param name="line">The line number where the information is being requested.</param>
177182
/// <param name="colAtEndOfNames">The column number at the end of the identifiers where the information is being requested.</param>
178183
/// <param name="lineText">The text of the line where the information is being requested.</param>
179184
/// <param name="names">The identifiers at the location where the information is being requested.</param>
180-
/// <param name="userOpName">An optional string used for tracing compiler operations associated with this request.</param>
181-
member GetF1Keyword : line:int * colAtEndOfNames:int * lineText:string * names:string list -> Async<string option>
185+
member GetF1Keyword : line:int * colAtEndOfNames:int * lineText:string * names:string list -> string option
182186

183187

184188
/// <summary>Compute a set of method overloads to show in a dialog relevant to the given code location.</summary>
@@ -187,16 +191,14 @@ type public FSharpCheckFileResults =
187191
/// <param name="colAtEndOfNames">The column number at the end of the identifiers where the information is being requested.</param>
188192
/// <param name="lineText">The text of the line where the information is being requested.</param>
189193
/// <param name="names">The identifiers at the location where the information is being requested.</param>
190-
/// <param name="userOpName">An optional string used for tracing compiler operations associated with this request.</param>
191-
member GetMethods : line:int * colAtEndOfNames:int * lineText:string * names:string list option -> Async<FSharpMethodGroup>
194+
member GetMethods : line:int * colAtEndOfNames:int * lineText:string * names:string list option -> FSharpMethodGroup
192195

193196
/// <summary>Compute a set of method overloads to show in a dialog relevant to the given code location. The resulting method overloads are returned as symbols.</summary>
194197
/// <param name="line">The line number where the information is being requested.</param>
195198
/// <param name="colAtEndOfNames">The column number at the end of the identifiers where the information is being requested.</param>
196199
/// <param name="lineText">The text of the line where the information is being requested.</param>
197200
/// <param name="names">The identifiers at the location where the information is being requested.</param>
198-
/// <param name="userOpName">An optional string used for tracing compiler operations associated with this request.</param>
199-
member GetMethodsAsSymbols : line:int * colAtEndOfNames:int * lineText:string * names:string list -> Async<FSharpSymbolUse list option>
201+
member GetMethodsAsSymbols : line:int * colAtEndOfNames:int * lineText:string * names:string list -> FSharpSymbolUse list option
200202

201203
/// <summary>Resolve the names at the given location to the declaration location of the corresponding construct.</summary>
202204
///
@@ -205,17 +207,15 @@ type public FSharpCheckFileResults =
205207
/// <param name="lineText">The text of the line where the information is being requested.</param>
206208
/// <param name="names">The identifiers at the location where the information is being requested.</param>
207209
/// <param name="preferFlag">If not given, then get the location of the symbol. If false, then prefer the location of the corresponding symbol in the implementation of the file (rather than the signature if present). If true, prefer the location of the corresponding symbol in the signature of the file (rather than the implementation).</param>
208-
/// <param name="userOpName">An optional string used for tracing compiler operations associated with this request.</param>
209-
member GetDeclarationLocation : line:int * colAtEndOfNames:int * lineText:string * names:string list * ?preferFlag:bool -> Async<FSharpFindDeclResult>
210+
member GetDeclarationLocation : line:int * colAtEndOfNames:int * lineText:string * names:string list * ?preferFlag:bool -> FSharpFindDeclResult
210211

211212
/// <summary>Resolve the names at the given location to a use of symbol.</summary>
212213
///
213214
/// <param name="line">The line number where the information is being requested.</param>
214215
/// <param name="colAtEndOfNames">The column number at the end of the identifiers where the information is being requested.</param>
215216
/// <param name="lineText">The text of the line where the information is being requested.</param>
216217
/// <param name="names">The identifiers at the location where the information is being requested.</param>
217-
/// <param name="userOpName">An optional string used for tracing compiler operations associated with this request.</param>
218-
member GetSymbolUseAtLocation : line:int * colAtEndOfNames:int * lineText:string * names:string list -> Async<FSharpSymbolUse option>
218+
member GetSymbolUseAtLocation : line:int * colAtEndOfNames:int * lineText:string * names:string list -> FSharpSymbolUse option
219219

220220
/// <summary>Get any extra colorization info that is available after the typecheck</summary>
221221
member GetSemanticClassification : range option -> struct (range * SemanticClassificationType)[]
@@ -228,21 +228,21 @@ type public FSharpCheckFileResults =
228228
member GetFormatSpecifierLocationsAndArity : unit -> (range*int)[]
229229

230230
/// Get all textual usages of all symbols throughout the file
231-
member GetAllUsesOfAllSymbolsInFile : unit -> Async<FSharpSymbolUse[]>
231+
member GetAllUsesOfAllSymbolsInFile : ?cancellationToken: CancellationToken -> FSharpSymbolUse[]
232232

233233
/// Get the textual usages that resolved to the given symbol throughout the file
234-
member GetUsesOfSymbolInFile : symbol:FSharpSymbol -> Async<FSharpSymbolUse[]>
234+
member GetUsesOfSymbolInFile : symbol:FSharpSymbol * ?cancellationToken: CancellationToken -> FSharpSymbolUse[]
235235

236-
member internal GetVisibleNamespacesAndModulesAtPoint : pos -> Async<ModuleOrNamespaceRef[]>
236+
member internal GetVisibleNamespacesAndModulesAtPoint : pos -> ModuleOrNamespaceRef[]
237237

238238
/// Find the most precise display environment for the given line and column.
239-
member GetDisplayContextForPos : pos : pos -> Async<FSharpDisplayContext option>
239+
member GetDisplayContextForPos : pos : pos -> FSharpDisplayContext option
240240

241241
/// Determines if a long ident is resolvable at a specific point.
242-
member internal IsRelativeNameResolvable: cursorPos : pos * plid : string list * item: Item -> Async<bool>
242+
member internal IsRelativeNameResolvable: cursorPos : pos * plid : string list * item: Item -> bool
243243

244244
/// Determines if a long ident is resolvable at a specific point.
245-
member IsRelativeNameResolvableFromSymbol: cursorPos : pos * plid : string list * symbol: FSharpSymbol -> Async<bool>
245+
member IsRelativeNameResolvableFromSymbol: cursorPos : pos * plid : string list * symbol: FSharpSymbol -> bool
246246

247247
/// Represents complete typechecked implementation file, including its typechecked signatures if any.
248248
member ImplementationFile: FSharpImplementationFileContents option
@@ -269,7 +269,6 @@ type public FSharpCheckFileResults =
269269
creationErrors: FSharpErrorInfo[] *
270270
parseErrors: FSharpErrorInfo[] *
271271
tcErrors: FSharpErrorInfo[] *
272-
reactorOps : IReactorOperations *
273272
keepAssemblyContents: bool *
274273
ccuSigForFile: ModuleOrNamespaceType *
275274
thisCcu: CcuThunk *
@@ -297,7 +296,6 @@ type public FSharpCheckFileResults =
297296
loadClosure: LoadClosure option *
298297
backgroundDiagnostics: (PhasedDiagnostic * FSharpErrorSeverity)[] *
299298
reactorOps: IReactorOperations *
300-
textSnapshotInfo : obj option *
301299
userOpName: string *
302300
isIncompleteTypeCheckEnvironment: bool *
303301
builder: IncrementalBuilder *
@@ -336,10 +334,10 @@ type public FSharpCheckProjectResults =
336334
member ProjectContext: FSharpProjectContext
337335

338336
/// Get the textual usages that resolved to the given symbol throughout the project
339-
member GetUsesOfSymbol: symbol:FSharpSymbol -> Async<FSharpSymbolUse[]>
337+
member GetUsesOfSymbol: symbol:FSharpSymbol * ?cancellationToken: CancellationToken -> FSharpSymbolUse[]
340338

341339
/// Get all textual usages of all symbols throughout the project
342-
member GetAllUsesOfAllSymbols: unit -> Async<FSharpSymbolUse[]>
340+
member GetAllUsesOfAllSymbols: ?cancellationToken: CancellationToken -> FSharpSymbolUse[]
343341

344342
/// Indicates if critical errors existed in the project options
345343
member HasCriticalErrors: bool

src/fsharp/service/ServiceAnalysis.fs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ module UnusedOpens =
224224
/// Async to allow cancellation.
225225
let getUnusedOpens (checkFileResults: FSharpCheckFileResults, getSourceLineStr: int -> string) : Async<range list> =
226226
async {
227-
let! symbolUses = checkFileResults.GetAllUsesOfAllSymbolsInFile()
227+
let! ct = Async.CancellationToken
228+
let symbolUses = checkFileResults.GetAllUsesOfAllSymbolsInFile(ct)
228229
let symbolUses = filterSymbolUses getSourceLineStr symbolUses
229230
let symbolUses = splitSymbolUses symbolUses
230231
let openStatements = getOpenStatements checkFileResults.OpenDeclarations
@@ -243,7 +244,8 @@ module SimplifyNames =
243244
let getSimplifiableNames (checkFileResults: FSharpCheckFileResults, getSourceLineStr: int -> string) : Async<SimplifiableRange list> =
244245
async {
245246
let result = ResizeArray()
246-
let! symbolUses = checkFileResults.GetAllUsesOfAllSymbolsInFile()
247+
let! ct = Async.CancellationToken
248+
let symbolUses = checkFileResults.GetAllUsesOfAllSymbolsInFile(ct)
247249
let symbolUses =
248250
symbolUses
249251
|> Array.filter (fun symbolUse -> not symbolUse.IsFromOpenStatement)
@@ -266,19 +268,17 @@ module SimplifyNames =
266268
if r.StartLine = r.EndLine then Range.mkPos r.StartLine (r.EndColumn - name.Length)
267269
else r.Start
268270

269-
let getNecessaryPlid (plid: string list) : Async<string list> =
271+
let getNecessaryPlid (plid: string list) : string list =
270272
let rec loop (rest: string list) (current: string list) =
271-
async {
272-
match rest with
273-
| [] -> return current
274-
| headIdent :: restPlid ->
275-
let! res = checkFileResults.IsRelativeNameResolvableFromSymbol(posAtStartOfName, current, symbolUse.Symbol)
276-
if res then return current
277-
else return! loop restPlid (headIdent :: current)
278-
}
273+
match rest with
274+
| [] -> current
275+
| headIdent :: restPlid ->
276+
let res = checkFileResults.IsRelativeNameResolvableFromSymbol(posAtStartOfName, current, symbolUse.Symbol)
277+
if res then current
278+
else loop restPlid (headIdent :: current)
279279
loop (List.rev plid) []
280280

281-
let! necessaryPlid = getNecessaryPlid plid
281+
let necessaryPlid = getNecessaryPlid plid
282282

283283
match necessaryPlid with
284284
| necessaryPlid when necessaryPlid = plid -> ()
@@ -342,7 +342,8 @@ module UnusedDeclarations =
342342

343343
let getUnusedDeclarations(checkFileResults: FSharpCheckFileResults, isScriptFile: bool) : Async<range list> =
344344
async {
345-
let! allSymbolUsesInFile = checkFileResults.GetAllUsesOfAllSymbolsInFile()
345+
let! ct = Async.CancellationToken
346+
let allSymbolUsesInFile = checkFileResults.GetAllUsesOfAllSymbolsInFile(ct)
346347
let unusedRanges = getUnusedDeclarationRanges allSymbolUsesInFile isScriptFile
347348
return unusedRanges
348349
}

0 commit comments

Comments
 (0)