-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
952428e
commit dcaff65
Showing
9 changed files
with
4,208 additions
and
3,951 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Interacting with the VS Code API |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
module Darklang = | ||
module VSCode = | ||
// <aliases> | ||
type Json = Stdlib.AltJson.Json | ||
// </aliases> | ||
|
||
/// Not sure if this is the best way to handle this... will this be OK across the wire? | ||
module Uri = | ||
type Uri = | ||
{ | ||
/// Scheme is the http part of | ||
/// http://www.example.com/some/path?query#fragment. | ||
/// The part before the first colon. | ||
scheme: String | ||
|
||
/// Authority is the www.example.com part of | ||
/// http://www.example.com/some/path?query#fragment. | ||
/// The part between the first double slashes and the next slash. | ||
authority: String | ||
|
||
/// Path is the /some/path part of | ||
/// http://www.example.com/some/path?query#fragment. | ||
path: String | ||
|
||
/// Query is the query part of | ||
/// http://www.example.com/some/path?query#fragment. | ||
query: String | ||
|
||
/// Fragment is the fragment part of | ||
/// http://www.example.com/some/path?query#fragment. | ||
fragment: String | ||
|
||
//TODO: fsPath: String | ||
} | ||
|
||
let toJson (u: Uri) : Json = | ||
[ ("scheme", Json.String u.scheme) | ||
("authority", Json.String u.authority) | ||
("path", Json.String u.path) | ||
("query", Json.String u.query) | ||
("fragment", Json.String u.fragment) ] | ||
|> Json.Object | ||
|
||
|
||
module AccessibilityInformation = | ||
type AccessibilityInformation = | ||
{ | ||
/// Label to be read out by a screen reader once the item has focus. | ||
label: String | ||
|
||
/// Role of the widget which defines how a screen reader interacts with it. | ||
/// The role should be set in special cases when for example a tree-like | ||
/// element behaves like a checkbox. If role is not specified the editor | ||
/// will pick the appropriate role automatically. | ||
/// More about aria roles can be found here https://w3c.github.io/aria/#widget_roles | ||
role: Stdlib.Option.Option<String> | ||
} | ||
|
||
let toJson (i: AccessibilityInformation) : Json = | ||
[ Some(("label", Json.String i.label)) | ||
role |> Stdlib.Option.map (fun r -> ("role", Json.String r)) ] | ||
|> Stdlib.Option.values | ||
|> Json.Object | ||
|
||
|
||
module Command = | ||
type Command = | ||
{ | ||
/// Arguments that the command handler should be invoked with. | ||
arguments: Stdlib.Option.Option<List<Json>> | ||
|
||
/// The identifier of the actual command handler. | ||
command: String | ||
|
||
/// Title of the command, like save. | ||
title: String | ||
|
||
/// A tooltip for the command, when represented in the UI. | ||
tooltip: Stdlib.Option.Option<String> | ||
} | ||
|
||
let toJson (c: Command) : Json = | ||
[ c.arguments |> Stdlib.Option.map (fun a -> ("arguments", Json.Array a)) | ||
Some(("command", Json.String c.command)) | ||
Some(("title", Json.String c.title)) | ||
c.tooltip |> Stdlib.Option.map (fun t -> ("tooltip", Json.String t)) ] | ||
|> Stdlib.Option.values | ||
|> Json.Object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
module Darklang = | ||
module VSCode = | ||
|
||
// https://code.visualstudio.com/api/references/vscode-api#TreeItemCollapsibleState for references | ||
module TreeView = | ||
module TreeItemCollapsibleState = | ||
type TreeItemCollapsibleState = | ||
/// Can be neither collapsed nor expanded. | ||
/// (Implies it has no children.) | ||
| None | ||
|
||
| Collapsed | ||
|
||
| Expanded | ||
|
||
let toJson (state: TreeItemCollapsibleState) : Json = | ||
match state with | ||
| None -> Json.Number 0.0 | ||
| Collapsed -> Json.Number 1.0 | ||
| Expanded -> Json.Number 2.0 | ||
|
||
|
||
module TreeItemType = | ||
type TreeItemType = | ||
| File | ||
| Directory | ||
|
||
let toJson (t: TreeItemType) : Json = | ||
match t with | ||
| File -> Json.String "file" | ||
| Directory -> Json.String "directory" | ||
|
||
|
||
module TreeItemCheckboxState = | ||
type TreeItemCheckboxState = | ||
| Unchecked | ||
| Checked | ||
|
||
let toJson (state: TreeItemCheckboxState) : Json = | ||
match state with | ||
| Unchecked -> Json.Number 0.0 | ||
| Checked -> Json.Number 1.0 | ||
|
||
module TreeItemLabel = | ||
type TreeItemLabel = | ||
{ label: String | ||
highlights: Stdlib.Option.Option<List<Int64 * Int64>> } | ||
|
||
let toJson (l: TreeItemLabel) : Json = | ||
[ Some(("label", Json.String l.label)) | ||
|
||
l.highlights | ||
|> Stdlib.Option.map (fun h -> | ||
("highlights", | ||
h | ||
|> Stdlib.List.map (fun (s, e) -> | ||
[ s |> Stdlib.Int64.toFloat |> Json.Number | ||
e |> Stdlib.Int64.toFloat |> Json.Number ] | ||
|> Json.Array) | ||
|> Json.Array)) ] | ||
|> Stdlib.Option.values | ||
|> Json.Object | ||
|
||
|
||
module TreeItem = | ||
module Description = | ||
type Description = | ||
| String of String | ||
| Bool of Bool | ||
|
||
let toJson (d: Description) : Json = | ||
match d with | ||
| String s -> Json.String s | ||
| Bool b -> Json.Bool b | ||
|
||
|
||
module Label = | ||
type Label = | ||
| String of String | ||
| TreeItemLabel of TreeItemLabel.TreeItemLabel | ||
|
||
let toJson (l: Label) : Json = | ||
match l with | ||
| String s -> Json.String s | ||
| TreeItemLabel l -> TreeItemLabel.toJson l | ||
|
||
|
||
module IconPath = | ||
type IconPath = | ||
// TODO: handle more of these | ||
//| Uri of Uri | ||
//| DarkAndLight of | ||
// ThemeIcon of | ||
| String of String | ||
|
||
let toJson (i: IconPath) : Json = | ||
match i with | ||
| String s -> Json.String s | ||
|
||
|
||
module Tooltip = | ||
type Tooltip = | ||
// TODO: MarkdownString of MarkdownString | ||
| String of String | ||
|
||
let toJson (t: Tooltip) : Json = | ||
match t with | ||
| String s -> Json.String s | ||
|
||
|
||
type TreeItem = | ||
{ | ||
id: Stdlib.Option.Option<String> | ||
label: Stdlib.Option.Option<Label.Label> | ||
collapsibleState: | ||
Stdlib.Option.Option<TreeItemCollapsibleState.TreeItemCollapsibleState> | ||
|
||
command: Stdlib.Option.Option<Command.Command> | ||
|
||
/// Context value of the tree item. This can be used to contribute item specific | ||
/// actions in the tree. For example, a tree item is given a context value as folder. | ||
/// When contributing actions to view/item/context using menus extension point, | ||
/// you can specify context value for key viewItem in when expression like viewItem == folder. | ||
contextValue: Stdlib.Option.Option<String> | ||
|
||
checkboxState: | ||
Stdlib.Option.Option<TreeItemCheckboxState.TreeItemCheckboxState> | ||
accessibilityInformation: | ||
Stdlib.Option.Option<AccessibilityInformation.AccessibilityInformation> | ||
|
||
description: Stdlib.Option.Option<Description.Description> | ||
|
||
iconPath: Stdlib.Option.Option<IconPath.IconPath> | ||
|
||
resourceUri: Stdlib.Option.Option<Uri.Uri> | ||
|
||
tooltip: Stdlib.Option.Option<Tooltip.Tooltip> | ||
} | ||
|
||
let toJson (i: TreeItem) : Json = | ||
[ i.id |> Stdlib.Option.map (fun id -> ("id", Json.String id)) | ||
|
||
i.label |> Stdlib.Option.map (fun l -> ("label", Label.toJson l)) | ||
|
||
i.collapsibleState | ||
|> Stdlib.Option.map (fun s -> | ||
("collapsibleState", TreeItemCollapsibleState.toJson s)) | ||
|
||
i.command |> Stdlib.Option.map (fun c -> ("command", Command.toJson c)) | ||
|
||
i.contextValue | ||
|> Stdlib.Option.map (fun cv -> ("contextValue", Json.String cv)) | ||
|
||
i.checkboxState | ||
|> Stdlib.Option.map (fun cs -> | ||
("checkboxState", TreeItemCheckboxState.toJson cs)) | ||
|
||
i.accessibilityInformation | ||
|> Stdlib.Option.map (fun ai -> | ||
("accessibilityInformation", AccessibilityInformation.toJson ai)) | ||
|
||
i.description | ||
|> Stdlib.Option.map (fun d -> ("description", Description.toJson d)) | ||
|
||
i.iconPath | ||
|> Stdlib.Option.map (fun ip -> ("iconPath", IconPath.toJson ip)) | ||
|
||
i.resourceUri | ||
|> Stdlib.Option.map (fun r -> ("resourceUri", Uri.toJson r)) | ||
|
||
i.tooltip |> Stdlib.Option.map (fun t -> ("tooltip", Tooltip.toJson t)) ] | ||
|
||
|> Stdlib.Option.values | ||
|> Json.Object |
Oops, something went wrong.