Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly classify 'new', add plaintext, fix Namespace name #9910

Merged
merged 2 commits into from Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 26 additions & 15 deletions src/fsharp/service/SemanticClassification.fs
Expand Up @@ -28,7 +28,7 @@ type SemanticClassificationType =
| Property
| MutableVar
| Module
| NameSpace
| Namespace
| Printf
| ComputationExpression
| IntrinsicFunction
Expand All @@ -55,6 +55,7 @@ type SemanticClassificationType =
| LocalValue
| Type
| TypeDef
| Plaintext

[<AutoOpen>]
module TcResolutionsExtensions =
Expand Down Expand Up @@ -164,8 +165,10 @@ module TcResolutionsExtensions =
add m SemanticClassificationType.IntrinsicFunction

| (Item.Value vref), _, _, _, _, m when isFunction g vref.Type ->
if valRefEq g g.range_op_vref vref || valRefEq g g.range_step_op_vref vref then
()
if isDiscard vref.DisplayName then
add m SemanticClassificationType.Plaintext
elif valRefEq g g.range_op_vref vref || valRefEq g g.range_step_op_vref vref then
add m SemanticClassificationType.Operator
elif vref.IsPropertyGetterMethod || vref.IsPropertySetterMethod then
add m SemanticClassificationType.Property
elif vref.IsMember then
Expand Down Expand Up @@ -213,21 +216,29 @@ module TcResolutionsExtensions =
add m SemanticClassificationType.Property

| Item.CtorGroup (_, minfos), _, _, _, _, m ->
if minfos |> List.forall (fun minfo -> isDisposableTy minfo.ApparentEnclosingType) then
add m SemanticClassificationType.DisposableType
elif minfos |> List.forall (fun minfo -> isStructTy g minfo.ApparentEnclosingType) then
add m SemanticClassificationType.ConstructorForValueType
else
match minfos with
| [] ->
add m SemanticClassificationType.ConstructorForReferenceType
| _ ->
if minfos |> List.forall (fun minfo -> isDisposableTy minfo.ApparentEnclosingType) then
add m SemanticClassificationType.DisposableType
elif minfos |> List.forall (fun minfo -> isStructTy g minfo.ApparentEnclosingType) then
add m SemanticClassificationType.ConstructorForValueType
else
add m SemanticClassificationType.ConstructorForReferenceType

| (Item.DelegateCtor _ | Item.FakeInterfaceCtor _), _, _, _, _, m ->
add m SemanticClassificationType.ConstructorForReferenceType

| Item.MethodGroup (_, minfos, _), _, _, _, _, m ->
if minfos |> List.forall (fun minfo -> minfo.IsExtensionMember || minfo.IsCSharpStyleExtensionMember) then
add m SemanticClassificationType.ExtensionMethod
else
match minfos with
| [] ->
add m SemanticClassificationType.Method
| _ ->
if minfos |> List.forall (fun minfo -> minfo.IsExtensionMember || minfo.IsCSharpStyleExtensionMember) then
add m SemanticClassificationType.ExtensionMethod
else
add m SemanticClassificationType.Method

// Special case measures for struct types
| Item.Types(_, TType_app(tyconRef, TType_measure _ :: _) :: _), LegitTypeOccurence, _, _, _, m when isStructTyconRef tyconRef ->
Expand Down Expand Up @@ -295,7 +306,7 @@ module TcResolutionsExtensions =

| Item.ModuleOrNamespaces (modref :: _), LegitTypeOccurence, _, _, _, m ->
if modref.IsNamespace then
add m SemanticClassificationType.NameSpace
add m SemanticClassificationType.Namespace
else
add m SemanticClassificationType.Module

Expand Down Expand Up @@ -331,7 +342,7 @@ module TcResolutionsExtensions =
elif tcref.IsModule then
add m SemanticClassificationType.Module
elif tcref.IsNamespace then
add m SemanticClassificationType.NameSpace
add m SemanticClassificationType.Namespace
elif tcref.IsUnionTycon || tcref.IsRecordTycon then
if isStructTyconRef tcref then
add m SemanticClassificationType.ValueType
Expand All @@ -351,8 +362,8 @@ module TcResolutionsExtensions =
else
add m SemanticClassificationType.ReferenceType

| _ ->
())
| _, _, _, _, _, m ->
add m SemanticClassificationType.Plaintext)
results.AddRange(formatSpecifierLocations |> Array.map (fun (m, _) -> struct(m, SemanticClassificationType.Printf)))
results.ToArray()
)
Expand Down
3 changes: 2 additions & 1 deletion src/fsharp/service/SemanticClassification.fsi
Expand Up @@ -20,7 +20,7 @@ type SemanticClassificationType =
| Property
| MutableVar
| Module
| NameSpace
| Namespace
| Printf
| ComputationExpression
| IntrinsicFunction
Expand All @@ -47,6 +47,7 @@ type SemanticClassificationType =
| LocalValue
| Type
| TypeDef
| Plaintext

/// Extension methods for the TcResolutions type.
[<AutoOpen>]
Expand Down
Expand Up @@ -32,7 +32,7 @@ module internal FSharpClassificationTypes =
| SemanticClassificationType.MutableVar -> MutableVar
| SemanticClassificationType.DisposableValue -> DisposableValue
| SemanticClassificationType.DisposableType -> DisposableType
| SemanticClassificationType.NameSpace -> ClassificationTypeNames.NamespaceName
| SemanticClassificationType.Namespace -> ClassificationTypeNames.NamespaceName
| SemanticClassificationType.Printf -> Printf
| SemanticClassificationType.Exception
| SemanticClassificationType.Module
Expand Down Expand Up @@ -63,6 +63,7 @@ module internal FSharpClassificationTypes =
| SemanticClassificationType.Delegate -> ClassificationTypeNames.DelegateName
| SemanticClassificationType.Value -> ClassificationTypeNames.Identifier
| SemanticClassificationType.LocalValue -> ClassificationTypeNames.LocalName
| SemanticClassificationType.Plaintext -> ClassificationTypeNames.Text

module internal ClassificationDefinitions =

Expand Down