language_server-protocol 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Dockerfile-node.development +6 -0
- data/Dockerfile.development +14 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/generate_files +5 -0
- data/bin/setup +8 -0
- data/language_server-protocol.gemspec +27 -0
- data/lib/language_server/protocol/constants/completion_item_kind.rb +29 -0
- data/lib/language_server/protocol/constants/diagnostic_severity.rb +24 -0
- data/lib/language_server/protocol/constants/document_highlight_kind.rb +23 -0
- data/lib/language_server/protocol/constants/error_codes.rb +18 -0
- data/lib/language_server/protocol/constants/file_change_type.rb +23 -0
- data/lib/language_server/protocol/constants/initialize_error.rb +15 -0
- data/lib/language_server/protocol/constants/insert_text_format.rb +27 -0
- data/lib/language_server/protocol/constants/message_type.rb +24 -0
- data/lib/language_server/protocol/constants/symbol_kind.rb +29 -0
- data/lib/language_server/protocol/constants/text_document_save_reason.rb +24 -0
- data/lib/language_server/protocol/constants/text_document_sync_kind.rb +26 -0
- data/lib/language_server/protocol/constants.rb +11 -0
- data/lib/language_server/protocol/interfaces/apply_workspace_edit_params.rb +29 -0
- data/lib/language_server/protocol/interfaces/apply_workspace_edit_response.rb +29 -0
- data/lib/language_server/protocol/interfaces/cancel_params.rb +29 -0
- data/lib/language_server/protocol/interfaces/client_capabilities.rb +47 -0
- data/lib/language_server/protocol/interfaces/code_action_context.rb +33 -0
- data/lib/language_server/protocol/interfaces/code_action_params.rb +50 -0
- data/lib/language_server/protocol/interfaces/code_lens.rb +55 -0
- data/lib/language_server/protocol/interfaces/code_lens_options.rb +32 -0
- data/lib/language_server/protocol/interfaces/code_lens_params.rb +29 -0
- data/lib/language_server/protocol/interfaces/code_lens_registration_options.rb +29 -0
- data/lib/language_server/protocol/interfaces/command.rb +48 -0
- data/lib/language_server/protocol/interfaces/completion_item.rb +145 -0
- data/lib/language_server/protocol/interfaces/completion_list.rb +43 -0
- data/lib/language_server/protocol/interfaces/completion_options.rb +42 -0
- data/lib/language_server/protocol/interfaces/completion_registration_options.rb +39 -0
- data/lib/language_server/protocol/interfaces/diagnostic.rb +67 -0
- data/lib/language_server/protocol/interfaces/did_change_configuration_params.rb +29 -0
- data/lib/language_server/protocol/interfaces/did_change_text_document_params.rb +40 -0
- data/lib/language_server/protocol/interfaces/did_change_watched_files_params.rb +29 -0
- data/lib/language_server/protocol/interfaces/did_close_text_document_params.rb +29 -0
- data/lib/language_server/protocol/interfaces/did_open_text_document_params.rb +29 -0
- data/lib/language_server/protocol/interfaces/did_save_text_document_params.rb +39 -0
- data/lib/language_server/protocol/interfaces/document_filter.rb +47 -0
- data/lib/language_server/protocol/interfaces/document_formatting_params.rb +38 -0
- data/lib/language_server/protocol/interfaces/document_highlight.rb +43 -0
- data/lib/language_server/protocol/interfaces/document_link.rb +42 -0
- data/lib/language_server/protocol/interfaces/document_link_options.rb +32 -0
- data/lib/language_server/protocol/interfaces/document_link_params.rb +29 -0
- data/lib/language_server/protocol/interfaces/document_link_registration_options.rb +29 -0
- data/lib/language_server/protocol/interfaces/document_on_type_formatting_options.rb +41 -0
- data/lib/language_server/protocol/interfaces/document_on_type_formatting_params.rb +56 -0
- data/lib/language_server/protocol/interfaces/document_on_type_formatting_registration_options.rb +38 -0
- data/lib/language_server/protocol/interfaces/document_range_formatting_params.rb +47 -0
- data/lib/language_server/protocol/interfaces/document_symbol_params.rb +29 -0
- data/lib/language_server/protocol/interfaces/execute_command_options.rb +32 -0
- data/lib/language_server/protocol/interfaces/execute_command_params.rb +38 -0
- data/lib/language_server/protocol/interfaces/execute_command_registration_options.rb +32 -0
- data/lib/language_server/protocol/interfaces/file_event.rb +41 -0
- data/lib/language_server/protocol/interfaces/formatting_options.rb +41 -0
- data/lib/language_server/protocol/interfaces/hover.rb +42 -0
- data/lib/language_server/protocol/interfaces/initialize_error.rb +35 -0
- data/lib/language_server/protocol/interfaces/initialize_params.rb +79 -0
- data/lib/language_server/protocol/interfaces/initialize_result.rb +29 -0
- data/lib/language_server/protocol/interfaces/location.rb +32 -0
- data/lib/language_server/protocol/interfaces/log_message_params.rb +38 -0
- data/lib/language_server/protocol/interfaces/message.rb +26 -0
- data/lib/language_server/protocol/interfaces/message_action_item.rb +29 -0
- data/lib/language_server/protocol/interfaces/notification_message.rb +38 -0
- data/lib/language_server/protocol/interfaces/parameter_information.rb +44 -0
- data/lib/language_server/protocol/interfaces/position.rb +38 -0
- data/lib/language_server/protocol/interfaces/publish_diagnostics_params.rb +38 -0
- data/lib/language_server/protocol/interfaces/range.rb +38 -0
- data/lib/language_server/protocol/interfaces/reference_context.rb +29 -0
- data/lib/language_server/protocol/interfaces/reference_params.rb +26 -0
- data/lib/language_server/protocol/interfaces/registration.rb +51 -0
- data/lib/language_server/protocol/interfaces/registration_params.rb +26 -0
- data/lib/language_server/protocol/interfaces/rename_params.rb +49 -0
- data/lib/language_server/protocol/interfaces/request_message.rb +47 -0
- data/lib/language_server/protocol/interfaces/response_error.rb +48 -0
- data/lib/language_server/protocol/interfaces/response_message.rb +48 -0
- data/lib/language_server/protocol/interfaces/save_options.rb +32 -0
- data/lib/language_server/protocol/interfaces/server_capabilities.rb +183 -0
- data/lib/language_server/protocol/interfaces/show_message_params.rb +38 -0
- data/lib/language_server/protocol/interfaces/show_message_request_params.rb +47 -0
- data/lib/language_server/protocol/interfaces/signature_help.rb +64 -0
- data/lib/language_server/protocol/interfaces/signature_help_options.rb +33 -0
- data/lib/language_server/protocol/interfaces/signature_help_registration_options.rb +30 -0
- data/lib/language_server/protocol/interfaces/signature_information.rb +54 -0
- data/lib/language_server/protocol/interfaces/symbol_information.rb +60 -0
- data/lib/language_server/protocol/interfaces/text_document_change_registration_options.rb +33 -0
- data/lib/language_server/protocol/interfaces/text_document_client_capabilities.rb +155 -0
- data/lib/language_server/protocol/interfaces/text_document_content_change_event.rb +51 -0
- data/lib/language_server/protocol/interfaces/text_document_edit.rb +38 -0
- data/lib/language_server/protocol/interfaces/text_document_identifier.rb +29 -0
- data/lib/language_server/protocol/interfaces/text_document_item.rb +57 -0
- data/lib/language_server/protocol/interfaces/text_document_position_params.rb +38 -0
- data/lib/language_server/protocol/interfaces/text_document_registration_options.rb +30 -0
- data/lib/language_server/protocol/interfaces/text_document_save_registration_options.rb +29 -0
- data/lib/language_server/protocol/interfaces/text_document_sync_options.rb +66 -0
- data/lib/language_server/protocol/interfaces/text_edit.rb +40 -0
- data/lib/language_server/protocol/interfaces/unregistration.rb +42 -0
- data/lib/language_server/protocol/interfaces/unregistration_params.rb +26 -0
- data/lib/language_server/protocol/interfaces/versioned_text_document_identifier.rb +29 -0
- data/lib/language_server/protocol/interfaces/will_save_text_document_params.rb +41 -0
- data/lib/language_server/protocol/interfaces/workspace_client_capabilites.rb +78 -0
- data/lib/language_server/protocol/interfaces/workspace_edit.rb +40 -0
- data/lib/language_server/protocol/interfaces/workspace_symbol_params.rb +32 -0
- data/lib/language_server/protocol/interfaces.rb +87 -0
- data/lib/language_server/protocol/transport/stdio/reader.rb +39 -0
- data/lib/language_server/protocol/transport/stdio/writer.rb +38 -0
- data/lib/language_server/protocol/transport/stdio.rb +2 -0
- data/lib/language_server/protocol/version.rb +5 -0
- data/lib/language_server/protocol.rb +7 -0
- data/package.json +10 -0
- data/scripts/generateFiles.ts +224 -0
- data/yarn.lock +293 -0
- metadata +207 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module LanguageServer
|
|
2
|
+
module Protocol
|
|
3
|
+
module Interfaces
|
|
4
|
+
class VersionedTextDocumentIdentifier
|
|
5
|
+
def initialize(version:)
|
|
6
|
+
@attributes = {}
|
|
7
|
+
|
|
8
|
+
@attributes[:version] = version
|
|
9
|
+
|
|
10
|
+
@attributes.freeze
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
#
|
|
14
|
+
# The version number of this document.
|
|
15
|
+
#
|
|
16
|
+
# @return [number]
|
|
17
|
+
def version
|
|
18
|
+
attributes.fetch(:version)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
attr_reader :attributes
|
|
22
|
+
|
|
23
|
+
def to_json(*args)
|
|
24
|
+
attributes.to_json(*args)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module LanguageServer
|
|
2
|
+
module Protocol
|
|
3
|
+
module Interfaces
|
|
4
|
+
#
|
|
5
|
+
# The parameters send in a will save text document notification.
|
|
6
|
+
#
|
|
7
|
+
class WillSaveTextDocumentParams
|
|
8
|
+
def initialize(text_document:, reason:)
|
|
9
|
+
@attributes = {}
|
|
10
|
+
|
|
11
|
+
@attributes[:textDocument] = text_document
|
|
12
|
+
@attributes[:reason] = reason
|
|
13
|
+
|
|
14
|
+
@attributes.freeze
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
#
|
|
18
|
+
# The document that will be saved.
|
|
19
|
+
#
|
|
20
|
+
# @return [TextDocumentIdentifier]
|
|
21
|
+
def text_document
|
|
22
|
+
attributes.fetch(:textDocument)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
#
|
|
26
|
+
# The 'TextDocumentSaveReason'.
|
|
27
|
+
#
|
|
28
|
+
# @return [number]
|
|
29
|
+
def reason
|
|
30
|
+
attributes.fetch(:reason)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
attr_reader :attributes
|
|
34
|
+
|
|
35
|
+
def to_json(*args)
|
|
36
|
+
attributes.to_json(*args)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
module LanguageServer
|
|
2
|
+
module Protocol
|
|
3
|
+
module Interfaces
|
|
4
|
+
#
|
|
5
|
+
# Workspace specific client capabilities.
|
|
6
|
+
#
|
|
7
|
+
class WorkspaceClientCapabilites
|
|
8
|
+
def initialize(apply_edit: nil, workspace_edit: nil, did_change_configuration: nil, did_change_watched_files: nil, symbol: nil, execute_command: nil)
|
|
9
|
+
@attributes = {}
|
|
10
|
+
|
|
11
|
+
@attributes[:applyEdit] = apply_edit if apply_edit
|
|
12
|
+
@attributes[:workspaceEdit] = workspace_edit if workspace_edit
|
|
13
|
+
@attributes[:didChangeConfiguration] = did_change_configuration if did_change_configuration
|
|
14
|
+
@attributes[:didChangeWatchedFiles] = did_change_watched_files if did_change_watched_files
|
|
15
|
+
@attributes[:symbol] = symbol if symbol
|
|
16
|
+
@attributes[:executeCommand] = execute_command if execute_command
|
|
17
|
+
|
|
18
|
+
@attributes.freeze
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
#
|
|
22
|
+
# The client supports applying batch edits to the workspace by supporting
|
|
23
|
+
# the request 'workspace/applyEdit'
|
|
24
|
+
#
|
|
25
|
+
# @return [boolean]
|
|
26
|
+
def apply_edit
|
|
27
|
+
attributes.fetch(:applyEdit)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
#
|
|
31
|
+
# Capabilities specific to `WorkspaceEdit`s
|
|
32
|
+
#
|
|
33
|
+
# @return [{ documentChanges?: boolean; }]
|
|
34
|
+
def workspace_edit
|
|
35
|
+
attributes.fetch(:workspaceEdit)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
#
|
|
39
|
+
# Capabilities specific to the `workspace/didChangeConfiguration` notification.
|
|
40
|
+
#
|
|
41
|
+
# @return [{ dynamicRegistration?: boolean; }]
|
|
42
|
+
def did_change_configuration
|
|
43
|
+
attributes.fetch(:didChangeConfiguration)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
#
|
|
47
|
+
# Capabilities specific to the `workspace/didChangeWatchedFiles` notification.
|
|
48
|
+
#
|
|
49
|
+
# @return [{ dynamicRegistration?: boolean; }]
|
|
50
|
+
def did_change_watched_files
|
|
51
|
+
attributes.fetch(:didChangeWatchedFiles)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
#
|
|
55
|
+
# Capabilities specific to the `workspace/symbol` request.
|
|
56
|
+
#
|
|
57
|
+
# @return [{ dynamicRegistration?: boolean; }]
|
|
58
|
+
def symbol
|
|
59
|
+
attributes.fetch(:symbol)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
#
|
|
63
|
+
# Capabilities specific to the `workspace/executeCommand` request.
|
|
64
|
+
#
|
|
65
|
+
# @return [{ dynamicRegistration?: boolean; }]
|
|
66
|
+
def execute_command
|
|
67
|
+
attributes.fetch(:executeCommand)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
attr_reader :attributes
|
|
71
|
+
|
|
72
|
+
def to_json(*args)
|
|
73
|
+
attributes.to_json(*args)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module LanguageServer
|
|
2
|
+
module Protocol
|
|
3
|
+
module Interfaces
|
|
4
|
+
class WorkspaceEdit
|
|
5
|
+
def initialize(changes: nil, document_changes: nil)
|
|
6
|
+
@attributes = {}
|
|
7
|
+
|
|
8
|
+
@attributes[:changes] = changes if changes
|
|
9
|
+
@attributes[:documentChanges] = document_changes if document_changes
|
|
10
|
+
|
|
11
|
+
@attributes.freeze
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
#
|
|
15
|
+
# Holds changes to existing resources.
|
|
16
|
+
#
|
|
17
|
+
# @return [{ [uri: string]: TextEdit[]; }]
|
|
18
|
+
def changes
|
|
19
|
+
attributes.fetch(:changes)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
#
|
|
23
|
+
# An array of `TextDocumentEdit`s to express changes to specific a specific
|
|
24
|
+
# version of a text document. Whether a client supports versioned document
|
|
25
|
+
# edits is expressed via `WorkspaceClientCapabilites.versionedWorkspaceEdit`.
|
|
26
|
+
#
|
|
27
|
+
# @return [TextDocumentEdit[]]
|
|
28
|
+
def document_changes
|
|
29
|
+
attributes.fetch(:documentChanges)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
attr_reader :attributes
|
|
33
|
+
|
|
34
|
+
def to_json(*args)
|
|
35
|
+
attributes.to_json(*args)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module LanguageServer
|
|
2
|
+
module Protocol
|
|
3
|
+
module Interfaces
|
|
4
|
+
#
|
|
5
|
+
# The parameters of a Workspace Symbol Request.
|
|
6
|
+
#
|
|
7
|
+
class WorkspaceSymbolParams
|
|
8
|
+
def initialize(query:)
|
|
9
|
+
@attributes = {}
|
|
10
|
+
|
|
11
|
+
@attributes[:query] = query
|
|
12
|
+
|
|
13
|
+
@attributes.freeze
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
#
|
|
17
|
+
# A non-empty query string
|
|
18
|
+
#
|
|
19
|
+
# @return [string]
|
|
20
|
+
def query
|
|
21
|
+
attributes.fetch(:query)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
attr_reader :attributes
|
|
25
|
+
|
|
26
|
+
def to_json(*args)
|
|
27
|
+
attributes.to_json(*args)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
require "language_server/protocol/interfaces/message"
|
|
2
|
+
require "language_server/protocol/interfaces/request_message"
|
|
3
|
+
require "language_server/protocol/interfaces/response_message"
|
|
4
|
+
require "language_server/protocol/interfaces/response_error"
|
|
5
|
+
require "language_server/protocol/interfaces/notification_message"
|
|
6
|
+
require "language_server/protocol/interfaces/cancel_params"
|
|
7
|
+
require "language_server/protocol/interfaces/position"
|
|
8
|
+
require "language_server/protocol/interfaces/range"
|
|
9
|
+
require "language_server/protocol/interfaces/location"
|
|
10
|
+
require "language_server/protocol/interfaces/diagnostic"
|
|
11
|
+
require "language_server/protocol/interfaces/command"
|
|
12
|
+
require "language_server/protocol/interfaces/text_edit"
|
|
13
|
+
require "language_server/protocol/interfaces/text_document_edit"
|
|
14
|
+
require "language_server/protocol/interfaces/workspace_edit"
|
|
15
|
+
require "language_server/protocol/interfaces/text_document_identifier"
|
|
16
|
+
require "language_server/protocol/interfaces/text_document_item"
|
|
17
|
+
require "language_server/protocol/interfaces/versioned_text_document_identifier"
|
|
18
|
+
require "language_server/protocol/interfaces/text_document_position_params"
|
|
19
|
+
require "language_server/protocol/interfaces/document_filter"
|
|
20
|
+
require "language_server/protocol/interfaces/initialize_params"
|
|
21
|
+
require "language_server/protocol/interfaces/workspace_client_capabilites"
|
|
22
|
+
require "language_server/protocol/interfaces/text_document_client_capabilities"
|
|
23
|
+
require "language_server/protocol/interfaces/client_capabilities"
|
|
24
|
+
require "language_server/protocol/interfaces/initialize_result"
|
|
25
|
+
require "language_server/protocol/interfaces/initialize_error"
|
|
26
|
+
require "language_server/protocol/interfaces/completion_options"
|
|
27
|
+
require "language_server/protocol/interfaces/signature_help_options"
|
|
28
|
+
require "language_server/protocol/interfaces/code_lens_options"
|
|
29
|
+
require "language_server/protocol/interfaces/document_on_type_formatting_options"
|
|
30
|
+
require "language_server/protocol/interfaces/document_link_options"
|
|
31
|
+
require "language_server/protocol/interfaces/execute_command_options"
|
|
32
|
+
require "language_server/protocol/interfaces/save_options"
|
|
33
|
+
require "language_server/protocol/interfaces/text_document_sync_options"
|
|
34
|
+
require "language_server/protocol/interfaces/server_capabilities"
|
|
35
|
+
require "language_server/protocol/interfaces/show_message_params"
|
|
36
|
+
require "language_server/protocol/interfaces/show_message_request_params"
|
|
37
|
+
require "language_server/protocol/interfaces/message_action_item"
|
|
38
|
+
require "language_server/protocol/interfaces/log_message_params"
|
|
39
|
+
require "language_server/protocol/interfaces/registration"
|
|
40
|
+
require "language_server/protocol/interfaces/registration_params"
|
|
41
|
+
require "language_server/protocol/interfaces/text_document_registration_options"
|
|
42
|
+
require "language_server/protocol/interfaces/unregistration"
|
|
43
|
+
require "language_server/protocol/interfaces/unregistration_params"
|
|
44
|
+
require "language_server/protocol/interfaces/did_change_configuration_params"
|
|
45
|
+
require "language_server/protocol/interfaces/did_open_text_document_params"
|
|
46
|
+
require "language_server/protocol/interfaces/did_change_text_document_params"
|
|
47
|
+
require "language_server/protocol/interfaces/text_document_content_change_event"
|
|
48
|
+
require "language_server/protocol/interfaces/text_document_change_registration_options"
|
|
49
|
+
require "language_server/protocol/interfaces/will_save_text_document_params"
|
|
50
|
+
require "language_server/protocol/interfaces/did_save_text_document_params"
|
|
51
|
+
require "language_server/protocol/interfaces/text_document_save_registration_options"
|
|
52
|
+
require "language_server/protocol/interfaces/did_close_text_document_params"
|
|
53
|
+
require "language_server/protocol/interfaces/did_change_watched_files_params"
|
|
54
|
+
require "language_server/protocol/interfaces/file_event"
|
|
55
|
+
require "language_server/protocol/interfaces/publish_diagnostics_params"
|
|
56
|
+
require "language_server/protocol/interfaces/completion_list"
|
|
57
|
+
require "language_server/protocol/interfaces/completion_item"
|
|
58
|
+
require "language_server/protocol/interfaces/completion_registration_options"
|
|
59
|
+
require "language_server/protocol/interfaces/hover"
|
|
60
|
+
require "language_server/protocol/interfaces/signature_help"
|
|
61
|
+
require "language_server/protocol/interfaces/signature_information"
|
|
62
|
+
require "language_server/protocol/interfaces/parameter_information"
|
|
63
|
+
require "language_server/protocol/interfaces/signature_help_registration_options"
|
|
64
|
+
require "language_server/protocol/interfaces/reference_params"
|
|
65
|
+
require "language_server/protocol/interfaces/reference_context"
|
|
66
|
+
require "language_server/protocol/interfaces/document_highlight"
|
|
67
|
+
require "language_server/protocol/interfaces/document_symbol_params"
|
|
68
|
+
require "language_server/protocol/interfaces/symbol_information"
|
|
69
|
+
require "language_server/protocol/interfaces/workspace_symbol_params"
|
|
70
|
+
require "language_server/protocol/interfaces/code_action_params"
|
|
71
|
+
require "language_server/protocol/interfaces/code_action_context"
|
|
72
|
+
require "language_server/protocol/interfaces/code_lens_params"
|
|
73
|
+
require "language_server/protocol/interfaces/code_lens"
|
|
74
|
+
require "language_server/protocol/interfaces/code_lens_registration_options"
|
|
75
|
+
require "language_server/protocol/interfaces/document_link_params"
|
|
76
|
+
require "language_server/protocol/interfaces/document_link"
|
|
77
|
+
require "language_server/protocol/interfaces/document_link_registration_options"
|
|
78
|
+
require "language_server/protocol/interfaces/document_formatting_params"
|
|
79
|
+
require "language_server/protocol/interfaces/formatting_options"
|
|
80
|
+
require "language_server/protocol/interfaces/document_range_formatting_params"
|
|
81
|
+
require "language_server/protocol/interfaces/document_on_type_formatting_params"
|
|
82
|
+
require "language_server/protocol/interfaces/document_on_type_formatting_registration_options"
|
|
83
|
+
require "language_server/protocol/interfaces/rename_params"
|
|
84
|
+
require "language_server/protocol/interfaces/execute_command_params"
|
|
85
|
+
require "language_server/protocol/interfaces/execute_command_registration_options"
|
|
86
|
+
require "language_server/protocol/interfaces/apply_workspace_edit_params"
|
|
87
|
+
require "language_server/protocol/interfaces/apply_workspace_edit_response"
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
module LanguageServer
|
|
4
|
+
module Protocol
|
|
5
|
+
module Transport
|
|
6
|
+
module Stdio
|
|
7
|
+
class Reader
|
|
8
|
+
def read(&block)
|
|
9
|
+
buffer = ""
|
|
10
|
+
header_parsed = false
|
|
11
|
+
content_length = nil
|
|
12
|
+
|
|
13
|
+
while char = STDIN.getc
|
|
14
|
+
buffer << char
|
|
15
|
+
|
|
16
|
+
unless header_parsed
|
|
17
|
+
if buffer[-4..-1] == "\r\n" * 2
|
|
18
|
+
content_length = buffer.match(/Content-Length: (\d+)/i)[1].to_i
|
|
19
|
+
|
|
20
|
+
header_parsed = true
|
|
21
|
+
buffer.clear
|
|
22
|
+
end
|
|
23
|
+
else
|
|
24
|
+
if buffer.bytesize == content_length
|
|
25
|
+
request = JSON.parse(buffer, symbolize_names: true)
|
|
26
|
+
|
|
27
|
+
block.call(request)
|
|
28
|
+
|
|
29
|
+
header_parsed = false
|
|
30
|
+
buffer.clear
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module LanguageServer
|
|
2
|
+
module Protocol
|
|
3
|
+
module Transport
|
|
4
|
+
module Stdio
|
|
5
|
+
class Writer
|
|
6
|
+
def respond(id:, result:)
|
|
7
|
+
write(id: id, result: result)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def notify(method:, params: {})
|
|
11
|
+
write(method: method, params: params)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def write(response)
|
|
17
|
+
response_str = response.merge(
|
|
18
|
+
jsonrpc: "2.0"
|
|
19
|
+
).to_json
|
|
20
|
+
|
|
21
|
+
headers = {
|
|
22
|
+
"Content-Length" => response_str.bytesize
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
headers.each do |k, v|
|
|
26
|
+
STDOUT.print "#{k}: #{v}\r\n"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
STDOUT.print "\r\n"
|
|
30
|
+
|
|
31
|
+
STDOUT.print response_str
|
|
32
|
+
STDOUT.flush
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
data/package.json
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import * as fetch from 'isomorphic-fetch';
|
|
5
|
+
|
|
6
|
+
const lspVersion = 'a0d9d12fa6d4c313d3ed70bd842f0a2c8e66e29e';
|
|
7
|
+
const rootDir = path.normalize(path.join(__dirname, ".."));
|
|
8
|
+
const tempDir = path.join(rootDir, "tmp");
|
|
9
|
+
const protocolMdPath = path.join(tempDir, lspVersion, "protocol.md");
|
|
10
|
+
|
|
11
|
+
const createFile = (filePath, content) => {
|
|
12
|
+
const dir = path.dirname(path.normalize(filePath));
|
|
13
|
+
|
|
14
|
+
dir.split(/(?!^)\//).forEach((_, index, all) => {
|
|
15
|
+
const dir = all.slice(0, index + 1).join("/");
|
|
16
|
+
|
|
17
|
+
if (!fs.existsSync(dir)) {
|
|
18
|
+
fs.mkdirSync(dir);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
fs.writeFileSync(filePath, content);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const extractTypeScriptSource = content => {
|
|
26
|
+
const regEx = /^```typescript\n([^]*?)^```\n/mg;
|
|
27
|
+
let match;
|
|
28
|
+
let result = "";
|
|
29
|
+
|
|
30
|
+
while((match = regEx.exec(content)) !== null) {
|
|
31
|
+
result = result.concat(match[1]);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const extractDefinitions = content => {
|
|
38
|
+
const fileName = path.join(tempDir, "protocol.ts");
|
|
39
|
+
createFile(fileName, content);
|
|
40
|
+
const program = ts.createProgram([fileName], {});
|
|
41
|
+
const checker = program.getTypeChecker();
|
|
42
|
+
|
|
43
|
+
const output = [];
|
|
44
|
+
|
|
45
|
+
const serialize = member => {
|
|
46
|
+
const symbol = checker.getSymbolAtLocation(member.name);
|
|
47
|
+
const type = checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration);
|
|
48
|
+
const types = member.kind == ts.SyntaxKind.UnionType ? (<ts.UnionTypeNode>(<ts.PropertySignature>member).type).types : [];
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
name: symbol.getName(),
|
|
52
|
+
documentation: ts.displayPartsToString(symbol.getDocumentationComment()),
|
|
53
|
+
type: checker.typeToString(type),
|
|
54
|
+
optional: !!member.questionToken,
|
|
55
|
+
nullable: (<ts.NodeArray<ts.TypeNode>>types).some(t => t.kind == ts.SyntaxKind.NullKeyword),
|
|
56
|
+
value: symbol.valueDeclaration ? symbol.valueDeclaration.getChildAt(symbol.valueDeclaration.getChildCount() - 1).getText() : null
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const handleInterface = (node: ts.InterfaceDeclaration) => {
|
|
61
|
+
const members = node.members.filter(member => member.name).map(member => serialize(member));
|
|
62
|
+
|
|
63
|
+
output.push(
|
|
64
|
+
{
|
|
65
|
+
interface: serialize(node),
|
|
66
|
+
members
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const handleModule = (node: ts.ModuleDeclaration) => {
|
|
72
|
+
const members = []
|
|
73
|
+
|
|
74
|
+
ts.forEachChild(node.body, node => {
|
|
75
|
+
members.push(serialize((<ts.VariableStatement>node).declarationList.declarations[0]));
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
output.push(
|
|
79
|
+
{
|
|
80
|
+
module: serialize(node),
|
|
81
|
+
members
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const visit = node => {
|
|
87
|
+
switch(node.kind) {
|
|
88
|
+
case(ts.SyntaxKind.InterfaceDeclaration):
|
|
89
|
+
handleInterface(node);
|
|
90
|
+
break;
|
|
91
|
+
|
|
92
|
+
case(ts.SyntaxKind.ModuleDeclaration):
|
|
93
|
+
handleModule(node);
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
ts.forEachChild(program.getSourceFile(fileName), visit);
|
|
99
|
+
|
|
100
|
+
return output;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
import Handlebars from "handlebars";
|
|
104
|
+
const snake = s => s.replace(/^[A-Z]/, s => s.toLowerCase()).replace(/[A-Z]/g, s => `_${s.toLowerCase()}`);
|
|
105
|
+
|
|
106
|
+
Handlebars.registerHelper("params", members => {
|
|
107
|
+
return members.map(member => `${snake(member.name)}:${(member.optional || member.nullable) ? " nil" : ""}`).join(", ");
|
|
108
|
+
});
|
|
109
|
+
Handlebars.registerHelper("snake", snake);
|
|
110
|
+
Handlebars.registerHelper("comment", (s, options) => {
|
|
111
|
+
const indent = Array(options.hash.indent + 1).join(" ");
|
|
112
|
+
return s.split("\n").map(s => s.trim()).map(s => `${indent}#${s.length == 0 ? "" : ` ${s}`}`).join("\n");
|
|
113
|
+
});
|
|
114
|
+
Handlebars.registerHelper("local_var", s => {
|
|
115
|
+
const rubyKeywords = ["end", "retry"]
|
|
116
|
+
const snaked = snake(s);
|
|
117
|
+
|
|
118
|
+
if (rubyKeywords.some(k => k == s)) {
|
|
119
|
+
return `binding.local_variable_get(:${snaked})`;
|
|
120
|
+
} else {
|
|
121
|
+
return snake(s);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
Handlebars.registerHelper("const", s => {
|
|
125
|
+
return snake(s).toUpperCase();
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
(async () => {
|
|
129
|
+
if (!fs.existsSync(protocolMdPath)) {
|
|
130
|
+
const res = await fetch(`https://github.com/Microsoft/language-server-protocol/raw/${lspVersion}/protocol.md`);
|
|
131
|
+
createFile(protocolMdPath, await res.text());
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const md = fs.readFileSync(protocolMdPath).toString();
|
|
135
|
+
const typeScriptSource = extractTypeScriptSource(md);
|
|
136
|
+
|
|
137
|
+
const definitions = extractDefinitions(typeScriptSource);
|
|
138
|
+
const interfaces = definitions.filter(d => d.interface);
|
|
139
|
+
const modules = definitions.filter(d => d.module);
|
|
140
|
+
|
|
141
|
+
interfaces.forEach(definition => {
|
|
142
|
+
createFile(path.join(rootDir, "lib", "language_server", "protocol", "interfaces", `${snake(definition.interface.name)}.rb`), Handlebars.compile(`
|
|
143
|
+
module LanguageServer
|
|
144
|
+
module Protocol
|
|
145
|
+
module Interfaces
|
|
146
|
+
{{#if definition.interface.documentation}}
|
|
147
|
+
#
|
|
148
|
+
{{comment definition.interface.documentation indent=6}}
|
|
149
|
+
#
|
|
150
|
+
{{/if}}
|
|
151
|
+
class {{definition.interface.name}}
|
|
152
|
+
def initialize({{params definition.members}})
|
|
153
|
+
@attributes = {}
|
|
154
|
+
|
|
155
|
+
{{#each definition.members}}
|
|
156
|
+
@attributes[:{{name}}] = {{local_var name}}{{#if optional}} if {{local_var name}}{{/if}}
|
|
157
|
+
{{/each}}
|
|
158
|
+
|
|
159
|
+
@attributes.freeze
|
|
160
|
+
end
|
|
161
|
+
{{#each definition.members}}
|
|
162
|
+
|
|
163
|
+
{{#if documentation}}
|
|
164
|
+
#
|
|
165
|
+
{{comment documentation indent=8}}
|
|
166
|
+
#
|
|
167
|
+
{{/if}}
|
|
168
|
+
# @return [{{type}}{{#if nullable}}, nil{{/if}}]
|
|
169
|
+
def {{snake name}}
|
|
170
|
+
attributes.fetch(:{{name}})
|
|
171
|
+
end
|
|
172
|
+
{{/each}}
|
|
173
|
+
|
|
174
|
+
attr_reader :attributes
|
|
175
|
+
|
|
176
|
+
def to_json(*args)
|
|
177
|
+
attributes.to_json(*args)
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
`.slice(1), {noEscape: true})({definition}));
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
modules.forEach(definition => {
|
|
187
|
+
createFile(path.join(rootDir, "lib", "language_server", "protocol", "constants", `${snake(definition.module.name)}.rb`), Handlebars.compile(`
|
|
188
|
+
module LanguageServer
|
|
189
|
+
module Protocol
|
|
190
|
+
module Constants
|
|
191
|
+
{{#if definition.module.documentation}}
|
|
192
|
+
#
|
|
193
|
+
{{comment definition.module.documentation indent=6}}
|
|
194
|
+
#
|
|
195
|
+
{{/if}}
|
|
196
|
+
module {{definition.module.name}}
|
|
197
|
+
{{#each definition.members}}
|
|
198
|
+
{{#if documentation}}
|
|
199
|
+
#
|
|
200
|
+
{{comment documentation indent=8}}
|
|
201
|
+
#
|
|
202
|
+
{{/if}}
|
|
203
|
+
{{const name}} = {{value}}
|
|
204
|
+
{{/each}}
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
`.slice(1), {noEscape: true})({definition}));
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
createFile(path.join(rootDir, "lib", "language_server", "protocol", "interfaces.rb"), Handlebars.compile(`
|
|
213
|
+
{{#each interfaces}}
|
|
214
|
+
require "language_server/protocol/interfaces/{{snake interface.name}}"
|
|
215
|
+
{{/each}}
|
|
216
|
+
`.slice(1), {noEscape: true})({interfaces}));
|
|
217
|
+
|
|
218
|
+
createFile(path.join(rootDir, "lib", "language_server", "protocol", "constants.rb"), Handlebars.compile(`
|
|
219
|
+
{{#each modules}}
|
|
220
|
+
require "language_server/protocol/constants/{{snake module.name}}"
|
|
221
|
+
{{/each}}
|
|
222
|
+
`.slice(1), {noEscape: true})({modules}));
|
|
223
|
+
|
|
224
|
+
})();
|