Skip to content

Commit

Permalink
Use Uri(_) directly (fixes fsprojects#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgewfraser committed Jan 27, 2019
1 parent 1e99829 commit cb973a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
5 changes: 1 addition & 4 deletions src/LSP/Ser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,7 @@ let rec private deserializer<'T> (options: JsonReadOptions, t: Type): JsonValue
fun j -> box(j.AsString())
elif t = typeof<Uri> then
fun j ->
// It seems that the Uri(...) constructor assumes the string has already been unescaped
let escaped = j.AsString()
let unescaped = Uri.UnescapeDataString(escaped)
box(Uri(unescaped))
box(Uri(j.AsString()))
elif t = typeof<JsonValue> then
fun j -> box(j)
elif isList t then
Expand Down
17 changes: 14 additions & 3 deletions tests/LSP.Tests/ParserTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -251,22 +251,33 @@ let ``parse a DidChangeWatchedFiles notification`` () =
let ``parse a minimal Initialize request`` () =
let json = JsonValue.Parse """{
"processId": 1,
"rootUri": "file://workspace",
"rootUri": "file:///workspace",
"capabilities": {
}
}"""
let (Initialize i) = parseRequest("initialize", json)
let expected = (
{
processId = Some 1;
rootUri = Some (Uri("file://workspace"));
processId = Some(1);
rootUri = Some(Uri("file:///workspace"));
initializationOptions = None;
capabilitiesMap = Map.empty;
trace = None
}
)
Assert.AreEqual(expected, i)

[<Test>]
let ``parse a special character in a URI`` () =
let json = JsonValue.Parse """{
"processId": 1,
"rootUri": "file:///dir/f%23-test",
"capabilities": {
}
}"""
let (Initialize i) = parseRequest("initialize", json)
Assert.AreEqual(i.rootUri.Value.LocalPath, "/dir/f#-test")

[<Test>]
let ``processId can be null`` () =
let json = JsonValue.Parse """{
Expand Down

0 comments on commit cb973a1

Please sign in to comment.