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

Added more highlightings #136

Closed
wants to merge 7 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public static string GetEntityHighlightingAttributeId([NotNull] this FSharpEntit
if (entity.IsFSharpRecord)
return FSharpHighlightingAttributeIdsModule.Record;

if (entity.IsMeasure)
return FSharpHighlightingAttributeIdsModule.UnitOfMeasure;

return entity.IsInterface
? FSharpHighlightingAttributeIdsModule.Interface
: FSharpHighlightingAttributeIdsModule.Class;
Expand All @@ -51,22 +54,32 @@ public static string GetMfvHighlightingAttributeId([NotNull] this FSharpMemberOr

var entity = mfv.DeclaringEntity;
if (mfv.IsModuleValueOrMember && (entity != null && !entity.Value.IsFSharpModule || mfv.IsExtensionMember))
return mfv.IsProperty || mfv.IsPropertyGetterMethod || mfv.IsPropertySetterMethod
? FSharpHighlightingAttributeIdsModule.Property
: FSharpHighlightingAttributeIdsModule.Method;
if (mfv.IsProperty || mfv.IsPropertyGetterMethod || mfv.IsPropertySetterMethod)
return mfv.IsExtensionMember
? FSharpHighlightingAttributeIdsModule.ExtensionProperty
: FSharpHighlightingAttributeIdsModule.Property;
else
return mfv.IsExtensionMember
? FSharpHighlightingAttributeIdsModule.ExtensionMethod
: FSharpHighlightingAttributeIdsModule.Method;

if (mfv.LiteralValue != null)
return FSharpHighlightingAttributeIdsModule.Literal;

if (mfv.IsActivePattern)
return FSharpHighlightingAttributeIdsModule.ActivePatternCase;

if (mfv.IsMutable || mfv.IsRefCell())
return FSharpHighlightingAttributeIdsModule.MutableValue;

if (IsMangledOpName(mfv.LogicalName))
return FSharpHighlightingAttributeIdsModule.Operator;

if (mfv.FullType.IsFunctionType || mfv.IsTypeFunction)
return mfv.IsMutable
? FSharpHighlightingAttributeIdsModule.MutableFunction
: FSharpHighlightingAttributeIdsModule.Function;

if (mfv.IsMutable || mfv.IsRefCell())
return FSharpHighlightingAttributeIdsModule.MutableValue;

var fsType = mfv.FullType;
if (fsType.HasTypeDefinition && fsType.TypeDefinition is var mfvTypeEntity && mfvTypeEntity.IsByRef)
return FSharpHighlightingAttributeIdsModule.MutableValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private void AddHighlightings(IEnumerable<FSharpResolvedSymbolUse> symbolsUses,

var highlightingId =
symbolUse.IsFromComputationExpression
? FSharpHighlightingAttributeIdsModule.Keyword
? FSharpHighlightingAttributeIdsModule.ComputationExpression
: symbol.GetHighlightingAttributeId();

if (symbolUse.IsFromDefinition && symbol is FSharpMemberOrFunctionOrValue mfv)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ module FSharpHighlightingAttributeIds =

let [<Literal>] Value = "ReSharper F# Value Identifier"
let [<Literal>] MutableValue = "ReSharper F# Mutable Value Identifier"
let [<Literal>] Function = "ReSharper F# Function Identifier"
let [<Literal>] MutableFunction = "ReSharper F# Mutable Function Identifier"

let [<Literal>] Parameter = "ReSharper F# Parameter Identifier" // todo: add setting
let [<Literal>] Literal = "ReSharper F# Literal Identifier"

Expand All @@ -58,9 +61,11 @@ module FSharpHighlightingAttributeIds =
let [<Literal>] Event = "ReSharper F# Event Identifier"

let [<Literal>] Method = "ReSharper F# Method Identifier"
let [<Literal>] ExtensionMethod = "ReSharper F# Extension Method Identifier" // todo: add setting
let [<Literal>] ExtensionProperty = "ReSharper F# Extension Property Identifier" // todo: add setting

let [<Literal>] ExtensionMethod = "ReSharper F# Extension Method Identifier"
let [<Literal>] ExtensionProperty = "ReSharper F# Extension Property Identifier"

let [<Literal>] ComputationExpression = "ReSharper F# Computation Expression Identifier"
let [<Literal>] UnitOfMeasure = "ReSharper F# Unit Of Measure Identifier"

type FSharpSettingsNamesProvider() =
inherit PrefixBasedSettingsNamesProvider("ReSharper F#", "FSHARP")
Expand Down Expand Up @@ -97,7 +102,7 @@ type FSharpSettingsNamesProvider() =
RiderPresentableName = "Syntax//Number",
Layer = HighlighterLayer.SYNTAX,
EffectType = EffectType.TEXT, ForegroundColor = "#000000", DarkForegroundColor = "#B5CEA8");

RegisterHighlighter(
FSharpHighlightingAttributeIds.LineComment,
FallbackAttributeId = DefaultLanguageAttributeIds.LINE_COMMENT,
Expand Down Expand Up @@ -228,6 +233,14 @@ type FSharpSettingsNamesProvider() =
VSPriority = VSPriority.IDENTIFIERS,
EffectType = EffectType.TEXT, ForegroundColor = "DarkBlue", DarkForegroundColor = "LightBlue");

RegisterHighlighter(
FSharpHighlightingAttributeIds.UnitOfMeasure,
FallbackAttributeId = FSharpHighlightingAttributeIds.TypeParameter,
GroupId = FSharpHighlightingAttributeIds.GroupId,
RiderPresentableName = "Types//Unit of measure",
Layer = HighlighterLayer.SYNTAX,
EffectType = EffectType.TEXT, ForegroundColor = "DarkBlue", DarkForegroundColor = "LightBlue");

RegisterHighlighter(
FSharpHighlightingAttributeIds.Union,
FallbackAttributeId = FSharpHighlightingAttributeIds.Enum,
Expand Down Expand Up @@ -291,7 +304,7 @@ type FSharpSettingsNamesProvider() =
Layer = HighlighterLayer.SYNTAX,
VSPriority = VSPriority.IDENTIFIERS,
EffectType = EffectType.TEXT, ForegroundColor = "Purple", DarkForegroundColor = "Violet");

RegisterHighlighter(
FSharpHighlightingAttributeIds.Value,
FallbackAttributeId = DefaultLanguageAttributeIds.LOCAL_VARIABLE,
Expand All @@ -310,7 +323,33 @@ type FSharpSettingsNamesProvider() =
VSPriority = FSharpHighlightingAttributeIds.VsPriorityPlusOne,
EffectType = EffectType.TEXT,
FontStyle = FontStyle.Bold);

RegisterHighlighter(
FSharpHighlightingAttributeIds.Function,
FallbackAttributeId = FSharpHighlightingAttributeIds.Value,
GroupId = FSharpHighlightingAttributeIds.GroupId,
RiderPresentableName = "Values//Function",
Layer = HighlighterLayer.SYNTAX,
VSPriority = VSPriority.IDENTIFIERS,
EffectType = EffectType.TEXT, ForegroundColor = "DarkCyan:Maroon", DarkForegroundColor = "Cyan");

RegisterHighlighter(
FSharpHighlightingAttributeIds.MutableFunction,
FallbackAttributeId = FSharpHighlightingAttributeIds.MutableValue,
GroupId = FSharpHighlightingAttributeIds.GroupId,
RiderPresentableName = "Values//Mutable function",
Layer = HighlighterLayer.SYNTAX,
VSPriority = VSPriority.IDENTIFIERS,
EffectType = EffectType.TEXT, ForegroundColor = "DarkCyan:Maroon", DarkForegroundColor = "Cyan");

RegisterHighlighter(
FSharpHighlightingAttributeIds.ComputationExpression,
FallbackAttributeId = FSharpHighlightingAttributeIds.Keyword,
GroupId = FSharpHighlightingAttributeIds.GroupId,
RiderPresentableName = "Values//Computation expression",
Layer = HighlighterLayer.SYNTAX,
EffectType = EffectType.TEXT, ForegroundColor = "#0000E0", DarkForegroundColor = "#569CD6");

RegisterHighlighter(
FSharpHighlightingAttributeIds.Method,
FallbackAttributeId = DefaultLanguageAttributeIds.METHOD,
Expand All @@ -336,7 +375,26 @@ type FSharpSettingsNamesProvider() =
RiderPresentableName = "Values//Active pattern case",
Layer = HighlighterLayer.SYNTAX,
VSPriority = VSPriority.IDENTIFIERS,
EffectType = EffectType.TEXT, ForegroundColor = "DarkCyan:Blue", DarkForegroundColor = "Cyan")>]
EffectType = EffectType.TEXT, ForegroundColor = "DarkCyan:Blue", DarkForegroundColor = "Cyan");

