Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
StachuDotNet committed Apr 5, 2024
1 parent 952428e commit dcaff65
Show file tree
Hide file tree
Showing 9 changed files with 4,208 additions and 3,951 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ module Darklang =
let r = jsonRpcRequest

match (r.method, r.id, r.params) with
| ("darklang/getRootNodes", Some requestId, None) ->
| ("darklang/getRootNodes", Some requestId, _) ->
// TODO: accept (in request params) the name of the specific package to get the root nodes for
TreeView.handleGetRootNodesRequest state requestId

| ("darklang/getChildNodes", Some requestId, Some(Object _p)) ->
Expand Down
79 changes: 30 additions & 49 deletions packages/darklang/languageTools/lsp-server/treeView.dark
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,44 @@ module Darklang =
module LanguageTools =
module LspServer =
module TreeView =
// TODO: move these types to something not our-lang-server -specific
module TreeItemCollapsibleState =
type TreeItemCollapsibleState =
/// Can be neither collapsed nor expanded.
/// (Implies it has no children.)
| None
// <aliases>
type TreeItemType = VSCode.TreeView.TreeItemType.TreeItemType

type TreeItemCollapsibleState =
VSCode.TreeView.TreeItemCollapsibleState.TreeItemCollapsibleState

type TreeItem = VSCode.TreeView.TreeItem.TreeItem
// </aliases>


let makeRootTreeItem (id: String) (label: String) : TreeItem =
TreeItem
{ id = Stdlib.Option.Option.Some id
label =
Stdlib.Option.Option.Some(
VSCode.TreeView.TreeItem.Label.Label.String label
)
collapsibleState = Stdlib.Option.Option.None
command = Stdlib.Option.Option.None
contextValue = Stdlib.Option.Option.None
checkboxState = Stdlib.Option.Option.None
accessibilityInformation = Stdlib.Option.Option.None
description = Stdlib.Option.Option.None
iconPath = Stdlib.Option.Option.None
resourceUri = Stdlib.Option.Option.None
tooltip = Stdlib.Option.Option.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 TreeItem =
type TreeItem =
{ id: String
label: String
type_: TreeItemType.TreeItemType
collapsibleState: TreeItemCollapsibleState.TreeItemCollapsibleState }

let toJson (i: TreeItem) : Json =
Json.Object
[ ("id", Json.String i.id)
("label", Json.String i.label)
("type", TreeItemType.toJson i.type_)
("collapsibleState",
TreeItemCollapsibleState.toJson i.collapsibleState) ]

/// handles `darklang/getRootNodes` requests
let handleGetRootNodesRequest
(state: LspState)
(requestId: JsonRPC.RequestId)
: LspState =
let response =
[ TreeItem.TreeItem
{ id = "test"
label = "Testing"
type_ = TreeItemType.TreeItemType.File
collapsibleState =
TreeItemCollapsibleState.TreeItemCollapsibleState.None } ]
|> Stdlib.List.map (fun i -> TreeItem.toJson i)
[ makeRootTreeItem "@darklang" "Darklang"
makeRootTreeItem "@stachu" "Stachu" ]

|> Stdlib.List.map (fun i -> VSCode.TreeView.TreeItem.toJson i)
|> Json.Array

let responseJson =
Expand Down
1 change: 1 addition & 0 deletions packages/darklang/vscode/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Interacting with the VS Code API
88 changes: 88 additions & 0 deletions packages/darklang/vscode/main.dark
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
174 changes: 174 additions & 0 deletions packages/darklang/vscode/tree-view.dark
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
Loading

0 comments on commit dcaff65

Please sign in to comment.