-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHover.fs
More file actions
42 lines (39 loc) · 1.66 KB
/
Hover.fs
File metadata and controls
42 lines (39 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/// <summary>
/// The hover capability shows a tooltip when you hover over something of interest.
/// </summary>
/// <see href="https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_hover"/>
module LspExample.Hover
open Ionide.LanguageServerProtocol.Types
open LspExample.Types
open LspExample.Types.DemoLang
/// <summary>
/// Generate hover information: the type of the value and some information about it
/// </summary>
/// <param name="hoverLocation">Where the hover is requested</param>
/// <param name="contents">The parsed file to lookup within</param>
let LookupHover (hoverLocation: Position) (contents: Line[]) : Hover =
match contents |> Array.tryItem (int hoverLocation.Line) with
| Some { Value = Number number
Contents = contents
Line = line } ->
{ Contents =
U3.C1
{ MarkupContent.Kind = MarkupKind.PlainText
Value = $"(Number) {number}" }
Range = range (line, 0) (line, contents.Length) |> Some }
| Some { Value = Text text
Contents = contents
Line = line } ->
let leading = text.TrimStart()
let trailing = text.TrimEnd()
{ Contents =
U3.C1
{ MarkupContent.Kind = MarkupKind.PlainText
Value = $"(Text) Length={text.Trim().Length}" }
Range = range (line, contents.Length - leading.Length) (line, trailing.Length) |> Some }
| _ ->
{ Contents =
U3.C1
{ MarkupContent.Kind = MarkupKind.PlainText
Value = "No hover information to display here" }
Range = None }