RegisterHighlighter(
FSharpHighlightingAttributeIds.ExtensionMethod,
FallbackAttributeId = FSharpHighlightingAttributeIds.Method,
GroupId = FSharpHighlightingAttributeIds.GroupId,
RiderPresentableName = "Members//Extension method",
Layer = HighlighterLayer.SYNTAX,
VSPriority = VSPriority.IDENTIFIERS,
EffectType = EffectType.TEXT, ForegroundColor = "DarkCyan:Maroon", DarkForegroundColor = "Cyan");

RegisterHighlighter(
FSharpHighlightingAttributeIds.ExtensionProperty,
FallbackAttributeId = FSharpHighlightingAttributeIds.Property,
GroupId = FSharpHighlightingAttributeIds.GroupId,
RiderPresentableName = "Members//Extensions property",
Layer = HighlighterLayer.SYNTAX,
VSPriority = VSPriority.IDENTIFIERS,
EffectType = EffectType.TEXT, ForegroundColor = "Purple", DarkForegroundColor = "Violet")>]

type FSharpHighlightingAttributeIds() = class end

module MissingAssemblyReferenceWorkaround =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let |hello|(1) (|name|(2): |byref|(3)<|string|(4)>) (|other|(5): |inref|(6)<|int

---------------------------------------------------------
(0): ReSharper F# Module Identifier:
(1): ReSharper F# Value Identifier:
(1): ReSharper F# Function Identifier:
(2): ReSharper F# Mutable Value Identifier:
(3): ReSharper F# Class Identifier:
(4): ReSharper F# Class Identifier:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let asyncCex = async { return 1 }

let seqCex = seq { 1 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
let |asyncCex|(0) = |async|(1) { return 1 }

let |seqCex|(2) = |seq|(3) { 1 }

---------------------------------------------------------
(0): ReSharper F# Value Identifier:
(1): ReSharper F# Computation Expression Identifier:
(2): ReSharper F# Value Identifier:
(3): ReSharper F# Computation Expression Identifier:
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
open System

type String with
static member StaticMethod() = "M"
static member StaticProperty = "P"
member x.Method() = "m"
member x.Property = "p"
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
open |System|(0)

type |String|(1) with
static member |StaticMethod|(2)() = "M"
static member |StaticProperty|(3) = "P"
member |x|(4).|Method|(5)() = "m"
member |x|(6).|Property|(7) = "p"

---------------------------------------------------------
(0): ReSharper F# Namespace Identifier:
(1): ReSharper F# Class Identifier:
(2): ReSharper F# Extension Method Identifier:
(3): ReSharper F# Extension Property Identifier:
(4): ReSharper F# Value Identifier:
(5): ReSharper F# Extension Method Identifier:
(6): ReSharper F# Value Identifier:
(7): ReSharper F# Extension Property Identifier:
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
open System
open System.Linq

type Char with
static member IsZero x = x = char 0

let linq (x : string) =
x.Select(Char.IsZero).ToArray()
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
open |System|(0)
open |System|(1).|Linq|(2)

type |Char|(3) with
static member |IsZero|(4) |x|(5) = |x|(6) |=|(7) |char|(8) 0

let |linq|(9) (|x|(10) : |string|(11)) =
|x|(12).|Select|(13)(|Char|(14).|IsZero|(15)).|ToArray|(16)()

---------------------------------------------------------
(0): ReSharper F# Namespace Identifier:
(1): ReSharper F# Namespace Identifier:
(2): ReSharper F# Namespace Identifier:
(3): ReSharper F# Struct Identifier:
(4): ReSharper F# Extension Method Identifier:
(5): ReSharper F# Value Identifier:
(6): ReSharper F# Value Identifier:
(7): ReSharper F# Operator Identifier:
(8): ReSharper F# Function Identifier:
(9): ReSharper F# Function Identifier:
(10): ReSharper F# Value Identifier:
(11): ReSharper F# Class Identifier:
(12): ReSharper F# Value Identifier:
(13): ReSharper F# Extension Method Identifier:
(14): ReSharper F# Struct Identifier:
(15): ReSharper F# Extension Method Identifier:
(16): ReSharper F# Extension Method Identifier:
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
open System

let func f g (x : string) =
let eq = Object.ReferenceEquals(x, null)
let mutable mf = f
g (mf x) eq
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
open |System|(0)

let |func|(1) |f|(2) |g|(3) (|x|(4) : |string|(5)) =
let |eq|(6) = |Object|(7).|ReferenceEquals|(8)(|x|(9), null)
let mutable |mf|(10) = |f|(11)
|g|(12) (|mf|(13) |x|(14)) |eq|(15)
---------------------------------------------------------
(0): ReSharper F# Namespace Identifier:
(1): ReSharper F# Function Identifier:
(2): ReSharper F# Function Identifier:
(3): ReSharper F# Function Identifier:
(4): ReSharper F# Value Identifier:
(5): ReSharper F# Class Identifier:
(6): ReSharper F# Value Identifier:
(7): ReSharper F# Class Identifier:
(8): ReSharper F# Method Identifier:
(9): ReSharper F# Value Identifier:
(10): ReSharper F# Mutable Function Identifier:
(11): ReSharper F# Function Identifier:
(12): ReSharper F# Function Identifier:
(13): ReSharper F# Mutable Function Identifier:
(14): ReSharper F# Value Identifier:
(15): ReSharper F# Value Identifier:
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let inline callTypeFunction<'T when 'T : (static member Two : 'T)> =
(^T : (static member Two : 'T) ())

let inline callTypeFunction2<'T> =
typeof<'T>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
let inline |callTypeFunction|(0)<|'T|(1) when |'T|(2) : (static member |Two|(3) : |'T|(4))> =
(|^T|(5) : (static member |Two|(6) : |'T|(7)) ())

let inline |callTypeFunction2|(8)<|'T|(9)> =
|typeof|(10)<|'T|(11)>

---------------------------------------------------------
(0): ReSharper F# Function Identifier:
(1): ReSharper F# Type Parameter Identifier:
(2): ReSharper F# Type Parameter Identifier:
(3): ReSharper F# Value Identifier:
(4): ReSharper F# Type Parameter Identifier:
(5): ReSharper F# Type Parameter Identifier:
(6): ReSharper F# Value Identifier:
(7): ReSharper F# Type Parameter Identifier:
(8): ReSharper F# Function Identifier:
(9): ReSharper F# Type Parameter Identifier:
(10): ReSharper F# Function Identifier:
(11): ReSharper F# Type Parameter Identifier:
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[<Measure>] type m

type vector3D<[<Measure>] 'u> = { x : float<'u>; y : float<'u>; z : float<'u> }
let xvec : vector3D<m> = { x = 0.0<m>; y = 0.0<m>; z = 0.0<m> }
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[<|Measure|(0)>] type |m|(1)

type |vector3D|(2)<[<|Measure|(3)>] |'u|(4)> = { |x|(5) : |float|(6)<|'u|(7)>; |y|(8) : |float|(9)<|'u|(10)>; |z|(11) : |float|(12)<|'u|(13)> }
let |xvec|(14) : |vector3D|(15)<|m|(16)> = { |x|(17) = 0.0<|m|(18)>; |y|(19) = 0.0<|m|(20)>; |z|(21) = 0.0<|m|(22)> }

---------------------------------------------------------
(0): ReSharper F# Class Identifier:
(1): ReSharper F# Unit Of Measure Identifier:
(2): ReSharper F# Record Identifier:
(3): ReSharper F# Class Identifier:
(4): ReSharper F# Type Parameter Identifier:
(5): ReSharper F# Field Identifier:
(6): ReSharper F# Class Identifier:
(7): ReSharper F# Type Parameter Identifier:
(8): ReSharper F# Field Identifier:
(9): ReSharper F# Class Identifier:
(10): ReSharper F# Type Parameter Identifier:
(11): ReSharper F# Field Identifier:
(12): ReSharper F# Class Identifier:
(13): ReSharper F# Type Parameter Identifier:
(14): ReSharper F# Value Identifier:
(15): ReSharper F# Record Identifier:
(16): ReSharper F# Unit Of Measure Identifier:
(17): ReSharper F# Field Identifier:
(18): ReSharper F# Unit Of Measure Identifier:
(19): ReSharper F# Field Identifier:
(20): ReSharper F# Unit Of Measure Identifier:
(21): ReSharper F# Field Identifier:
(22): ReSharper F# Unit Of Measure Identifier:
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ let _ =

---------------------------------------------------------
(0): ReSharper F# Module Identifier:
(1): ReSharper F# Keyword:
(1): ReSharper F# Computation Expression Identifier:
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace JetBrains.ReSharper.Plugins.FSharp.Tests.Features.Daemon

open JetBrains.ReSharper.TestFramework
open NUnit.Framework
open JetBrains.ReSharper.Plugins.FSharp.Daemon.Cs.Highlightings

Expand Down Expand Up @@ -29,3 +30,17 @@ type IdentifierHighlightingTest() =
[<Test>] member x.``Byrefs 01``() = x.DoNamedTest()

[<Test>] member x.``Union case 01``() = x.DoNamedTest()

[<Test>] member x.``Extension members 01``() = x.DoNamedTest()

[<TestReferences("System", "System.Core")>]
[<Test>] member x.``Extension members 02``() = x.DoNamedTest()

[<TestReferences("System")>]
[<Test>] member x.``Functions 01``() = x.DoNamedTest()

[<Test>] member x.``Functions 02``() = x.DoNamedTest()

[<Test>] member x.``Computation expressions``() = x.DoNamedTest()

[<Test>] member x.``Units of measure``() = x.DoNamedTest()