Apply Ocamlvalue derive to oxidized aast related types
[hiphop-php.git] / hphp / hack / src / utils / lsp / lsp.mli
blobd1c38fcb98732305a6353c96c37cf3c365bfe1dc
1 (*
2 * Copyright (c) 2019, Facebook, Inc.
3 * All rights reserved.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
8 *)
10 type lsp_id = NumberId of int | StringId of string
11 type documentUri = string
12 type position = { line : int; character : int; }
13 type range = { start : position; end_ : position; }
14 module Location : sig type t = { uri : documentUri; range : range; } end
15 module DefinitionLocation :
16 sig type t = { location : Location.t; title : string option; } end
17 type markedString = MarkedString of string | MarkedCode of string * string
18 module Command : sig
19 type t = {
20 title: string; (* title of the command, like `save` *)
21 command: string; (* the identifier of the actual command handler *)
22 arguments: Hh_json.json list; (* wire: it can be omitted *)
24 end
25 module TextEdit : sig type t = { range : range; newText : string; } end
26 module TextDocumentIdentifier : sig type t = { uri : documentUri; } end
27 module VersionedTextDocumentIdentifier :
28 sig type t = { uri : documentUri; version : int; } end
29 module TextDocumentEdit :
30 sig
31 type t = {
32 textDocument : VersionedTextDocumentIdentifier.t;
33 edits : TextEdit.t list;
35 end
36 module WorkspaceEdit :
37 sig
38 type t = {
39 changes: TextEdit.t list SMap.t; (* holds changes to existing docs *)
41 end
42 module TextDocumentItem :
43 sig
44 type t = {
45 uri : documentUri;
46 languageId : string;
47 version : int;
48 text : string;
50 end
51 module CodeLens :
52 sig
53 type t = {
54 range : range;
55 command : Command.t;
56 data : Hh_json.json option;
58 end
59 module TextDocumentPositionParams :
60 sig
61 type t = {
62 textDocument : TextDocumentIdentifier.t;
63 position : position;
65 end
66 module DocumentFilter :
67 sig
68 type t = {
69 language : string option;
70 scheme : string option;
71 pattern : string option;
73 end
74 module DocumentSelector : sig type t = DocumentFilter.t list end
75 module SymbolInformation :
76 sig
77 type t = {
78 name : string;
79 kind : symbolKind;
80 location : Location.t;
81 containerName : string option;
83 and symbolKind =
84 File
85 | Module
86 | Namespace
87 | Package
88 | Class
89 | Method
90 | Property
91 | Field
92 | Constructor
93 | Enum
94 | Interface
95 | Function
96 | Variable
97 | Constant
98 | String
99 | Number
100 | Boolean
101 | Array
103 module MessageType :
104 sig type t = ErrorMessage | WarningMessage | InfoMessage | LogMessage end
105 module CancelRequest :
106 sig type params = cancelParams and cancelParams = { id : lsp_id; } end
107 module CodeActionKind :
109 type t = (string * string list)
110 val is_kind : t -> t -> bool
111 val contains_kind : t -> t list -> bool
112 val contains_kind_opt : default:bool -> t -> t list option -> bool
113 val kind_of_string : string -> t
114 val string_of_kind : t -> string
115 val sub_kind : t -> string -> t
116 val quickfix : t
117 val source : t
119 module Initialize :
121 type params = {
122 processId : int option;
123 rootPath : string option;
124 rootUri : documentUri option;
125 initializationOptions : initializationOptions;
126 client_capabilities : client_capabilities;
127 trace : trace;
129 and result = { server_capabilities : server_capabilities; }
130 and errorData = { retry : bool; }
131 and trace = Off | Messages | Verbose
132 and initializationOptions = {
133 useTextEditAutocomplete : bool;
134 liveSyntaxErrors : bool;
135 namingTableSavedStatePath : string option;
136 sendServerStatusEvents : bool;
138 and client_capabilities = {
139 workspace : workspaceClientCapabilities;
140 textDocument : textDocumentClientCapabilities;
141 window : windowClientCapabilities;
142 telemetry : telemetryClientCapabilities;
144 and workspaceClientCapabilities = {
145 applyEdit : bool;
146 workspaceEdit : workspaceEdit;
147 didChangeWatchedFiles : dynamicRegistration;
149 and dynamicRegistration = {
150 dynamicRegistration : bool;
152 and workspaceEdit = { documentChanges : bool; }
153 and textDocumentClientCapabilities = {
154 synchronization : synchronization;
155 completion : completion;
156 codeAction : codeAction;
158 and synchronization = {
159 can_willSave : bool;
160 can_willSaveWaitUntil : bool;
161 can_didSave : bool;
163 and completion = { completionItem : completionItem; }
164 and completionItem = { snippetSupport : bool; }
165 and codeAction = {
166 codeAction_dynamicRegistration : bool;
167 codeActionLiteralSupport : codeActionliteralSupport option; }
168 and codeActionliteralSupport = { codeAction_valueSet: CodeActionKind.t list}
169 and windowClientCapabilities = {
170 status : bool;
171 progress : bool;
172 actionRequired : bool;
174 and telemetryClientCapabilities = { connectionStatus : bool; }
175 and server_capabilities = {
176 textDocumentSync : textDocumentSyncOptions;
177 hoverProvider : bool;
178 completionProvider : completionOptions option;
179 signatureHelpProvider : signatureHelpOptions option;
180 definitionProvider : bool;
181 typeDefinitionProvider: bool;
182 referencesProvider : bool;
183 documentHighlightProvider : bool;
184 documentSymbolProvider : bool;
185 workspaceSymbolProvider : bool;
186 codeActionProvider : bool;
187 codeLensProvider : codeLensOptions option;
188 documentFormattingProvider : bool;
189 documentRangeFormattingProvider : bool;
190 documentOnTypeFormattingProvider :
191 documentOnTypeFormattingOptions option;
192 renameProvider : bool;
193 documentLinkProvider : documentLinkOptions option;
194 executeCommandProvider : executeCommandOptions option;
195 typeCoverageProvider : bool;
196 rageProvider : bool;
198 and completionOptions = {
199 resolveProvider : bool;
200 completion_triggerCharacters : string list;
202 and signatureHelpOptions = { sighelp_triggerCharacters : string list; }
203 and codeLensOptions = { codelens_resolveProvider : bool; }
204 and documentOnTypeFormattingOptions = {
205 firstTriggerCharacter : string;
206 moreTriggerCharacter : string list;
208 and documentLinkOptions = { doclink_resolveProvider : bool; }
209 and executeCommandOptions = { commands : string list; }
210 and textDocumentSyncOptions = {
211 want_openClose : bool;
212 want_change : textDocumentSyncKind;
213 want_willSave : bool;
214 want_willSaveWaitUntil : bool;
215 want_didSave : saveOptions option;
217 and textDocumentSyncKind = NoSync | FullSync | IncrementalSync
218 and saveOptions = { includeText : bool; }
220 module Shutdown : sig end
221 module Exit : sig end
222 module Rage :
224 type result = rageItem list
225 and rageItem = { title : string option; data : string; }
227 module CodeLensResolve :
229 type params = CodeLens.t
230 and result = CodeLens.t
232 module Hover :
234 type params = TextDocumentPositionParams.t
235 and result = hoverResult option
236 and hoverResult = {
237 contents : markedString list;
238 range : range option;
241 module PublishDiagnostics :
243 type diagnosticCode = IntCode of int | StringCode of string | NoCode
244 type diagnosticSeverity = Error | Warning | Information | Hint
245 val min_diagnosticSeverity : int
246 val max_diagnosticSeverity : int
247 val diagnosticSeverity_to_enum : diagnosticSeverity -> int
248 val diagnosticSeverity_of_enum : int -> diagnosticSeverity option
249 type params = publishDiagnosticsParams
250 and publishDiagnosticsParams = {
251 uri : documentUri;
252 diagnostics : diagnostic list;
254 and diagnostic = {
255 range : range;
256 severity : diagnosticSeverity option;
257 code : diagnosticCode;
258 source : string option;
259 message : string;
260 relatedInformation : diagnosticRelatedInformation list;
261 relatedLocations : relatedLocation list;
263 and diagnosticRelatedInformation = {
264 relatedLocation : Location.t;
265 relatedMessage : string;
267 and relatedLocation = diagnosticRelatedInformation
269 module DidOpen :
271 type params = didOpenTextDocumentParams
272 and didOpenTextDocumentParams = { textDocument : TextDocumentItem.t; }
274 module DidClose :
276 type params = didCloseTextDocumentParams
277 and didCloseTextDocumentParams = {
278 textDocument : TextDocumentIdentifier.t;
281 module DidSave :
283 type params = didSaveTextDocumentParams
284 and didSaveTextDocumentParams = {
285 textDocument : TextDocumentIdentifier.t;
286 text : string option;
289 module DidChange :
291 type params = didChangeTextDocumentParams
292 and didChangeTextDocumentParams = {
293 textDocument : VersionedTextDocumentIdentifier.t;
294 contentChanges : textDocumentContentChangeEvent list;
296 and textDocumentContentChangeEvent = {
297 range : range option;
298 rangeLength : int option;
299 text : string;
302 module DidChangeWatchedFiles :
304 type registerOptions = {
305 watchers: fileSystemWatcher list;
307 and fileSystemWatcher = {
308 globPattern: string;
310 type fileChangeType =
311 | Created
312 | Updated
313 | Deleted
314 [@@deriving enum]
315 type params = {
316 changes: fileEvent list;
318 and fileEvent = {
319 uri: documentUri;
320 type_: fileChangeType;
323 module Definition :
325 type params = TextDocumentPositionParams.t
326 and result = DefinitionLocation.t list
328 module TypeDefinition :
330 type params = TextDocumentPositionParams.t
331 and result = DefinitionLocation.t list
333 module CodeAction :
335 type t = {
336 title: string;
337 kind: CodeActionKind.t;
338 diagnostics: PublishDiagnostics.diagnostic list;
339 action : edit_and_or_command;
341 and edit_and_or_command =
342 | EditOnly of WorkspaceEdit.t
343 | CommandOnly of Command.t
344 | BothEditThenCommand of (WorkspaceEdit.t * Command.t)
345 type result = command_or_action list
346 and command_or_action =
347 | Command of Command.t
348 | Action of t
350 module CodeActionRequest :
352 type params = {
353 textDocument: TextDocumentIdentifier.t;
354 range: range;
355 context: codeActionContext;
357 and codeActionContext = {
358 diagnostics: PublishDiagnostics.diagnostic list;
359 only: CodeActionKind.t list option
362 module Completion :
364 type completionItemKind =
365 | Text (* 1 *)
366 | Method (* 2 *)
367 | Function (* 3 *)
368 | Constructor (* 4 *)
369 | Field (* 5 *)
370 | Variable (* 6 *)
371 | Class (* 7 *)
372 | Interface (* 8 *)
373 | Module (* 9 *)
374 | Property (* 10 *)
375 | Unit (* 11 *)
376 | Value (* 12 *)
377 | Enum (* 13 *)
378 | Keyword (* 14 *)
379 | Snippet (* 15 *)
380 | Color (* 16 *)
381 | File (* 17 *)
382 | Reference (* 18 *)
383 | Folder (* 19 *)
384 | EnumMember (* 20 *)
385 | Constant (* 21 *)
386 | Struct (* 22 *)
387 | Event (* 23 *)
388 | Operator (* 24 *)
389 | TypeParameter (* 25 *)
390 [@@deriving enum]
392 type insertTextFormat =
393 | PlainText (* 1 *) (* the insertText/textEdits are just plain strings *)
394 | SnippetFormat (* 2 *) (* wire: just "Snippet" *)
395 [@@deriving enum]
397 type params = completionParams
399 and completionParams = {
400 loc: TextDocumentPositionParams.t;
401 context: completionContext option;
404 and completionContext = {
405 triggerKind: completionTriggerKind;
408 and completionTriggerKind =
409 | Invoked (* 1 *)
410 | TriggerCharacter (* 2 *)
411 | TriggerForIncompleteCompletions (* 3 *)
413 and result = completionList (* wire: can also be 'completionItem list' *)
415 and completionList = {
416 isIncomplete: bool; (* further typing should result in recomputing *)
417 items: completionItem list;
420 and completionItem = {
421 label: string; (* the label in the UI *)
422 kind: completionItemKind option; (* tells editor which icon to use *)
423 detail: string option; (* human-readable string like type/symbol info *)
424 inlineDetail: string option; (* nuclide-specific, right column *)
425 itemType: string option; (* nuclide-specific, left column *)
426 documentation: markedString list option; (* human-readable doc-comment *)
427 sortText: string option; (* used for sorting; if absent, uses label *)
428 filterText: string option; (* used for filtering; if absent, uses label *)
429 insertText: string option; (* used for inserting; if absent, uses label *)
430 insertTextFormat: insertTextFormat option;
431 textEdits: TextEdit.t list; (* wire: split into hd and tl *)
432 command: Command.t option; (* if present, is executed after completion *)
433 data: Hh_json.json option;
437 module CompletionItemResolve :
439 type params = Completion.completionItem
441 and result = Completion.completionItem
443 module WorkspaceSymbol :
445 type params = workspaceSymbolParams
446 and result = SymbolInformation.t list
447 and workspaceSymbolParams = { query : string; }
449 module DocumentSymbol :
451 type params = documentSymbolParams
452 and result = SymbolInformation.t list
453 and documentSymbolParams = { textDocument : TextDocumentIdentifier.t; }
455 module FindReferences :
457 type params = referenceParams
458 and result = Location.t list
459 and referenceParams = {
460 loc : TextDocumentPositionParams.t;
461 context : referenceContext;
463 and referenceContext = {
464 includeDeclaration : bool;
465 includeIndirectReferences : bool;
468 module DocumentHighlight :
470 type params = TextDocumentPositionParams.t
471 and result = documentHighlight list
472 and documentHighlight = {
473 range : range;
474 kind : documentHighlightKind option;
476 and documentHighlightKind = Text | Read | Write
478 module TypeCoverage :
480 type params = typeCoverageParams
481 and result = {
482 coveredPercent : int;
483 uncoveredRanges : uncoveredRange list;
484 defaultMessage : string;
486 and typeCoverageParams = { textDocument : TextDocumentIdentifier.t; }
487 and uncoveredRange = { range : range; message : string option; }
489 module DocumentFormatting :
491 type params = documentFormattingParams
492 and result = TextEdit.t list
493 and documentFormattingParams = {
494 textDocument : TextDocumentIdentifier.t;
495 options : formattingOptions;
497 and formattingOptions = { tabSize : int; insertSpaces : bool; }
499 module DocumentRangeFormatting :
501 type params = documentRangeFormattingParams
502 and result = TextEdit.t list
503 and documentRangeFormattingParams = {
504 textDocument : TextDocumentIdentifier.t;
505 range : range;
506 options : DocumentFormatting.formattingOptions;
509 module DocumentOnTypeFormatting :
511 type params = documentOnTypeFormattingParams
512 and result = TextEdit.t list
513 and documentOnTypeFormattingParams = {
514 textDocument : TextDocumentIdentifier.t;
515 position : position;
516 ch : string;
517 options : DocumentFormatting.formattingOptions;
520 module SignatureHelp :
522 type params = TextDocumentPositionParams.t
523 and result = t option
524 and t = {
525 signatures : signature_information list;
526 activeSignature : int;
527 activeParameter : int;
529 and signature_information = {
530 siginfo_label : string;
531 siginfo_documentation : string option;
532 parameters : parameter_information list;
534 and parameter_information = {
535 parinfo_label : string;
536 parinfo_documentation : string option;
539 module Rename :
541 type params = renameParams
543 and result = WorkspaceEdit.t
545 and renameParams = {
546 textDocument: TextDocumentIdentifier.t;
547 position: position;
548 newName: string;
551 module DocumentCodeLens :
553 type params = codelensParams
555 and result = CodeLens.t list
557 and codelensParams = {
558 textDocument: TextDocumentIdentifier.t;
561 module LogMessage :
563 type params = logMessageParams
564 and logMessageParams = { type_ : MessageType.t; message : string; }
566 module ShowMessage :
568 type params = showMessageParams
569 and showMessageParams = { type_ : MessageType.t; message : string; }
571 module ShowMessageRequest :
573 type t = Present of { id : lsp_id; } | Absent
574 and params = showMessageRequestParams
575 and result = messageActionItem option
576 and showMessageRequestParams = {
577 type_ : MessageType.t;
578 message : string;
579 actions : messageActionItem list;
581 and messageActionItem = { title : string; }
583 module ShowStatus :
585 type params = showStatusParams
586 and result = ShowMessageRequest.messageActionItem option
587 and showStatusParams = {
588 request : ShowMessageRequest.showMessageRequestParams;
589 progress : int option;
590 total : int option;
591 shortMessage : string option;
594 module Progress :
596 type t = Present of { id : int; label : string; } | Absent
597 and params = progressParams
598 and progressParams = { id : int; label : string option; }
600 module ActionRequired :
602 type t = Present of { id : int; label : string; } | Absent
603 and params = actionRequiredParams
604 and actionRequiredParams = { id : int; label : string option; }
606 module ConnectionStatus :
608 type params = connectionStatusParams
609 and connectionStatusParams = { isConnected : bool; }
611 module ToggleTypeCoverage :
613 type params = toggleTypeCoverageParams
614 and toggleTypeCoverageParams = { toggle : bool; }
616 module Error :
618 type t = {code: int; message: string; data: Hh_json.json option}
619 exception Parse of string
620 exception InvalidRequest of string
621 exception MethodNotFound of string
622 exception InvalidParams of string
623 exception InternalError of string
624 exception ServerErrorStart of string * Initialize.errorData
625 exception ServerErrorEnd of string
626 exception ServerNotInitialized of string
627 exception Unknown of string
628 exception RequestCancelled of string
630 module Code : sig
631 val parseError: int
632 val invalidRequest: int
633 val methodNotFound: int
634 val invalidParams: int
635 val internalError: int
636 val serverErrorStart: int
637 val serverErrorEnd: int
638 val serverNotInitialized: int
639 val unknownErrorCode: int
640 val requestCancelled: int
641 val contentModified: int
645 type lsp_registration_options =
646 | DidChangeWatchedFilesRegistrationOptions of
647 DidChangeWatchedFiles.registerOptions
648 module RegisterCapability :
650 type params = {
651 registrations : registration list;
653 and registration = {
654 id : string;
655 method_ : string;
656 registerOptions : lsp_registration_options;
658 val make_registration : lsp_registration_options -> registration
661 type lsp_request =
662 | InitializeRequest of Initialize.params
663 | RegisterCapabilityRequest of RegisterCapability.params
664 | ShutdownRequest
665 | CodeLensResolveRequest of CodeLensResolve.params
666 | HoverRequest of Hover.params
667 | DefinitionRequest of Definition.params
668 | TypeDefinitionRequest of TypeDefinition.params
669 | CodeActionRequest of CodeActionRequest.params
670 | CompletionRequest of Completion.params
671 | CompletionItemResolveRequest of CompletionItemResolve.params
672 | WorkspaceSymbolRequest of WorkspaceSymbol.params
673 | DocumentSymbolRequest of DocumentSymbol.params
674 | FindReferencesRequest of FindReferences.params
675 | DocumentHighlightRequest of DocumentHighlight.params
676 | TypeCoverageRequest of TypeCoverage.params
677 | DocumentFormattingRequest of DocumentFormatting.params
678 | DocumentRangeFormattingRequest of DocumentRangeFormatting.params
679 | DocumentOnTypeFormattingRequest of DocumentOnTypeFormatting.params
680 | ShowMessageRequestRequest of ShowMessageRequest.params
681 | ShowStatusRequest of ShowStatus.params
682 | RageRequest
683 | RenameRequest of Rename.params
684 | DocumentCodeLensRequest of DocumentCodeLens.params
685 | UnknownRequest of string * Hh_json.json option
686 type lsp_result =
687 | InitializeResult of Initialize.result
688 | ShutdownResult
689 | CodeLensResolveResult of CodeLensResolve.result
690 | HoverResult of Hover.result
691 | DefinitionResult of Definition.result
692 | TypeDefinitionResult of TypeDefinition.result
693 | CodeActionResult of CodeAction.result
694 | CompletionResult of Completion.result
695 | CompletionItemResolveResult of CompletionItemResolve.result
696 | WorkspaceSymbolResult of WorkspaceSymbol.result
697 | DocumentSymbolResult of DocumentSymbol.result
698 | FindReferencesResult of FindReferences.result
699 | DocumentHighlightResult of DocumentHighlight.result
700 | TypeCoverageResult of TypeCoverage.result
701 | DocumentFormattingResult of DocumentFormatting.result
702 | DocumentRangeFormattingResult of DocumentRangeFormatting.result
703 | DocumentOnTypeFormattingResult of DocumentOnTypeFormatting.result
704 | ShowMessageRequestResult of ShowMessageRequest.result
705 | ShowStatusResult of ShowStatus.result
706 | RageResult of Rage.result
707 | RenameResult of Rename.result
708 | DocumentCodeLensResult of DocumentCodeLens.result
709 | ErrorResult of Error.t * string (* the string is a stacktrace *)
710 type lsp_notification =
711 | ExitNotification
712 | CancelRequestNotification of CancelRequest.params
713 | PublishDiagnosticsNotification of PublishDiagnostics.params
714 | DidOpenNotification of DidOpen.params
715 | DidCloseNotification of DidClose.params
716 | DidSaveNotification of DidSave.params
717 | DidChangeNotification of DidChange.params
718 | DidChangeWatchedFilesNotification of DidChangeWatchedFiles.params
719 | LogMessageNotification of LogMessage.params
720 | TelemetryNotification of LogMessage.params (* LSP allows 'any' but we only send these *)
721 | ShowMessageNotification of ShowMessage.params
722 | ProgressNotification of Progress.params
723 | ActionRequiredNotification of ActionRequired.params
724 | ConnectionStatusNotification of ConnectionStatus.params
725 | InitializedNotification
726 | SetTraceNotification (* $/setTraceNotification *)
727 | LogTraceNotification (* $/logTraceNotification *)
728 | UnknownNotification of string * Hh_json.json option
729 type lsp_message =
730 | RequestMessage of lsp_id * lsp_request
731 | ResponseMessage of lsp_id * lsp_result
732 | NotificationMessage of lsp_notification
734 type 'a lsp_handler = 'a lsp_result_handler * 'a lsp_error_handler
735 and 'a lsp_error_handler = (Error.t * string) -> 'a -> 'a
736 and 'a lsp_result_handler =
737 | ShowMessageHandler of (ShowMessageRequest.result -> 'a -> 'a)
738 | ShowStatusHandler of (ShowStatus.result -> 'a -> 'a)
740 module IdKey :
742 type t = lsp_id
743 val compare : t -> t -> int
745 module IdSet : sig include module type of Set.Make (IdKey) end
746 module IdMap : sig include module type of MyMap.Make (IdKey) end