2 * Copyright (c) 2019, Facebook, Inc.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
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
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 *)
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
:
32 textDocument
: VersionedTextDocumentIdentifier.t
;
33 edits
: TextEdit.t list
;
36 module WorkspaceEdit
:
39 changes
: TextEdit.t list
SMap.t
; (* holds changes to existing docs *)
42 module TextDocumentItem
:
56 data
: Hh_json.json
option;
59 module TextDocumentPositionParams
:
62 textDocument
: TextDocumentIdentifier.t
;
66 module DocumentFilter
:
69 language
: string option;
70 scheme
: string option;
71 pattern
: string option;
74 module DocumentSelector
: sig type t
= DocumentFilter.t list
end
75 module SymbolInformation
:
80 location
: Location.t
;
81 containerName
: string option;
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
122 processId
: int option;
123 rootPath
: string option;
124 rootUri
: documentUri
option;
125 initializationOptions
: initializationOptions
;
126 client_capabilities
: client_capabilities
;
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
= {
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
= {
160 can_willSaveWaitUntil
: bool;
163 and completion
= { completionItem
: completionItem
; }
164 and completionItem
= { snippetSupport
: bool; }
166 codeAction_dynamicRegistration
: bool;
167 codeActionLiteralSupport
: codeActionliteralSupport
option; }
168 and codeActionliteralSupport
= { codeAction_valueSet
: CodeActionKind.t list
}
169 and windowClientCapabilities
= {
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;
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
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
234 type params
= TextDocumentPositionParams.t
235 and result
= hoverResult
option
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
= {
252 diagnostics
: diagnostic list
;
256 severity
: diagnosticSeverity
option;
257 code
: diagnosticCode
;
258 source
: string option;
260 relatedInformation
: diagnosticRelatedInformation list
;
261 relatedLocations
: relatedLocation list
;
263 and diagnosticRelatedInformation
= {
264 relatedLocation
: Location.t
;
265 relatedMessage
: string;
267 and relatedLocation
= diagnosticRelatedInformation
271 type params
= didOpenTextDocumentParams
272 and didOpenTextDocumentParams
= { textDocument
: TextDocumentItem.t
; }
276 type params
= didCloseTextDocumentParams
277 and didCloseTextDocumentParams
= {
278 textDocument
: TextDocumentIdentifier.t
;
283 type params
= didSaveTextDocumentParams
284 and didSaveTextDocumentParams
= {
285 textDocument
: TextDocumentIdentifier.t
;
286 text
: string option;
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;
302 module DidChangeWatchedFiles
:
304 type registerOptions
= {
305 watchers
: fileSystemWatcher list
;
307 and fileSystemWatcher
= {
310 type fileChangeType
=
316 changes
: fileEvent list
;
320 type_
: fileChangeType
;
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
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
350 module CodeActionRequest
:
353 textDocument
: TextDocumentIdentifier.t
;
355 context
: codeActionContext
;
357 and codeActionContext
= {
358 diagnostics
: PublishDiagnostics.diagnostic list
;
359 only
: CodeActionKind.t list
option
364 type completionItemKind
=
368 | Constructor
(* 4 *)
384 | EnumMember
(* 20 *)
389 | TypeParameter
(* 25 *)
392 type insertTextFormat
=
393 | PlainText
(* 1 *) (* the insertText/textEdits are just plain strings *)
394 | SnippetFormat
(* 2 *) (* wire: just "Snippet" *)
397 type params
= completionParams
399 and completionParams
= {
400 loc
: TextDocumentPositionParams.t
;
401 context
: completionContext
option;
404 and completionContext
= {
405 triggerKind
: completionTriggerKind
;
408 and completionTriggerKind
=
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
= {
474 kind
: documentHighlightKind
option;
476 and documentHighlightKind
= Text
| Read
| Write
478 module TypeCoverage
:
480 type params
= typeCoverageParams
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
;
506 options
: DocumentFormatting.formattingOptions
;
509 module DocumentOnTypeFormatting
:
511 type params
= documentOnTypeFormattingParams
512 and result
= TextEdit.t list
513 and documentOnTypeFormattingParams
= {
514 textDocument
: TextDocumentIdentifier.t
;
517 options
: DocumentFormatting.formattingOptions
;
520 module SignatureHelp
:
522 type params
= TextDocumentPositionParams.t
523 and result
= t
option
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;
541 type params
= renameParams
543 and result
= WorkspaceEdit.t
546 textDocument
: TextDocumentIdentifier.t
;
551 module DocumentCodeLens
:
553 type params
= codelensParams
555 and result
= CodeLens.t list
557 and codelensParams
= {
558 textDocument
: TextDocumentIdentifier.t
;
563 type params
= logMessageParams
564 and logMessageParams
= { type_
: MessageType.t
; message
: string; }
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
;
579 actions
: messageActionItem list
;
581 and messageActionItem
= { title
: string; }
585 type params
= showStatusParams
586 and result
= ShowMessageRequest.messageActionItem
option
587 and showStatusParams
= {
588 request
: ShowMessageRequest.showMessageRequestParams
;
589 progress
: int option;
591 shortMessage
: string option;
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; }
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
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
:
651 registrations
: registration list
;
656 registerOptions
: lsp_registration_options
;
658 val make_registration
: lsp_registration_options
-> registration
662 | InitializeRequest
of Initialize.params
663 | RegisterCapabilityRequest
of RegisterCapability.params
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
683 | RenameRequest
of Rename.params
684 | DocumentCodeLensRequest
of DocumentCodeLens.params
685 | UnknownRequest
of string * Hh_json.json
option
687 | InitializeResult
of Initialize.result
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
=
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
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
)
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