text
stringlengths
12
786k
module DocumentSelector = struct type selector = ( [ ` Filter of DocumentFilter . t | ` String of string ] [ @ js . union ] ) [ @@ js ] let selector_of_js js_val = match Ojs . type_of js_val with | " string " -> ` String ( [ % js . to : string ] js_val ) | _ -> ` Filter ( [ % js . to : DocumentFilter . t ] js_val ) type t = ( [ ` Filter of DocumentFilter . t | ` String of string | ` List of selector list ] [ @ js . union ] ) [ @@ js ] let t_of_js js_val = if Ojs . type_of js_val = " string " then ` String ( [ % js . to : string ] js_val ) else if Ojs . has_property js_val " length " then ` List ( [ % js . to : selector list ] js_val ) else ` Filter ( [ % js . to : DocumentFilter . t ] js_val ) end
module DocumentFormattingEditProvider = struct include Interface . Make ( ) include [ % js : val provideDocumentFormattingEdits : t -> document : TextDocument . t -> options : FormattingOptions . t -> token : CancellationToken . t -> TextEdit . t list ProviderResult . t [ @@ js . call ] val create : provideDocumentFormattingEdits : ( document : TextDocument . t -> options : FormattingOptions . t -> token : CancellationToken . t -> TextEdit . t list ProviderResult . t ) -> t [ @@ js . builder ] ] end
module Hover = struct include Interface . Make ( ) include [ % js : val contents : t -> MarkdownString . t [ @@ js . get ] val range : t -> Range . t or_undefined [ @@ js . get ] val make : contents : ( [ ` MarkdownString of MarkdownString . t | ` MarkdownStringArray of MarkdownString . t list ] [ @ js . union ] ) -> t [ @@ js . new " vscode . Hover " ] ] end
module HoverProvider = struct include Interface . Make ( ) include [ % js : val provideHover : t -> document : TextDocument . t -> position : Position . t -> token : CancellationToken . t -> Hover . t ProviderResult . t [ @@ js . call ] val create : provideHover : ( document : TextDocument . t -> position : Position . t -> token : CancellationToken . t -> Hover . t ProviderResult . t ) -> t [ @@ js . builder ] ] end
module TaskGroup = struct include Class . Make ( ) include [ % js : val clean : t [ @@ js . global " vscode . TaskGroup . Clean " ] val build : t [ @@ js . global " vscode . TaskGroup . Build " ] val rebuild : t [ @@ js . global " vscode . TaskGroup . Rebuild " ] val test : t [ @@ js . global " vscode . TaskGroup . Test " ] ] end
module TaskScope = struct type t = | Folder of WorkspaceFolder . t | Global | Workspace let t_to_js = function | Folder f -> [ % js . of : WorkspaceFolder . t ] f | Global -> [ % js . of : int ] 1 | Workspace -> [ % js . of : int ] 2 let t_of_js js_val = match Ojs . type_of js_val with | " number " when [ % js . to : int ] js_val = 1 -> Global | " number " when [ % js . to : int ] js_val = 2 -> Workspace | _ -> Folder ( [ % js . to : WorkspaceFolder . t ] js_val ) end
module RunOptions = struct include Interface . Make ( ) include [ % js : val reevaluateOnRerun : t -> bool or_undefined [ @@ js . get ] val create : ? reevaluateOnRerun : bool -> unit -> t [ @@ js . builder ] ] end
module TaskRevealKind = struct type t = | Always [ @ js 1 ] | Silent [ @ js 2 ] | Never [ @ js 3 ] [ @@ js . enum ] [ @@ js ] end
module TaskPanelKind = struct type t = | Shared [ @ js 1 ] | Dedicated [ @ js 2 ] | New [ @ js 3 ] [ @@ js . enum ] [ @@ js ] end
module TaskPresentationOptions = struct include Interface . Make ( ) include [ % js : val reveal : t -> TaskRevealKind . t or_undefined [ @@ js . get ] val echo : t -> bool or_undefined [ @@ js . get ] val focus : t -> bool or_undefined [ @@ js . get ] val panel : t -> TaskPanelKind . t or_undefined [ @@ js . get ] val showReuseMessage : t -> bool or_undefined [ @@ js . get ] val clear : t -> bool or_undefined [ @@ js . get ] val create : ? reveal : TaskRevealKind . t -> ? echo : bool -> ? focus : bool -> ? panel : TaskPanelKind . t -> ? showReuseMessage : bool -> ? clear : bool -> unit -> t [ @@ js . builder ] ] end
module Task = struct include Class . Make ( ) type execution = ( [ ` ProcessExecution of ProcessExecution . t | ` ShellExecution of ShellExecution . t | ` CustomExecution of CustomExecution . t ] [ @ js . union ] ) [ @@ js ] let execution_of_js js_val = if Ojs . has_property js_val " process " then ` ProcessExecution ( [ % js . to : ProcessExecution . t ] js_val ) else if Ojs . has_property js_val " command " then ` ShellExecution ( [ % js . to : ShellExecution . t ] js_val ) else ` CustomExecution ( [ % js . to : CustomExecution . t ] js_val ) include [ % js : val make : definition : TaskDefinition . t -> scope : TaskScope . t -> name : string -> source : string -> ? execution : execution -> ? problemMatchers : string list -> unit -> t [ @@ js . new " vscode . Task " ] val definition : t -> TaskDefinition . t [ @@ js . get ] val scope : t -> TaskScope . t or_undefined [ @@ js . get ] val name : t -> string [ @@ js . get ] val detail : t -> string or_undefined [ @@ js . get ] val execution : t -> execution or_undefined [ @@ js . get ] val isBackground : t -> bool [ @@ js . get ] val source : t -> string [ @@ js . get ] val group : t -> TaskGroup . t or_undefined [ @@ js . get ] val presentationOptions : t -> TaskPresentationOptions . t [ @@ js . get ] val runOptions : t -> RunOptions . t [ @@ js . get ] val set_group : t -> TaskGroup . t -> unit [ @@ js . set ] ] end
module TaskProvider = struct include Interface . Generic ( Ojs ) ( ) module Make ( T : Js . T ) = struct type t = T . t generic [ @@ js ] include [ % js : val provideTasks : t -> token : CancellationToken . t -> T . t list ProviderResult . t [ @@ js . call ] val resolveTask : t -> task : T . t -> token : CancellationToken . t -> T . t ProviderResult . t [ @@ js . call ] val create : provideTasks ( : token : CancellationToken . t -> T . t list ProviderResult . t ) -> resolveTask : ( task : T . t -> token : CancellationToken . t -> T . t ProviderResult . t ) -> t [ @@ js . builder ] ] end module Default = Make ( Task ) end
module ConfigurationScope = struct type t = ( [ ` Uri of Uri . t | ` TextDocument of TextDocument . t | ` WorkspaceFolder of WorkspaceFolder . t ] [ @ js . union ] ) [ @@ js ] let t_of_js js_val = if Ojs . has_property js_val " path " then ` Uri ( [ % js . to : Uri . t ] js_val ) else if Ojs . has_property js_val " index " then ` WorkspaceFolder ( [ % js . to : WorkspaceFolder . t ] js_val ) else ` TextDocument ( [ % js . to : TextDocument . t ] js_val ) end
module MessageOptions = struct include Interface . Make ( ) include [ % js : val modal : t -> bool or_undefined [ @@ js . get ] val create : ? modal : bool -> unit -> t [ @@ js . builder ] ] end
module Progress = struct include Interface . Make ( ) type value = { message : string or_undefined ; increment : int or_undefined } [ @@ js ] include [ % js : val report : t -> value : value -> unit [ @@ js . call ] ] end
module TextDocumentContentChangeEvent = struct include Interface . Make ( ) include [ % js : val range : t -> Range . t [ @@ js . get ] val rangeLength : t -> int [ @@ js . get ] val rangeOffset : t -> int [ @@ js . get ] val text : t -> string [ @@ js . get ] ] end
module TextDocumentChangeEvent = struct include Interface . Make ( ) include [ % js : val contentChanges : t -> TextDocumentContentChangeEvent . t list [ @@ js . get ] val document : t -> TextDocument . t [ @@ js . get ] ] end
module TextDocumentContentProvider = struct include Interface . Make ( ) module OnDidChange = Event . Make ( Uri ) include [ % js : val onDidChange : t -> OnDidChange . t or_undefined [ @@ js . get ] val provideTextDocumentContent : t -> uri : Uri . t -> token : CancellationToken . t -> string ProviderResult . t [ @@ js . call ] val create : ? onDidChange : OnDidChange . t -> provideTextDocumentContent : ( uri : Uri . t -> token : CancellationToken . t -> string ProviderResult . t ) -> unit -> t [ @@ js . builder ] ] end
module FileSystemWatcher = struct include Interface . Make ( ) module OnDidChange = Event . Make ( Uri ) include [ % js : val onDidChange : t -> OnDidChange . t [ @@ js . get ] ] end
module Workspace = struct module OnDidChangeWorkspaceFolders = Event . Make ( WorkspaceFolder ) module OnDidOpenTextDocument = Event . Make ( TextDocument ) module OnDidCloseTextDocument = Event . Make ( TextDocument ) module OnDidSaveTextDocument = Event . Make ( TextDocument ) module OnDidChangeTextDocument = Event . Make ( TextDocumentChangeEvent ) type textDocumentOptions = { language : string ; content : string } [ @@ js ] type workspaceFolderToAdd = { name : string ; uri : Uri . t } [ @@ js ] include [ % js : val workspaceFolders : unit -> WorkspaceFolder . t maybe_list [ @@ js . get " vscode . workspace . workspaceFolders " ] val name : unit -> string or_undefined [ @@ js . get " vscode . workspace . name " ] val createFileSystemWatcher : GlobPattern . t -> ? ignoreCreateEvents ( : bool [ @ js . default false ] ) -> ? ignoreChangeEvents ( : bool [ @ js . default false ] ) -> ? ignoreDeleteEvents ( : bool [ @ js . default false ] ) -> unit -> FileSystemWatcher . t [ @@ js . global " vscode . workspace . createFileSystemWatcher " ] val workspaceFile : unit -> Uri . t or_undefined [ @@ js . get " vscode . workspace . workspaceFile " ] val rootPath : unit -> string or_undefined [ @@ js . get " vscode . workspace . rootPath " ] val textDocuments : unit -> TextDocument . t list [ @@ js . get " vscode . workspace . textDocuments " ] val onDidChangeWorkspaceFolders : OnDidChangeWorkspaceFolders . t [ @@ js . global " vscode . workspace . onDidChangeWorkspaceFolders " ] val getWorkspaceFolder : uri : Uri . t -> WorkspaceFolder . t or_undefined [ @@ js . global " vscode . workspace . getWorkspaceFolder " ] val onDidOpenTextDocument : OnDidOpenTextDocument . t [ @@ js . global " vscode . workspace . onDidOpenTextDocument " ] val onDidSaveTextDocument : OnDidSaveTextDocument . t [ @@ js . global " vscode . workspace . onDidSaveTextDocument " ] val onDidCloseTextDocument : OnDidCloseTextDocument . t [ @@ js . global " vscode . workspace . onDidCloseTextDocument " ] val onDidChangeTextDocument : OnDidChangeTextDocument . t [ @@ js . global " vscode . workspace . onDidChangeTextDocument " ] val applyEdit : edit : WorkspaceEdit . t -> bool Promise . t [ @@ js . global " vscode . workspace . applyEdit " ] val registerTextDocumentContentProvider : scheme : string -> provider : TextDocumentContentProvider . t -> Disposable . t [ @@ js . global " vscode . workspace . registerTextDocumentContentProvider " ] val asRelativePath : pathOrUri ( [ : ` String of string | ` Uri of Uri . t ] [ @ js . union ] ) -> ? includeWorkspaceFolder : bool -> unit -> string [ @@ js . global " vscode . workspace . asRelativePath " ] val getConfiguration : ? section : string -> ? scope : ConfigurationScope . t -> unit -> WorkspaceConfiguration . t [ @@ js . global " vscode . workspace . getConfiguration " ] val findFiles : includes : GlobPattern . t -> ? excludes : GlobPattern . t -> ? maxResults : int -> ? token : CancellationToken . t -> unit -> Uri . t list Promise . t [ @@ js . global " vscode . workspace . findFiles " ] val openTextDocument : ( [ ` Uri of Uri . t | ` Filename of string | ` Interactive of textDocumentOptions or_undefined ] [ @ js . union ] ) -> TextDocument . t Promise . t [ @@ js . global " vscode . workspace . openTextDocument " ] val updateWorkspaceFolders : start : int -> deleteCount : int or_undefined -> workspaceFoldersToAdd ( : workspaceFolderToAdd list [ @ js . variadic ] ) -> bool [ @@ js . global " vscode . workspace . updateWorkspaceFolders " ] ] end
module TreeItemCollapsibleState = struct type t = | None [ @ js 0 ] | Collapsed [ @ js 1 ] | Expanded [ @ js 2 ] [ @@ js . enum ] [ @@ js ] end
module CustomDocument = struct module type T = sig include Js . T val uri : t -> Uri . t val dispose : t -> unit end include Interface . Make ( ) include [ % js : val uri : t -> Uri . t [ @@ js . get ] val dispose : t -> unit [ @@ js . call ] val create : uri : Uri . t -> dispose ( : unit -> unit ) -> t [ @@ js . builder ] ] end
module TreeItemLabel = struct include Interface . Make ( ) include [ % js : val label : t -> string [ @@ js . get ] val highlights : t -> ( int * int ) list or_undefined [ @@ js . get ] val create : label : string -> ? highlights ( : int * int ) list -> unit -> t [ @@ js . builder ] ] end
module ThemeIcon = struct include Class . Make ( ) include [ % js : val make : id : string -> ? color : ThemeColor . t -> unit -> t [ @@ js . new " vscode . ThemeIcon " ] val file : t [ @@ js . global " vscode . ThemeIcon . File " ] val folder : t [ @@ js . global " vscode . ThemeIcon . Folder " ] val id : t -> string [ @@ js . get ] val color : t -> ThemeColor . t or_undefined [ @@ js . get ] ] end
module TreeItem = struct include Class . Make ( ) type label = ( [ ` String of string | ` TreeItemLabel of TreeItemLabel . t ] [ @ js . union ] ) [ @@ js ] let label_of_js js_val = if Ojs . type_of js_val = " string " then ` String ( [ % js . to : string ] js_val ) else if Ojs . has_property js_val " label " then ` TreeItemLabel ( [ % js . to : TreeItemLabel . t ] js_val ) else assert false module LightDarkIcon = struct type t = { light : ( [ ` String of string | ` Uri of Uri . t ] [ @ js . union ] ) ; dark : ( [ ` String of string | ` Uri of Uri . t ] [ @ js . union ] ) } [ @@ js ] let t_of_js js_val = let light_js = Ojs . get_prop_ascii js_val " light " in let dark_js = Ojs . get_prop_ascii js_val " dark " in let light = if Ojs . has_property light_js " parse " then ` Uri ( [ % js . to : Uri . t ] light_js ) else ` String ( [ % js . to : string ] light_js ) in let dark = if Ojs . has_property dark_js " parse " then ` Uri ( [ % js . to : Uri . t ] dark_js ) else ` String ( [ % js . to : string ] dark_js ) in { light ; dark } end type iconPath = ( [ ` String of string | ` Uri of Uri . t | ` LightDark of LightDarkIcon . t | ` ThemeIcon of ThemeIcon . t ] [ @ js . union ] ) [ @@ js ] let iconPath_of_js js_val = if Ojs . has_property js_val " path " then ` Uri ( [ % js . to : Uri . t ] js_val ) else if Ojs . has_property js_val " id " then ` ThemeIcon ( [ % js . to : ThemeIcon . t ] js_val ) else if Ojs . type_of js_val = " string " then ` String ( [ % js . to : string ] js_val ) else if Ojs . has_property js_val " light " then ` LightDark ( [ % js . to : LightDarkIcon . t ] js_val ) else assert false type description = ( [ ` String of string | ` Bool of bool ] [ @ js . union ] ) [ @@ js ] let description_of_js js_val = match Ojs . type_of js_val with | " boolean " -> ` Bool ( [ % js . to : bool ] js_val ) | " string " -> ` String ( [ % js . to : string ] js_val ) | _ -> assert false type tooltip = ( [ ` String of string | ` MarkdownString of MarkdownString . t | ` Undefined ] [ @ js . union ] ) [ @@ js ] let tooltip_of_js js_val = if Ojs . type_of js_val = " string " then ` String ( [ % js . to : string ] js_val ) else if Ojs . type_of js_val = " undefined " then ` Undefined else if Ojs . has_property js_val " value " then ` MarkdownString ( [ % js . to : MarkdownString . t ] js_val ) else assert false include [ % js : val make_label : label : label -> ? collapsibleState : TreeItemCollapsibleState . t -> unit -> t [ @@ js . new " vscode . TreeItem " ] val make_resource : resourceUri : Uri . t -> ? collapsibleState : TreeItemCollapsibleState . t -> unit -> t [ @@ js . new " vscode . TreeItem " ] val label : t -> label or_undefined [ @@ js . get ] val set_label : t -> label -> unit [ @@ js . set ] val id : t -> string or_undefined [ @@ js . get ] val set_id : t -> string -> unit [ @@ js . set ] val iconPath : t -> iconPath or_undefined [ @@ js . get ] val set_iconPath : t -> iconPath -> unit [ @@ js . set ] val description : t -> description or_undefined [ @@ js . get ] val set_description : t -> description -> unit [ @@ js . set ] val resourceUri : t -> Uri . t or_undefined [ @@ js . get ] val set_resourceUri : t -> Uri . t -> unit [ @@ js . set ] val tooltip : t -> tooltip or_undefined [ @@ js . get ] val set_tooltip : t -> tooltip -> unit [ @@ js . set ] val collapsibleState : t -> TreeItemCollapsibleState . t or_undefined [ @@ js . get ] val set_collapsibleState : t -> TreeItemCollapsibleState . t -> unit [ @@ js . set ] val command : t -> Command . t or_undefined [ @@ js . get ] val set_command : t -> Command . t -> unit [ @@ js . set ] val contextValue : t -> string or_undefined [ @@ js . get ] val set_contextValue : t -> string -> unit [ @@ js . set ] val accessibilityInformation : t -> AccessibilityInformation . t or_undefined [ @@ js . get ] val set_accessibilityInformation : t -> AccessibilityInformation . t -> unit [ @@ js . set ] ] end
module TreeDataProvider = struct include Interface . Generic ( Ojs ) ( ) module Make ( T : Js . T ) = struct type t = T . t generic [ @@ js ] module OnDidChangeTreeData = Event . Make ( struct type t = T . t or_undefined [ @@ js ] end ) type getTreeItemResult = ( [ ` Value of TreeItem . t | ` Promise of TreeItem . t Promise . t ] [ @ js . union ] ) [ @@ js ] let getTreeItemResult_of_js js_val = if Ojs . has_property js_val " then " then ` Promise ( [ % js . to : TreeItem . t Promise . t ] js_val ) else ` Value ( [ % js . to : TreeItem . t ] js_val ) include [ % js : val onDidChangeTreeData : t -> OnDidChangeTreeData . t or_undefined [ @@ js . get ] val getTreeItem : t -> element : T . t -> getTreeItemResult [ @@ js . call ] val getChildren : t -> ? element : T . t -> unit -> T . t list ProviderResult . t [ @@ js . call ] val getParent : t -> ( element : T . t -> T . t ProviderResult . t ) or_undefined [ @@ js . call ] val resolveTreeItem : t -> ( item : TreeItem . t -> element : T . t -> token : CancellationToken . t -> TreeItem . t ProviderResult . t ) or_undefined [ @@ js . call ] val create : ? onDidChangeTreeData : OnDidChangeTreeData . t -> getTreeItem ( : element : T . t -> getTreeItemResult ) -> getChildren ( :? element : T . t -> unit -> T . t list ProviderResult . t ) -> ? getParent ( : element : T . t -> T . t ProviderResult . t ) -> ? resolveTreeItem : ( item : TreeItem . t -> element : T . t -> token : CancellationToken . t -> TreeItem . t ProviderResult . t ) -> unit -> t [ @@ js . builder ] ] end end
module TreeViewOptions = struct include Class . Generic ( Ojs ) ( ) module Make ( T : Js . T ) = struct type t = T . t generic [ @@ js ] module TreeDataProvider = TreeDataProvider . Make ( T ) include [ % js : val treeDataProvider : t -> TreeDataProvider . t [ @@ js . get ] val showCollapseAll : t -> bool or_undefined [ @@ js . get ] val canSelectMany : t -> bool or_undefined [ @@ js . get ] ] end end
module TreeViewExpansionEvent = struct include Interface . Generic ( Ojs ) ( ) module Make ( T : Js . T ) = struct type t = T . t generic [ @@ js ] include [ % js : val element : t -> T . t [ @@ js . get ] val create : element : T . t -> t [ @@ js . builder ] ] end end
module TreeViewSelectionChangeEvent = struct include Interface . Generic ( Ojs ) ( ) module Make ( T : Js . T ) = struct type t = T . t generic [ @@ js ] include [ % js : val selection : t -> T . t list [ @@ js . get ] val create : selection : T . t list -> t [ @@ js . builder ] ] end end
module TreeViewVisibilityChangeEvent = struct include Interface . Make ( ) include [ % js : val visible : t -> bool [ @@ js . get ] val create : visible : bool -> t [ @@ js . builder ] ] end
module TreeView = struct include Class . Generic ( Disposable ) ( ) module Make ( T : Js . T ) = struct type t = T . t generic [ @@ js ] module OnDidExpandElement = Event . Make ( TreeViewExpansionEvent . Make ( T ) ) module OnDidCollapseElement = Event . Make ( TreeViewExpansionEvent . Make ( T ) ) module OnDidChangeSelection = Event . Make ( TreeViewSelectionChangeEvent . Make ( T ) ) module OnDidChangeVisibility = Event . Make ( TreeViewVisibilityChangeEvent ) include [ % js : val onDidExpandElement : t -> OnDidExpandElement . t [ @@ js . get ] val onDidCollapseElement : t -> OnDidCollapseElement . t [ @@ js . get ] val selection : t -> T . t list [ @@ js . get ] val onDidChangeSelection : t -> OnDidChangeSelection . t [ @@ js . get ] val visible : t -> bool [ @@ js . get ] val onDidChangeVisibility : t -> OnDidChangeVisibility . t [ @@ js . get ] val message : t -> string or_undefined [ @@ js . get ] val title : t -> string or_undefined [ @@ js . get ] val description : t -> string or_undefined [ @@ js . get ] val reveal : t -> element : T . t -> Ojs . t -> Promise . void [ @@ js . call ] ] let reveal this ~ element ? select ? focus ? expand ( ) = let options = Ojs . obj [ ] || in iter_set options " select " [ % js . of : bool ] select ; iter_set options " focus " [ % js . of : bool ] focus ; iter_set options " expand " [ % js . of : ( [ ` Bool of bool | ` Int of int ] [ @ js . union ] ) ] expand ; reveal this ~ element options end end
module WebviewPanelOptions = struct include Interface . Make ( ) include [ % js : val enableFindWidget : t -> bool or_undefined [ @@ js . get ] val retainContextWhenHidden : t -> bool or_undefined [ @@ js . get ] ] end
module WebviewPortMapping = struct include Interface . Make ( ) include [ % js : val extensionHostPort : t -> int [ @@ js . get ] val webviewPort : t -> int [ @@ js . get ] ] end
module WebviewOptions = struct include Interface . Make ( ) include [ % js : val enableCommandUris : t -> bool [ @@ js . get ] val enableScripts : t -> bool [ @@ js . get ] val set_enableScripts : t -> bool -> unit [ @@ js . set ] val localResourceRoots : t -> Uri . t list [ @@ js . get ] val portMapping : t -> WebviewPortMapping . t list [ @@ js . get ] val create : enableCommandUris : bool -> enableScripts : bool -> localResourceRoots : Uri . t list -> portMapping : WebviewPortMapping . t list -> t [ @@ js . builder ] ] end
module WebView = struct include Interface . Make ( ) module OnDidReceiveMessage = Event . Make ( Js . Any ) include [ % js : val onDidReceiveMessage : t -> OnDidReceiveMessage . t [ @@ js . get ] val cspSource : t -> string [ @@ js . get ] val html : t -> string [ @@ js . get ] val set_html : t -> string -> unit [ @@ js . set ] val options : t -> WebviewOptions . t [ @@ js . get ] val set_options : t -> WebviewOptions . t -> unit [ @@ js . set ] val asWebviewUri : t -> localResource : Uri . t -> Uri . t [ @@ js . call ] val postMessage : t -> Js . Any . t -> bool Promise . t [ @@ js . call ] val create : onDidReceiveMessage : OnDidReceiveMessage . t -> cspSource : string -> html : string -> options : WebviewOptions . t -> close ( : unit -> unit ) -> asWebviewUri ( : Uri . t -> Uri . t ) -> postMessage ( : Js . Any . t -> bool Promise . t ) -> t [ @@ js . builder ] ] end
module WebviewPanel = struct include Interface . Make ( ) module WebviewPanelOnDidChangeViewStateEvent = struct type webviewPanel = t [ @@ js ] include Interface . Make ( ) include [ % js : val webviewPanel : t -> webviewPanel [ @@ js . get ] ] end module LightDarkIcon = struct type t = { light : Uri . t ; dark : Uri . t } [ @@ js ] end type iconPath = ( [ ` Uri of Uri . t | ` LightDark of LightDarkIcon . t ] [ @ js . union ] ) [ @@ js ] module OnDidChangeViewState = Event . Make ( WebviewPanelOnDidChangeViewStateEvent ) module OnDidDispose = Event . Make ( Js . Unit ) include [ % js : val onDidChangeViewState : t -> OnDidChangeViewState . t [ @@ js . get ] val onDidDispose : t -> OnDidDispose . t [ @@ js . get ] val active : t -> bool [ @@ js . get ] val options : t -> WebviewPanelOptions . t [ @@ js . get ] val title : t -> string [ @@ js . get ] val viewColumn : t -> ViewColumn . t or_undefined [ @@ js . get ] val viewType : t -> string [ @@ js . get ] val visible : t -> bool [ @@ js . get ] val webview : t -> WebView . t [ @@ js . get ] val set_webview : t -> WebView . t -> unit [ @@ js . set ] val dispose : t -> Js . Any . t [ @@ js . call ] val reveal : t -> ? preserveFocus : bool -> ? viewColumn : ViewColumn . t -> unit -> unit [ @@ js . call ] val create : onDidChangeViewState : OnDidChangeViewState . t -> onDidDispose : OnDidDispose . t -> active : bool -> options : WebviewPanelOptions . t -> title : string -> viewColumn : ViewColumn . t -> viewType : string -> visible : bool -> webview : WebView . t -> dispose : Js . Any . t -> reveal : ( ? preserveFocus : bool -> ? viewColumn : ViewColumn . t -> unit -> unit ) -> t [ @@ js . builder ] ] end
module CustomTextEditorProvider = struct include Interface . Make ( ) module ResolvedEditor = struct type t = ( [ ` Promise of Promise . void | ` Unit of Js . Unit . t ] [ @ js . union ] ) [ @@ js ] let t_of_js js_val = if Ojs . is_null js_val then ` Unit ( [ % js . to : Js . Unit . t ] js_val ) else ` Promise ( [ % js . to : Promise . void ] js_val ) let t_to_js = function | ` Unit v -> Js . Unit . t_to_js v | ` Promise p -> Promise . void_to_js p end include [ % js : val resolveCustomTextEditor : t -> document : TextDocument . t -> webviewPanel : WebviewPanel . t -> token : CancellationToken . t -> ResolvedEditor . t [ @@ js . call ] val create : resolveCustomTextEditor : ( document : TextDocument . t -> webviewPanel : WebviewPanel . t -> token : CancellationToken . t -> ResolvedEditor . t ) -> t [ @@ js . builder ] ] end
module CustomDocumentOpenContext = struct include Interface . Make ( ) include [ % js : val backupId : t -> string or_undefined [ @@ js . get ] ] end
module CustomReadonlyEditorProvider = struct include Interface . Generic ( Ojs ) ( ) module Make ( T : CustomDocument . T ) = struct type t = T . t generic [ @@ js ] include [ % js : val openCustomDocument : t -> uri : Uri . t -> openContext : CustomDocumentOpenContext . t -> token : CancellationToken . t -> T . t Promise . t [ @@ js . call ] val resolveCustomEditor : t -> document : T . t -> webviewPanel : WebviewPanel . t -> token : CancellationToken . t -> unit Promise . t [ @@ js . call ] val create : resolveCustomEditor : ( document : T . t -> webviewPanel : WebviewPanel . t -> token : CancellationToken . t -> unit Promise . t ) -> openCustomDocument : ( uri : Uri . t -> openContext : CustomDocumentOpenContext . t -> token : CancellationToken . t -> T . t Promise . t ) -> t [ @@ js . builder ] ] end end
module RegisterCustomEditorProviderOptions = struct include Interface . Make ( ) include [ % js : val supportsMultipleEditorsPerDocument : t -> bool or_undefined [ @@ js . get ] val create : ? supportsMultipleEditorsPerDocument : bool -> unit -> t [ @@ js . builder ] ] end
module Window = struct module OnDidChangeActiveTextEditor = Event . Make ( TextEditor ) module OnDidChangeVisibleTextEditors = Event . Make ( Js . List ( TextEditor ) ) module OnDidChangeActiveTerminal = Event . Make ( Js . Or_undefined ( Terminal ) ) module OnDidOpenTerminal = Event . Make ( Terminal ) module OnDidCloseTerminal = Event . Make ( Terminal ) include [ % js : val activeTextEditor : unit -> TextEditor . t or_undefined [ @@ js . get " vscode . window . activeTextEditor " ] val visibleTextEditors : unit -> TextEditor . t list [ @@ js . get " vscode . window . visibleTextEditors " ] val onDidChangeActiveTextEditor : unit -> OnDidChangeActiveTextEditor . t [ @@ js . get " vscode . window . onDidChangeActiveTextEditor " ] val onDidChangeVisibleTextEditors : unit -> OnDidChangeVisibleTextEditors . t [ @@ js . get " vscode . window . onDidChangeVisibleTextEditors " ] val terminals : unit -> Terminal . t list [ @@ js . get " vscode . window . terminals " ] val activeTerminal : unit -> Terminal . t or_undefined [ @@ js . get " vscode . window . activeTerminal " ] val onDidChangeActiveTerminal : unit -> OnDidChangeActiveTerminal . t [ @@ js . get " vscode . window . onDidChangeActiveTerminal " ] val onDidOpenTerminal : unit -> OnDidOpenTerminal . t [ @@ js . get " vscode . window . onDidOpenTerminal " ] val onDidCloseTerminal : unit -> OnDidCloseTerminal . t [ @@ js . get " vscode . window . onDidCloseTerminal " ] val showTextDocument : document : ( [ ` TextDocument of TextDocument . t | ` Uri of Uri . t ] [ @ js . union ] ) -> ? column : ViewColumn . t -> ? preserveFocus : bool -> unit -> TextEditor . t Promise . t [ @@ js . global " vscode . window . showTextDocument " ] val showInformationMessage : message : string -> ? options : MessageOptions . t -> items ( : MessageItem . t list [ @ js . variadic ] ) -> unit -> MessageItem . t or_undefined Promise . t [ @@ js . global " vscode . window . showInformationMessage " ] val showWarningMessage : message : string -> ? options : MessageOptions . t -> items ( : MessageItem . t list [ @ js . variadic ] ) -> unit -> MessageItem . t or_undefined Promise . t [ @@ js . global " vscode . window . showWarningMessage " ] val showErrorMessage : message : string -> ? options : MessageOptions . t -> items ( : MessageItem . t list [ @ js . variadic ] ) -> unit -> MessageItem . t or_undefined Promise . t [ @@ js . global " vscode . window . showErrorMessage " ] val showQuickPickItems : choices : QuickPickItem . t list -> ? options : QuickPickOptions . t -> ? token : CancellationToken . t -> unit -> QuickPickItem . t or_undefined Promise . t [ @@ js . global " vscode . window . showQuickPick " ] val showQuickPick : items : string list -> ? options : QuickPickOptions . t -> ? token : CancellationToken . t -> unit -> string or_undefined Promise . t [ @@ js . global " vscode . window . showQuickPick " ] val showInputBox : ? options : InputBoxOptions . t -> ? token : CancellationToken . t -> unit -> string or_undefined Promise . t [ @@ js . global " vscode . window . showInputBox " ] val createOutputChannel : name : string -> OutputChannel . t [ @@ js . global " vscode . window . createOutputChannel " ] val setStatusBarMessage : text : string -> ? hide ( [ : ` AfterTimeout of int ] [ @ js . union ] ) -> unit -> Disposable . t [ @@ js . global " vscode . window . setStatusBarMessage " ] val withProgress : options : ProgressOptions . t -> task : Ojs . t -> Ojs . t [ @@ js . global " vscode . window . withProgress " ] val createStatusBarItem : ? alignment : StatusBarAlignment . t -> ? priority : int -> unit -> StatusBarItem . t [ @@ js . global " vscode . window . createStatusBarItem " ] val createTerminal : ? name : string -> ? shellPath : string -> ? shellArgs ( [ : ` String of string | ` Strings of string list ] [ @ js . union ] ) -> unit -> Terminal . t [ @@ js . global " vscode . window . createTerminal " ] val createTerminalFromOptions : options : ( [ ` TerminalOptions of TerminalOptions . t | ` ExtensionTerminalOptions of ExtensionTerminalOptions . t ] [ @ js . union ] ) -> Terminal . t [ @@ js . global " vscode . window . createTerminal " ] val registerTreeDataProvider : viewId : string -> treeDataProvider : Ojs . t -> Disposable . t [ @@ js . global " vscode . window . registerTreeDataProvider " ] val createTreeView : viewId : string -> options : Ojs . t -> Ojs . t [ @@ js . global " vscode . window . createTreeView " ] val createWebviewPanel : viewType : string -> title : string -> showOptions : ViewColumn . t -> WebviewPanel . t [ @@ js . global " vscode . window . createWebviewPanel " ] val registerCustomTextEditorProvider : viewType : string -> provider : CustomTextEditorProvider . t -> ? options : RegisterCustomEditorProviderOptions . t -> unit -> Disposable . t [ @@ js . global " vscode . window . registerCustomEditorProvider " ] val registerCustomReadonlyEditorProvider : viewType : string -> provider : Ojs . t -> ? options : RegisterCustomEditorProviderOptions . t -> unit -> Disposable . t [ @@ js . global " vscode . window . registerCustomEditorProvider " ] ] let getChoices choices = choices |> List . map ( fun ( title , choice ) -> ( MessageItem . create ~ title ( ) , choice ) ) let showInformationMessage ~ message ? options ( ? choices = [ ] ) ( ) = let choices = getChoices choices in let open Promise . Option . Syntax in let + item = showInformationMessage ~ message ? options ~ items ( : List . map fst choices ) ( ) in List . assoc item choices let showWarningMessage ~ message ? options ( ? choices = [ ] ) ( ) = let choices = getChoices choices in let open Promise . Option . Syntax in let + item = showWarningMessage ~ message ? options ~ items ( : List . map fst choices ) ( ) in List . assoc item choices let showErrorMessage ~ message ? options ( ? choices = [ ] ) ( ) = let choices = getChoices choices in let open Promise . Option . Syntax in let + item = showErrorMessage ~ message ? options ~ items ( : List . map fst choices ) ( ) in List . assoc item choices let showQuickPickItems ~ choices ? options ? token ( ) = let open Promise . Option . Syntax in let + item = showQuickPickItems ~ choices ( : List . map fst choices ) ? options ? token ( ) in List . assoc item choices let withProgress ( type a ) ( module T : Js . T with type t = a ) ~ options ~ task : a Promise . t = let task = [ % js . of : progress : Progress . t -> token : CancellationToken . t -> T . t Promise . t ] task in [ % js . to : T . t Promise . t ] ( withProgress ~ options ~ task ) let registerTreeDataProvider ( type a ) ( module T : Js . T with type t = a ) ( ~ viewId : string ) ( ~ treeDataProvider : a TreeDataProvider . t ) : Disposable . t = let module TreeDataProvider = TreeDataProvider . Make ( T ) in let treeDataProvider = [ % js . of : TreeDataProvider . t ] treeDataProvider in registerTreeDataProvider ~ viewId ~ treeDataProvider let createTreeView ( type a ) ( module T : Js . T with type t = a ) ( ~ viewId : string ) ( ~ options : a TreeViewOptions . t ) : a TreeView . t = let module TreeViewOptions = TreeViewOptions . Make ( T ) in let module TreeView = TreeView . Make ( T ) in let options = [ % js . of : TreeViewOptions . t ] options in [ % js . to : TreeView . t ] ( createTreeView ~ viewId ~ options ) let registerCustomReadonlyEditorProvider ( type a ) ( module T : CustomDocument . T with type t = a ) ( ~ viewType : string ) ( ~ provider : a CustomReadonlyEditorProvider . t ) ( ? options : RegisterCustomEditorProviderOptions . t or_undefined ) ( ) : Disposable . t = let module CustomReadonlyEditorProvider = CustomReadonlyEditorProvider . Make ( T ) in let provider = [ % js . of : CustomReadonlyEditorProvider . t ] provider in registerCustomReadonlyEditorProvider ~ viewType ~ provider ? options ( ) end
module Commands = struct include [ % js : val registerCommand : command : string -> callback ( : args ( : Js . Any . t list [ @ js . variadic ] ) -> unit ) -> Disposable . t [ @@ js . global " vscode . commands . registerCommand " ] val registerTextEditorCommand : command : string -> callback : ( textEditor : TextEditor . t -> edit : TextEditorEdit . t -> args ( : Js . Any . t list [ @ js . variadic ] ) -> unit ) -> Disposable . t [ @@ js . global " vscode . commands . registerTextEditorCommand " ] val executeCommand : command : string -> args ( : Js . Any . t list [ @ js . variadic ] ) -> Js . Any . t or_undefined Promise . t [ @@ js . global " vscode . commands . executeCommand " ] val getCommands : ? filterInternal : bool -> unit -> string list Promise . t [ @@ js . global " vscode . commands . getCommands " ] ] end
module Languages = struct include [ % js : val registerDocumentFormattingEditProvider : selector : DocumentSelector . t -> provider : DocumentFormattingEditProvider . t -> Disposable . t [ @@ js . global " vscode . languages . registerDocumentFormattingEditProvider " ] val registerHoverProvider : selector : DocumentSelector . t -> provider : HoverProvider . t -> Disposable . t [ @@ js . global " vscode . languages . registerHoverProvider " ] val getDiagnostics : Uri . t -> Diagnostic . t list [ @@ js . global " vscode . languages . getDiagnostics " ] val getDiagnostics_all : unit -> ( Uri . t * Diagnostic . t list ) list [ @@ js . global " vscode . languages . getDiagnostics " ] ] end
module Tasks = struct include [ % js : val registerTaskProvider : type_ : string -> provider : TaskProvider . Default . t -> Disposable . t [ @@ js . global " vscode . tasks . registerTaskProvider " ] ] end
module Env = struct include [ % js : val shell : unit -> string [ @@ js . get " vscode . env . shell " ] ] end
module RevealOutputChannelOn = struct type t = | Info [ @ js 1 ] | Warn [ @ js 2 ] | Error [ @ js 3 ] | Never [ @ js 4 ] [ @@ js . enum ] [ @@ js ] end
module ServerCapabilities = struct include Interface . Make ( ) include [ % js : val experimental : t -> Jsonoo . t or_undefined [ @@ js . get ] val create : ? experimental : Jsonoo . t -> unit -> t [ @@ js . builder ] ] end
module InitializeResult = struct include Interface . Make ( ) type serverInfo = { name : string ; version : string or_undefined } [ @@ js ] include [ % js : val capabilities : t -> ServerCapabilities . t [ @@ js . get ] val serverInfo : t -> serverInfo or_undefined [ @@ js . get ] ] end
module DocumentFilter = struct include Interface . Make ( ) include [ % js : val language : t -> string or_undefined [ @@ js . get ] val scheme : t -> string or_undefined [ @@ js . get ] val pattern : t -> string or_undefined [ @@ js . get ] val createLanguage : language : string -> ? scheme : string -> ? pattern : string -> unit -> t [ @@ js . builder ] val createScheme : ? language : string -> scheme : string -> ? pattern : string -> unit -> t [ @@ js . builder ] val createPattern : ? language : string -> ? scheme : string -> pattern : string -> unit -> t [ @@ js . builder ] ] end
module DocumentSelector = struct type selector = ( [ ` Filter of DocumentFilter . t | ` String of string ] [ @ js . union ] ) [ @@ js ] let selector_of_js js_val = match Ojs . type_of js_val with | " string " -> ` String ( [ % js . to : string ] js_val ) | _ -> ` Filter ( [ % js . to : DocumentFilter . t ] js_val ) type t = selector array [ @@ js ] let language ( ? scheme = " file " ) ? pattern l = ` Filter ( DocumentFilter . createLanguage ~ language : l ~ scheme ? pattern ( ) ) end
module ClientOptions = struct include Interface . Make ( ) include [ % js : val documentSelector : t -> DocumentSelector . t or_undefined [ @@ js . get ] val outputChannel : t -> Vscode . OutputChannel . t or_undefined [ @@ js . get ] val revealOutputChannelOn : t -> RevealOutputChannelOn . t [ @@ js . get ] val create : ? documentSelector : DocumentSelector . t -> ? outputChannel : Vscode . OutputChannel . t -> ? revealOutputChannelOn : RevealOutputChannelOn . t -> unit -> t [ @@ js . builder ] ] end
module ExecutableOptions = struct include Interface . Make ( ) include [ % js : val cwd : t -> string or_undefined [ @@ js . get ] val env : t -> string Dict . t or_undefined [ @@ js . get ] val detached : t -> bool or_undefined [ @@ js . get ] val shell : t -> bool or_undefined [ @@ js . get ] val create : ? cwd : string -> ? env : string Dict . t -> ? detached : bool -> ? shell : bool -> unit -> t [ @@ js . builder ] ] end
module Executable = struct include Interface . Make ( ) include [ % js : val command : t -> string [ @@ js . get ] val args : t -> string list or_undefined [ @@ js . get ] val options : t -> ExecutableOptions . t or_undefined [ @@ js . get ] val create : command : string -> ? args : string list -> ? options : ExecutableOptions . t -> unit -> t [ @@ js . builder ] ] end
module ClientCapabilities = struct include Interface . Make ( ) include [ % js : val experimental : t -> Jsonoo . t or_undefined [ @@ js . get ] val set_experimental : t -> Jsonoo . t or_undefined -> unit [ @@ js . set ] ] end
module InitializeParams = struct include Interface . Make ( ) end
module StaticFeature = struct include Interface . Make ( ) include [ % js : val make : ? fillInitializeParams ( : params : InitializeParams . t -> unit ) -> fillClientCapabilities ( : capabilities : ClientCapabilities . t -> unit ) -> initialize : ( capabilities : ServerCapabilities . t -> documentSelector : DocumentSelector . t or_undefined -> unit ) -> dispose ( : unit -> unit ) -> unit -> t [ @@ js . builder ] ] end
module LanguageClient = struct include Class . Make ( ) include [ % js : val make : id : string -> name : string -> serverOptions : ServerOptions . t -> clientOptions : ClientOptions . t -> ? forceDebug : bool -> unit -> t [ @@ js . new " vscode_languageclient . LanguageClient " ] val start : t -> unit [ @@ js . call ] val stop : t -> unit [ @@ js . call ] val onReady : t -> Promise . void [ @@ js . call ] val initializeResult : t -> InitializeResult . t [ @@ js . get ] val sendRequest : t -> meth : string -> data : Jsonoo . t -> ? token : Vscode . CancellationToken . t -> unit -> Jsonoo . t Promise . t [ @@ js . call ] val registerFeature : t -> feature : StaticFeature . t -> unit [ @@ js . call ] ] let ready_initialize_result t = let open Promise . Syntax in let + ( ) = onReady t in initializeResult t end
let suggest_to_pick_sandbox ( ) = let open Promise . Syntax in let select_pm_button_text = " Select package manager and sandbox " in let + selection = Window . showInformationMessage ~ message : " OCaml Platform is using the package manager and sandbox available in \ the environment . Pick a particular package manager and sandbox by \ clicking the button below " ~ choices [ : ( select_pm_button_text , ( ) ) ] ( ) in Option . iter selection ~ f ( : fun ( ) -> let ( _ : Ojs . t option Promise . t ) = Vscode . Commands . executeCommand ~ command : Extension_consts . Commands . select_sandbox ~ args [ ] : in ( ) )
let activate ( extension : ExtensionContext . t ) = Process . Env . set " OCAML_LSP_SERVER_LOG " " " ; - let open Promise . Syntax in let instance = Extension_instance . make ( ) in ExtensionContext . subscribe extension ~ disposable ( : Extension_instance . disposable instance ) ; Dune_formatter . register extension instance ; Dune_task_provider . register extension instance ; Extension_commands . register_all_commands extension instance ; Treeview_switches . register extension instance ; Treeview_sandbox . register extension instance ; Treeview_commands . register extension ; Treeview_help . register extension ; Ast_editor . register extension instance ; Cm_editor . register extension instance ; Repl . register extension instance ; let sandbox_opt = Sandbox . of_settings_or_detect ( ) in let ( _ : unit Promise . t ) = let * sandbox_opt in let is_fallback = Option . is_none sandbox_opt in if is_fallback then suggest_to_pick_sandbox ( ) else Promise . return ( ) in let ( _ : unit Promise . t ) = let * sandbox_opt in let sandbox = Option . value sandbox_opt ~ default : Sandbox . Global in Extension_instance . set_sandbox instance sandbox ; let * ( ) = Extension_instance . update_ocaml_info instance in let + ( ) = Extension_instance . start_language_server instance in ( ) in Promise . return ( )
let ( ) = let open Js_of_ocaml . Js in export " activate " ( wrap_callback activate )
module T = Uterm open struct let get_id_of_lb_arg = function | Uast . Lunit -> assert false | Uast . Lnone id | Loptional id | Lnamed id | Lghost ( id , _ ) -> id end let loc_of_lb_arg = function | Uast . Lunit -> T . dummy_loc | lb -> T . location ( get_id_of_lb_arg lb ) . pid_loc let ident_of_lb_arg = function | Uast . Lunit -> T . mk_id " ( ) " | lb -> T . preid ( get_id_of_lb_arg lb ) end
let sp_post sp_hd_ret sp_post = let term_loc = T . location sp_post . Uast . term_loc in let mk_pvar lb = let pat_loc = loc_of_lb_arg lb in T . mk_pattern ( Pvar ( ident_of_lb_arg lb ) ) ~ pat_loc in let pvar_of_lb_arg_list lb_arg_list = List . map mk_pvar lb_arg_list in let pat = match pvar_of_lb_arg_list sp_hd_ret with | [ p ] -> p | pl -> T . mk_pattern ( Ptuple pl ) ~ pat_loc : term_loc in ( term_loc , [ ( pat , T . term true sp_post ) ] )
let sp_post_no_ret sp_post = let term_loc = T . location sp_post . Uast . term_loc in let id_result = T . mk_id " result " in ( term_loc , [ ( T . mk_pattern ( Pvar id_result ) , T . term true sp_post ) ] )
let sp_xpost ( loc , q_pat_t_option_list ) = let loc = T . location loc in let pat_term ( q , t ) = ( T . pattern q , T . term true t ) in let qualid_pat_term_opt ( q , pt_opt ) = ( T . qualid q , Opt . map pat_term pt_opt ) in ( loc , List . map qualid_pat_term_opt q_pat_t_option_list )
let empty_spec = { sp_pre = [ ] ; sp_post = [ ] ; sp_xpost = [ ] ; sp_reads = [ ] ; sp_writes = [ ] ; sp_alias = [ ] ; sp_variant = [ ] ; sp_checkrw = false ; sp_diverge = false ; sp_partial = false ; }
let vspec spec = let sp_writes = List . map ( T . term false ) spec . Uast . sp_writes in let sp_checkrw = match sp_writes with [ ] -> false | _ -> true in let sp_post = match spec . Uast . sp_header with | None -> List . map sp_post_no_ret spec . sp_post | Some hd -> List . map ( sp_post hd . sp_hd_ret ) spec . sp_post in { sp_pre = List . map ( T . term false ) spec . Uast . sp_pre ; sp_post ; sp_xpost = List . map sp_xpost spec . sp_xpost ; sp_reads = [ ] ; sp_writes ; sp_alias = [ ] ; sp_variant = List . map ( fun t -> ( T . term false t , None ) ) spec . sp_variant ; sp_checkrw ; sp_diverge = spec . sp_diverge ; sp_partial = false ; }
let fun_spec spec = { sp_pre = List . map ( T . term false ) spec . Uast . fun_req ; sp_post = List . map sp_post_no_ret spec . fun_ens ; sp_xpost = [ ] ; sp_reads = [ ] ; sp_writes = [ ] ; sp_alias = [ ] ; sp_variant = List . map ( fun t -> ( T . term false t , None ) ) spec . fun_variant ; sp_checkrw = false ; sp_diverge = false ; sp_partial = false ; }
let spec_union s1 s2 = { sp_pre = s1 . sp_pre @ s2 . sp_pre ; sp_post = s1 . sp_post @ s2 . sp_post ; sp_xpost = s1 . sp_xpost @ s2 . sp_xpost ; sp_reads = s1 . sp_reads @ s2 . sp_reads ; sp_writes = s1 . sp_writes @ s2 . sp_writes ; sp_alias = s1 . sp_alias @ s2 . sp_alias ; sp_variant = s1 . sp_variant @ s2 . sp_variant ; sp_checkrw = s1 . sp_checkrw || s2 . sp_checkrw ; sp_diverge = s1 . sp_diverge || s2 . sp_diverge ; sp_partial = s1 . sp_partial || s2 . sp_partial ; }
let add_word ? custom name dict = let open L in { dict with words = Dict . add name ? custom dict . words }
let add role ? custom name dict = let open L in { dict with words = Dict . add name ? custom dict . words ; roles = R . add ( String . lowercase_ascii name ) role dict . roles ; }
let add_ext x exts = S . add ( String . lowercase_ascii x ) exts
let vendor_tag ( dict , out ) ( x : Structured_spec . short_tag ) = ( add Extension x . name dict , add_ext x . name out )
let empty = let open L in { words = Dict . empty ; roles = R . empty ; context = { mu with prefix = [ " vk " ] } }
let add_post x dict = L . { dict with roles = R . add x Postfix dict . roles }
let add_pre x dict = L . { dict with roles = R . add x Prefix dict . roles }
let make spec = let dict , exts = List . fold_left vendor_tag ( empty , S . empty ) spec . Structured_spec . tags in dict |> add Main " RandR " |> add Main " RR " |> add Main " DirectFB " |> add Main " FB " |> add Main " D3D12 " |> add Main " MacOS " |> add Main " LOD " |> add Main " ID " |> add Extension " EXT " |> add Extension " KHX " |> add Main " IOS " |> add Main " 1D " |> add Main " 2D " |> add Main " 3D " |> add Main " 1d " |> add Main " 2d " |> add Main " 3d " |> add Main " 16Bit " |> add Main " 8Bit " |> add Main " UUID " |> add_word " AABB " |> add_word " CAMetalLayer " |> add_word " SM " |> add_word ~ custom [ " : vulkan " ; " 1 " ; " 1 " ] " Vulkan11 " |> add_word ~ custom [ " : vulkan " ; " 1 " ; " 2 " ] " Vulkan12 " |> add Main " ASTC " |> add Main " HDR " |> add_word " PCI " |> add_word " Win32 " |> add_post " flags " |> add_post " flag " |> add_post " bits " |> add_post " bit " |> add_pre " vk " , exts |> add_ext " KHX " |> add_ext " EXT "
object method msg : Js . js_string Js . t Js . readonly_prop method indicator : Js . js_string Js . t Js . readonly_prop method file : Js . js_string Js . t Js . readonly_prop method line : int Js . readonly_prop method col : int Js . readonly_prop end object method code : Js . js_string Js . t Js . optdef_prop method file : Js . js_string Js . t Js . optdef_prop end object method version : bool Js . optdef_prop method dparse : bool Js . optdef_prop method deps : bool Js . optdef_prop method check : bool Js . optdef_prop method eval : bool Js . optdef_prop method code : Js . js_string Js . t Js . optdef_prop method output : Js . js_string Js . t Js . optdef_prop method real : Js . js_string Js . t Js . optdef_prop method template : Js . js_string Js . t Js . optdef_prop method includes : Js . js_string Js . t Js . js_array Js . t Js . optdef_prop method files : js_file_code Js . t Js . js_array Js . t Js . optdef_prop end object method output : Js . js_string Js . t Js . optdef_prop method real : Js . js_string Js . t Js . optdef_prop method template : Js . js_string Js . t Js . optdef_prop method includes : Js . js_string Js . t Js . js_array Js . t Js . optdef_prop end
let new_object ( ) = Js . Unsafe . coerce ( object % js end )
let convertOutputErrors errors = let makeErrorObject error : error Js . t = let msg , indicator , file , line , col = Error . reportErrorStringNoLoc error in object % js val msg = Js . string msg val indicator = Js . string indicator val file = Js . string file val line = line val col = col end in List . map makeErrorObject errors |> Array . of_list |> Js . array
let convertInputFile ( i : js_file_code Js . t ) : input list = match Js . Optdef . to_option i . ## file , Js . Optdef . to_option i . ## code with | Some file , Some code -> [ Code ( Js . to_string file , Js . to_string code ) ] | Some file , None -> [ File ( Js . to_string file ) ] | None , Some code -> [ Code ( " live . vult " , Js . to_string code ) ] | None , None -> [ ]
let convertInputFiles ( files : js_file_code Js . t Js . js_array Js . t ) : input list = Js . to_array files |> Array . map convertInputFile |> Array . to_list |> List . flatten
let getFile ( args : args ) ( ext : FileKind . t ) : string = match ext with | FileKind . ExtOnly e -> args . output ^ " . " ^ e | FileKind . FullName n -> Filename . concat ( Filename . dirname args . output ) n
let convertOutputFile ( file : string ) ( code : string ) : js_file_code Js . t = let obj = new_object ( ) in obj . ## file := Js . string file ; obj . ## code := Js . string code ; obj
let convertOutputFiles args files = List . map ( fun ( text , file ) -> convertOutputFile ( getFile args file ) ( Pla . print text ) ) files |> Array . of_list |> Js . array
let set value fset = if Js . Optdef . test value then Js . Optdef . iter value ( fun a -> fset a )
let convertCodeName code = match code with | " c " -> CCode | " js " -> JSCode | " lua " -> LuaCode | _ -> failwith ( Printf . sprintf " unknow code generator ' % s ' " code )
let getArguments ( obj : js_args Js . t ) = let args = { default_arguments with files = [ ] } in set obj . ## dparse ( fun v -> args . dparse <- v ) ; set obj . ## deps ( fun v -> args . deps <- v ) ; set obj . ## check ( fun v -> args . check <- v ) ; set obj . ## eval ( fun v -> args . eval <- v ) ; set obj . ## version ( fun v -> args . show_version <- v ) ; set obj . ## code ( fun v -> args . code <- convertCodeName ( Js . to_string v ) ) ; set obj . ## output ( fun v -> args . output <- Js . to_string v ) ; set obj . ## real ( fun v -> args . real <- Js . to_string v ) ; set obj . ## template ( fun v -> args . template <- Js . to_string v ) ; set obj . ## includes ( fun v -> args . includes <- Js . to_array v |> Array . map Js . to_string |> Array . to_list ) ; set obj . ## files ( fun v -> args . files <- convertInputFiles v ) ; args
let applyOptions ( options : options Js . t ) ( args : args ) = set options . ## output ( fun v -> args . output <- Js . to_string v ) ; set options . ## real ( fun v -> args . real <- Js . to_string v ) ; set options . ## template ( fun v -> args . template <- Js . to_string v ) ; set options . ## includes ( fun v -> args . includes <- Js . to_array v |> Array . map Js . to_string |> Array . to_list )
let showResult ( args : args ) ( output : output ) : ' a Js . t = match output with | Version v -> let obj = new_object ( ) in obj . ## version := Js . string v ; obj | Message v -> let obj = new_object ( ) in obj . ## message := Js . string v ; obj | Dependencies deps -> let obj = new_object ( ) in obj . ## dependencies := Js . array ( List . map Js . string deps |> Array . of_list ) ; obj | ParsedCode v -> let obj = new_object ( ) in obj . ## parsedCode := Js . string v ; obj | GeneratedCode files -> let obj = new_object ( ) in obj . ## generatedCode := convertOutputFiles args files ; obj | Interpret v -> let obj = new_object ( ) in obj . ## interpret := Js . string v ; obj | CheckOk -> let obj = new_object ( ) in obj . ## check := Js . bool true ; obj | Errors errors -> let obj = new_object ( ) in obj . ## errors := convertOutputErrors errors ; obj
let showResults ( args : args ) ( results : output list ) = results |> List . map ( showResult args ) |> Array . of_list |> Js . array
let main ( input : js_args Js . t ) = let args = getArguments input in Driver . main args |> showResults args
let version = let args = { default_arguments with show_version = true } in match Driver . main args with | [ Version v ] -> Js . string v | _ -> failwith " unknown error "
let codeGeneration args results = match results with | GeneratedCode files :: _ -> convertOutputFiles args files |> Js . Unsafe . coerce | Errors errors :: _ -> convertOutputErrors errors |> Js . Unsafe . coerce | _ -> failwith " unknown error "
let generateJs ( files : js_file_code Js . t Js . js_array Js . t ) ( options : ' a Js . t ) = let args = { default_arguments with code = JSCode ; files = convertInputFiles files } in let ( ) = applyOptions options args in let results = Driver . main args in codeGeneration args results
let generateC ( files : js_file_code Js . t Js . js_array Js . t ) ( options : ' a Js . t ) = let args = { default_arguments with code = CCode ; files = convertInputFiles files } in let ( ) = applyOptions options args in let results = Driver . main args in codeGeneration args results
let generateLua ( files : js_file_code Js . t Js . js_array Js . t ) ( options : ' a Js . t ) = let args = { default_arguments with code = LuaCode ; files = convertInputFiles files } in let ( ) = applyOptions options args in let results = Driver . main args in codeGeneration args results
let _ = Js . export_all ( object % js method main = main method version = version method generateJs = generateJs method generateC = generateC method generateLua = generateLua end )
let generateJSCode s = let args = { default_arguments with code = JSCode ; real = " js " ; template = " browser " ; files = [ Code ( " live . vult " , Js . to_string s ) ] } in match Driver . main args with | [ GeneratedCode [ ( code , _ ) ] ] -> Js . string ( Pla . print code ) | [ Errors errors ] -> let error_strings = List . map ( fun error -> let msg , indicator , _ , _ , _ = Error . reportErrorStringNoLoc error in msg ^ " \ n " ^ indicator ) errors |> String . concat " \ n " in Js . string ( " Errors in the program :\ n " ^ error_strings ) | _ -> Js . string " unknown error "
let makeAceError ( e : Error . t ) = let msg , indicator , _ , line , col = Error . reportErrorStringNoLoc e in Js . Unsafe . obj [ | " text " , Js . Unsafe . inject ( Js . string ( msg ^ " \ n " ^ indicator ) ) ; " row " , Js . Unsafe . inject ( Js . string ( string_of_int ( line - 1 ) ) ) ; " column " , Js . Unsafe . inject ( Js . string ( string_of_int ( col - 1 ) ) ) ; " type " , Js . Unsafe . inject ( Js . string " error " ) ; " raw " , Js . Unsafe . inject ( Js . string msg ) ] |
let checkCode s = let args = { default_arguments with check = true ; files = [ Code ( " live . vult " , Js . to_string s ) ] } in match Driver . main args with | [ Errors errors ] -> let error_objects = List . map makeAceError errors in error_objects |> Array . of_list |> Js . array | _ -> Js . array [ ] ||