Skip to content

Commit 4926f2e

Browse files
committed
Add FSharpCodeCompletionOptions
* Allows providing obsolete items * Allows disabling override items * Allows disabling pattern name suggestion items
1 parent 12efe3b commit 4926f2e

File tree

8 files changed

+480
-135
lines changed

8 files changed

+480
-135
lines changed

src/Compiler/Checking/AttributeChecking.fs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,10 @@ let CheckMethInfoAttributes g m tyargsOpt (minfo: MethInfo) =
577577

578578
/// Indicate if a method has 'Obsolete', 'CompilerMessageAttribute' or 'TypeProviderEditorHideMethodsAttribute'.
579579
/// Used to suppress the item in intellisense.
580-
let MethInfoIsUnseen g (m: range) (ty: TType) minfo =
581-
let isUnseenByObsoleteAttrib () =
580+
let MethInfoIsUnseen g (m: range) (ty: TType) minfo allowObsolete =
581+
let isUnseenByObsoleteAttrib () =
582+
if allowObsolete then false else
583+
582584
match BindMethInfoAttributes m minfo
583585
(fun ilAttribs -> Some(CheckILAttributesForUnseen g ilAttribs m))
584586
(fun fsAttribs -> Some(CheckFSharpAttributesForUnseen g fsAttribs m))

src/Compiler/Checking/AttributeChecking.fsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ val CheckILFieldAttributes: g: TcGlobals -> finfo: ILFieldInfo -> m: range -> un
7777
val CheckMethInfoAttributes:
7878
g: TcGlobals -> m: range -> tyargsOpt: 'a option -> minfo: MethInfo -> OperationResult<unit>
7979

80-
val MethInfoIsUnseen: g: TcGlobals -> m: range -> ty: TType -> minfo: MethInfo -> bool
80+
val MethInfoIsUnseen: g: TcGlobals -> m: range -> ty: TType -> minfo: MethInfo -> allowObsolete: bool -> bool
8181

8282
val PropInfoIsUnseen: m: 'a -> pinfo: PropInfo -> bool
8383

src/Compiler/Checking/NameResolution.fs

Lines changed: 68 additions & 67 deletions
Large diffs are not rendered by default.

src/Compiler/Checking/NameResolution.fsi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,10 +913,11 @@ val ResolveCompletionsInType:
913913
AccessorDomain ->
914914
bool ->
915915
TType ->
916+
allowObsolete: bool ->
916917
Item list
917918

918919
val GetVisibleNamespacesAndModulesAtPoint:
919-
NameResolver -> NameResolutionEnv -> FullyQualifiedFlag -> range -> AccessorDomain -> ModuleOrNamespaceRef list
920+
NameResolver -> NameResolutionEnv -> FullyQualifiedFlag -> range -> AccessorDomain -> allowObsolete: bool -> ModuleOrNamespaceRef list
920921

921922
val IsItemResolvable: NameResolver -> NameResolutionEnv -> range -> AccessorDomain -> string list -> Item -> bool
922923

src/Compiler/Service/FSharpCheckerResults.fs

Lines changed: 71 additions & 51 deletions
Large diffs are not rendered by default.

src/Compiler/Service/FSharpCheckerResults.fsi

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,14 @@ type public FSharpParsingOptions =
245245
static member internal FromTcConfigBuilder:
246246
tcConfigB: TcConfigBuilder * sourceFiles: string[] * isInteractive: bool -> FSharpParsingOptions
247247

