Skip to content

Commit

Permalink
Merge pull request dotnet#16 from cmeeren/codelens-coloroption
Browse files Browse the repository at this point in the history
Implement color option
  • Loading branch information
realvictorprm authored Oct 25, 2017
2 parents afc2622 + 4e4ff6a commit fb5a132
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 34 deletions.
27 changes: 25 additions & 2 deletions vsintegration/src/FSharp.Editor/CodeLens/LineLens.fs
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,32 @@ type internal FSharpCodeLensService
let! taggedText, navigation = lens.TaggedText
let textBox = new TextBlock(Width = 500., Background = Brushes.Transparent, Opacity = 0.0, TextTrimming = TextTrimming.None)
DependencyObjectExtensions.SetDefaultTextProperties(textBox, formatMap.Value)
textBox.Inlines.Add (Documents.Run Settings.CodeLens.Prefix)

let prefix = Documents.Run Settings.CodeLens.Prefix
prefix.Foreground <- SolidColorBrush(Color.FromRgb(153uy, 153uy, 153uy))
textBox.Inlines.Add (prefix)

for text in taggedText do

let coloredProperties = layoutTagToFormatting text.Tag
let actualProperties =
if Settings.CodeLens.UseColors
then
// If color is gray (R=G=B), change to correct gray color.
// Otherwise, use the provided color.
match coloredProperties.ForegroundBrush with
| :? SolidColorBrush as b ->
let c = b.Color
if c.R = c.G && c.R = c.B
then coloredProperties.SetForeground(Color.FromRgb(153uy, 153uy, 153uy))
else coloredProperties
| _ -> coloredProperties
else
coloredProperties.SetForeground(Color.FromRgb(153uy, 153uy, 153uy))

let run = Documents.Run text.Text
DependencyObjectExtensions.SetTextProperties (run, layoutTagToFormatting text.Tag)
DependencyObjectExtensions.SetTextProperties (run, actualProperties)

let inl =
match text with
| :? Layout.NavigableTaggedText as nav when navigation.IsTargetValid nav.Range ->
Expand All @@ -362,6 +384,7 @@ type internal FSharpCodeLensService
navigation.NavigateTo nav.Range)
h :> Documents.Inline
| _ -> run :> _
DependencyObjectExtensions.SetTextProperties (inl, actualProperties)
textBox.Inlines.Add inl
lens.Computed <- true
lens.UiElement <- textBox
Expand Down
2 changes: 2 additions & 0 deletions vsintegration/src/FSharp.Editor/Options/EditorOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type LanguageServicePerformanceOptions =
type CodeLensOptions =
{ Enabled : bool
ReplaceWithLineLens: bool
UseColors: bool
Prefix : string }

[<Export(typeof<ISettings>)>]
Expand Down Expand Up @@ -73,6 +74,7 @@ type internal Settings [<ImportingConstructor>](store: SettingsStore) =

store.RegisterDefault
{ Enabled = true
UseColors = false
ReplaceWithLineLens = true
Prefix = "// " }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
<StackPanel>
<CheckBox x:Name="enableCodeLens" IsChecked="{Binding Enabled}"
Content="{x:Static local:Strings.CodeLens_Switch}"/>
<CheckBox x:Name="useColors" IsChecked="{Binding UseColors}"
Content="{x:Static local:Strings.CodeLens_UseColors}"/>
<CheckBox x:Name="replaceWithLineLens" IsChecked="{Binding ReplaceWithLineLens}"
Content="{x:Static local:Strings.CodeLens_Replace_LineLens}"/>
<Grid>
Expand Down
73 changes: 41 additions & 32 deletions vsintegration/src/FSharp.UIResources/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vsintegration/src/FSharp.UIResources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,7 @@
<data name="CodeLens_Prefix" xml:space="preserve">
<value>Annotation prefix</value>
</data>
<data name="CodeLens_UseColors" xml:space="preserve">
<value>Use colors in annotations</value>
</data>
</root>

0 comments on commit fb5a132

Please sign in to comment.