-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypes.fs
More file actions
68 lines (55 loc) · 2.1 KB
/
Types.fs
File metadata and controls
68 lines (55 loc) · 2.1 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
module LspExample.Types
open System
open System.IO
open Ionide.LanguageServerProtocol.Types
/// <summary>
/// An absolute path on the file system. Should be a real file or directory.
/// </summary>
type AbsolutePath = AbsolutePath of string
/// Functions for working with AbsolutePaths
module AbsolutePath =
/// Handle windows path separators
let private deDOS (path: string) =
if Path.DirectorySeparatorChar = '\\' then
path.Replace('\\', '/')
else
path
let ofUri (uri: Uri) =
uri.AbsolutePath |> Uri.UnescapeDataString |> deDOS |> AbsolutePath
let toString (AbsolutePath path) = path
let toUri (AbsolutePath path) =
if Environment.OSVersion.Platform = PlatformID.Win32NT then
$"file:///%s{path}"
else
$"file://%s{path}"
/// <summary>
/// Convert a file URI from the client to an absolute file path for the local file system.
/// </summary>
/// <remarks>Removes the schema and unescapes any specially encoded characters because the LSP spec does not specify if characters are encoded.</remarks>
/// <param name="uri">The file URI to convert</param>
let uriToPath (uri: string) =
uri |> Uri.UnescapeDataString |> Uri |> AbsolutePath.ofUri
/// Active pattern to make working with .NET BCL Try* functions nicer
let (|Success|Nothing|) (valueFound: bool, value: 'a) =
if valueFound then Success value else Nothing
/// Construct an LSP range record
let range (startLine: int, startColumn: int) (endLine: int, endColumn: int) : Range =
{ Start =
{ Line = uint32 startLine
Character = uint32 startColumn }
End =
{ Line = uint32 endLine
Character = uint32 endColumn } }
/// Holder for cached file contents that are synced from the LSP client
[<ReferenceEquality>]
type FileContent = FileContent of int * string
/// Define the abstract types of the simple demo language
module DemoLang =
type Value =
| Number of float
| Text of string
| Empty of string
type Line =
{ Line: int
Contents: string
Value: Value }