248+
type public FSharpCodeCompletionOptions =
249+
{ SuggestPatternNames: bool
250+
SuggestObsoleteSymbols: bool
251+
SuggestGeneratedOverrides: bool
252+
SuggestOverrideBodies: bool }
253+
254+
static member Default: FSharpCodeCompletionOptions
255+
248256
/// A handle to the results of CheckFileInProject.
249257
[<Sealed>]
250258
type public FSharpCheckFileResults =
@@ -293,8 +301,8 @@ type public FSharpCheckFileResults =
293301
/// <param name="completionContextAtPos">
294302
/// Completion context for a particular position computed in advance.
295303
/// </param>
296-
/// <param name="genBodyForOverriddenMeth">
297-
/// A switch to determine whether to generate a default implementation body for overridden method when completing.
304+
/// <param name="options">
305+
/// Options to allow customizing behavior by an IDE.
298306
/// </param>
299307
member GetDeclarationListInfo:
300308
parsedFileResults: FSharpParseFileResults option *
@@ -303,7 +311,7 @@ type public FSharpCheckFileResults =
303311
partialName: PartialLongName *
304312
?getAllEntities: (unit -> AssemblySymbol list) *
305313
?completionContextAtPos: (pos * CompletionContext option) *
306-
?genBodyForOverriddenMeth: bool ->
314+
?options: FSharpCodeCompletionOptions ->
307315
DeclarationListInfo
308316

309317
/// <summary>Get the items for a declaration list in FSharpSymbol format</summary>
@@ -324,16 +332,16 @@ type public FSharpCheckFileResults =
324332
/// <param name="getAllEntities">
325333
/// Function that returns all entities from current and referenced assemblies.
326334
/// </param>
327-
/// <param name="genBodyForOverriddenMeth">
328-
/// A switch to determine whether to generate a default implementation body for overridden method when completing.
335+
/// <param name="options">
336+
/// Options to allow customizing behavior by an IDE.
329337
/// </param>
330338
member GetDeclarationListSymbols:
331339
parsedFileResults: FSharpParseFileResults option *
332340
line: int *
333341
lineText: string *
334342
partialName: PartialLongName *
335343
?getAllEntities: (unit -> AssemblySymbol list) *
336-
?genBodyForOverriddenMeth: bool ->
344+
?options: FSharpCodeCompletionOptions ->
337345
FSharpSymbolUse list list
338346

339347
/// <summary>Compute a formatted tooltip for the given keywords</summary>

tests/FSharp.Compiler.Service.Tests/Checker.fs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ module CheckResultsExtensions =
125125
member this.GetTooltip(context: ResolveContext, width) =
126126
this.GetToolTip(context.Pos.Line, context.Pos.Column, context.LineText, context.Names, FSharpTokenTag.Identifier, width)
127127

128-
member this.GetCodeCompletionSuggestions(context: CodeCompletionContext, parseResults: FSharpParseFileResults) =
129-
this.GetDeclarationListInfo(Some parseResults, context.Pos.Line, context.LineText, context.PartialIdentifier)
128+
member this.GetCodeCompletionSuggestions(context: CodeCompletionContext, parseResults: FSharpParseFileResults, options: FSharpCodeCompletionOptions) =
129+
this.GetDeclarationListInfo(Some parseResults, context.Pos.Line, context.LineText, context.PartialIdentifier, options = options)
130130

131131
[<RequireQualifiedAccess>]
132132
module Checker =
@@ -152,10 +152,13 @@ module Checker =
152152
let _, checkResults = getParseAndCheckResults context.Source
153153
context, checkResults
154154

155-
let getCompletionInfo (markedSource: string) =
155+
let getCompletionInfoWithOptions (options: FSharpCodeCompletionOptions) (markedSource: string) =
156156
let context = getCompletionContext markedSource
157157
let parseResults, checkResults = getParseAndCheckResults context.Source
158-
checkResults.GetCodeCompletionSuggestions(context, parseResults)
158+
checkResults.GetCodeCompletionSuggestions(context, parseResults, options)
159+
160+
let getCompletionInfo markedSource =
161+
getCompletionInfoWithOptions FSharpCodeCompletionOptions.Default markedSource
159162

160163
let getSymbolUses (markedSource: string) =
161164
let context, checkResults = getCheckedResolveContext markedSource

0 commit comments

Comments
 (0)