-
Notifications
You must be signed in to change notification settings - Fork 15
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
content script now doesn't rewrite code as refmt errors #92
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,19 @@ | ||
open Core; | ||
|
||
module Refmt = { | ||
let refmt = Refmt2.refmtJS; | ||
let refmt = Refmt2.refmt; | ||
let parse = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use Result.map? let parse = Result.map(((inlang, outLang, outText)) =>
Protocol.Refmt.{ outText, inLang, outLang }; |
||
fun | ||
| ("Failure", error) => Protocol.Error(error) | ||
| (conversion, outText) => | ||
switch (conversion |> Js.String.split("to")) { | ||
| [|inLang, outLang|] when Protocol.languageOfString(outLang) != RefmtShared.UnknownLang => | ||
Protocol.Ok( | ||
| Result.Error(error) => Result.Error(error) | ||
| Result.Ok((inLang, outLang, outText)) => | ||
Result.Ok( | ||
Protocol.Refmt.{ | ||
outText, | ||
inLang: Protocol.languageOfString(inLang), | ||
outLang: Protocol.languageOfString(outLang) | ||
inLang, | ||
outLang | ||
} | ||
) | ||
| _ => Protocol.Error(outText) | ||
}; | ||
; | ||
}; | ||
|
||
Protocol.Refmt.listen( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
open Common; | ||
|
||
type result('a, 'e) = | ||
| Ok('a) | ||
| Error('e); | ||
open Result; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for the open since all the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah IDK why that's there :3 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
type language = RefmtShared.language; | ||
|
||
|
@@ -30,58 +27,47 @@ module Refmt = { | |
inType: codeType, | ||
outLang: language | ||
}; | ||
type payloadSerialized = { | ||
outText: string, | ||
inLang: string, | ||
outLang: string | ||
}; | ||
[@bs.deriving jsConverter] | ||
type payload = { | ||
outText: string, | ||
inLang: language, | ||
outLang: language | ||
}; | ||
type response = result(payload, string); | ||
type response = result(string, payload); | ||
let responseToJs = x => { | ||
switch (x) { | ||
| Result.Ok(x) => Obj.magic(("Ok", payloadToJs(x))) | ||
| Result.Error(x) => Obj.magic(("Error", x)) | ||
}; | ||
}; | ||
let responseFromJs:Js.Json.t=>response = x => { | ||
switch(Obj.magic(x)) { | ||
| ("Ok", x) => Result.Ok(payloadFromJs(Obj.magic(x))) | ||
| (_, x) => Result.Error(Obj.magic(x)) | ||
}; | ||
}; | ||
/* Bucklescript's variant tags will be erased when serialized, so we have to manually serialize the response | ||
*/ | ||
let serialize: result(payload, string) => (int, payloadSerialized) = | ||
fun | ||
| Error(error) => (0, {outText: error, inLang: "", outLang: ""}) | ||
| Ok(payload) => ( | ||
1, | ||
{ | ||
outText: payload.outText, | ||
inLang: stringOfLanguage(payload.inLang), | ||
outLang: stringOfLanguage(payload.outLang) | ||
} | ||
); | ||
let deserialize: ((int, payloadSerialized)) => result(payload, string) = | ||
fun | ||
| (0, {outText: error}) => Error(error) | ||
| (1, payload) => | ||
Ok({ | ||
outText: payload.outText, | ||
inLang: languageOfString(payload.inLang), | ||
outLang: languageOfString(payload.outLang) | ||
}) | ||
| _ => raise(DeserializationFail); | ||
let send = | ||
( | ||
text, | ||
~inLang=RefmtShared.UnknownLang, | ||
~inType=RefmtShared.UnknownType, | ||
~outLang=RefmtShared.UnknownLang, | ||
cb | ||
cb:(response)=>unit | ||
) => | ||
Message.query( | ||
"refmt:refmt", | ||
{input: text |> normalizeText |> untoplevel, inLang, inType, outLang}, | ||
(response) => cb(deserialize(response)) | ||
(response) => cb(responseFromJs(response)) | ||
); | ||
let listen: ((request, response => unit) => unit) => unit = | ||
(cb) => | ||
Message.receive( | ||
"refmt:refmt", | ||
(request, _, respond) => cb(request, (r) => r |> serialize |> respond) | ||
(request, _, respond) => cb(request, (r) => { | ||
r |> responseToJs |> respond; | ||
}) | ||
); | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,9 @@ let getBlacklist = () => [ | |
"mwhittaker.github.io/distributed-systems-ocaml/code_MorePipes.html" /* #49 */ | ||
]; | ||
|
||
let getWhitelist = () => []; | ||
let getWhitelist = () => [ | ||
"codebad.com/~hdon/reason-tools-test.html" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for adding this test! |
||
]; | ||
|
||
let getSignificantUrl = () => Location.hostname ++ Location.pathname; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Much more reliable.