language_server 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/bin/console +6 -0
  3. data/circle.yml +0 -1
  4. data/docker-compose.yml +2 -7
  5. data/language_server.gemspec +1 -0
  6. data/lib/language_server/completion_provider/ad_hoc.rb +6 -6
  7. data/lib/language_server/completion_provider/rcodetools.rb +3 -5
  8. data/lib/language_server/definition_provider/ad_hoc.rb +34 -0
  9. data/lib/language_server/logger.rb +37 -0
  10. data/lib/language_server/project/node.rb +65 -1
  11. data/lib/language_server/project/parser.rb +40 -10
  12. data/lib/language_server/project.rb +20 -3
  13. data/lib/language_server/version.rb +1 -1
  14. data/lib/language_server.rb +43 -24
  15. metadata +19 -110
  16. data/Dockerfile-node.development +0 -6
  17. data/bin/generate_files +0 -5
  18. data/lib/language_server/protocol/constants/completion_item_kind.rb +0 -29
  19. data/lib/language_server/protocol/constants/diagnostic_severity.rb +0 -24
  20. data/lib/language_server/protocol/constants/document_highlight_kind.rb +0 -23
  21. data/lib/language_server/protocol/constants/error_codes.rb +0 -18
  22. data/lib/language_server/protocol/constants/file_change_type.rb +0 -23
  23. data/lib/language_server/protocol/constants/initialize_error.rb +0 -15
  24. data/lib/language_server/protocol/constants/insert_text_format.rb +0 -27
  25. data/lib/language_server/protocol/constants/message_type.rb +0 -24
  26. data/lib/language_server/protocol/constants/symbol_kind.rb +0 -29
  27. data/lib/language_server/protocol/constants/text_document_save_reason.rb +0 -24
  28. data/lib/language_server/protocol/constants/text_document_sync_kind.rb +0 -26
  29. data/lib/language_server/protocol/constants.rb +0 -11
  30. data/lib/language_server/protocol/interfaces/apply_workspace_edit_params.rb +0 -29
  31. data/lib/language_server/protocol/interfaces/apply_workspace_edit_response.rb +0 -29
  32. data/lib/language_server/protocol/interfaces/cancel_params.rb +0 -29
  33. data/lib/language_server/protocol/interfaces/client_capabilities.rb +0 -47
  34. data/lib/language_server/protocol/interfaces/code_action_context.rb +0 -33
  35. data/lib/language_server/protocol/interfaces/code_action_params.rb +0 -50
  36. data/lib/language_server/protocol/interfaces/code_lens.rb +0 -55
  37. data/lib/language_server/protocol/interfaces/code_lens_options.rb +0 -32
  38. data/lib/language_server/protocol/interfaces/code_lens_params.rb +0 -29
  39. data/lib/language_server/protocol/interfaces/code_lens_registration_options.rb +0 -29
  40. data/lib/language_server/protocol/interfaces/command.rb +0 -48
  41. data/lib/language_server/protocol/interfaces/completion_item.rb +0 -145
  42. data/lib/language_server/protocol/interfaces/completion_list.rb +0 -43
  43. data/lib/language_server/protocol/interfaces/completion_options.rb +0 -42
  44. data/lib/language_server/protocol/interfaces/completion_registration_options.rb +0 -39
  45. data/lib/language_server/protocol/interfaces/diagnostic.rb +0 -67
  46. data/lib/language_server/protocol/interfaces/did_change_configuration_params.rb +0 -29
  47. data/lib/language_server/protocol/interfaces/did_change_text_document_params.rb +0 -40
  48. data/lib/language_server/protocol/interfaces/did_change_watched_files_params.rb +0 -29
  49. data/lib/language_server/protocol/interfaces/did_close_text_document_params.rb +0 -29
  50. data/lib/language_server/protocol/interfaces/did_open_text_document_params.rb +0 -29
  51. data/lib/language_server/protocol/interfaces/did_save_text_document_params.rb +0 -39
  52. data/lib/language_server/protocol/interfaces/document_filter.rb +0 -47
  53. data/lib/language_server/protocol/interfaces/document_formatting_params.rb +0 -38
  54. data/lib/language_server/protocol/interfaces/document_highlight.rb +0 -43
  55. data/lib/language_server/protocol/interfaces/document_link.rb +0 -42
  56. data/lib/language_server/protocol/interfaces/document_link_options.rb +0 -32
  57. data/lib/language_server/protocol/interfaces/document_link_params.rb +0 -29
  58. data/lib/language_server/protocol/interfaces/document_link_registration_options.rb +0 -29
  59. data/lib/language_server/protocol/interfaces/document_on_type_formatting_options.rb +0 -41
  60. data/lib/language_server/protocol/interfaces/document_on_type_formatting_params.rb +0 -56
  61. data/lib/language_server/protocol/interfaces/document_on_type_formatting_registration_options.rb +0 -38
  62. data/lib/language_server/protocol/interfaces/document_range_formatting_params.rb +0 -47
  63. data/lib/language_server/protocol/interfaces/document_symbol_params.rb +0 -29
  64. data/lib/language_server/protocol/interfaces/execute_command_options.rb +0 -32
  65. data/lib/language_server/protocol/interfaces/execute_command_params.rb +0 -38
  66. data/lib/language_server/protocol/interfaces/execute_command_registration_options.rb +0 -32
  67. data/lib/language_server/protocol/interfaces/file_event.rb +0 -41
  68. data/lib/language_server/protocol/interfaces/formatting_options.rb +0 -41
  69. data/lib/language_server/protocol/interfaces/hover.rb +0 -42
  70. data/lib/language_server/protocol/interfaces/initialize_error.rb +0 -35
  71. data/lib/language_server/protocol/interfaces/initialize_params.rb +0 -79
  72. data/lib/language_server/protocol/interfaces/initialize_result.rb +0 -29
  73. data/lib/language_server/protocol/interfaces/location.rb +0 -32
  74. data/lib/language_server/protocol/interfaces/log_message_params.rb +0 -38
  75. data/lib/language_server/protocol/interfaces/message.rb +0 -26
  76. data/lib/language_server/protocol/interfaces/message_action_item.rb +0 -29
  77. data/lib/language_server/protocol/interfaces/notification_message.rb +0 -38
  78. data/lib/language_server/protocol/interfaces/parameter_information.rb +0 -44
  79. data/lib/language_server/protocol/interfaces/position.rb +0 -38
  80. data/lib/language_server/protocol/interfaces/publish_diagnostics_params.rb +0 -38
  81. data/lib/language_server/protocol/interfaces/range.rb +0 -38
  82. data/lib/language_server/protocol/interfaces/reference_context.rb +0 -29
  83. data/lib/language_server/protocol/interfaces/reference_params.rb +0 -26
  84. data/lib/language_server/protocol/interfaces/registration.rb +0 -51
  85. data/lib/language_server/protocol/interfaces/registration_params.rb +0 -26
  86. data/lib/language_server/protocol/interfaces/rename_params.rb +0 -49
  87. data/lib/language_server/protocol/interfaces/request_message.rb +0 -47
  88. data/lib/language_server/protocol/interfaces/response_error.rb +0 -48
  89. data/lib/language_server/protocol/interfaces/response_message.rb +0 -48
  90. data/lib/language_server/protocol/interfaces/save_options.rb +0 -32
  91. data/lib/language_server/protocol/interfaces/server_capabilities.rb +0 -183
  92. data/lib/language_server/protocol/interfaces/show_message_params.rb +0 -38
  93. data/lib/language_server/protocol/interfaces/show_message_request_params.rb +0 -47
  94. data/lib/language_server/protocol/interfaces/signature_help.rb +0 -64
  95. data/lib/language_server/protocol/interfaces/signature_help_options.rb +0 -33
  96. data/lib/language_server/protocol/interfaces/signature_help_registration_options.rb +0 -30
  97. data/lib/language_server/protocol/interfaces/signature_information.rb +0 -54
  98. data/lib/language_server/protocol/interfaces/symbol_information.rb +0 -60
  99. data/lib/language_server/protocol/interfaces/text_document_change_registration_options.rb +0 -33
  100. data/lib/language_server/protocol/interfaces/text_document_client_capabilities.rb +0 -155
  101. data/lib/language_server/protocol/interfaces/text_document_content_change_event.rb +0 -51
  102. data/lib/language_server/protocol/interfaces/text_document_edit.rb +0 -38
  103. data/lib/language_server/protocol/interfaces/text_document_identifier.rb +0 -29
  104. data/lib/language_server/protocol/interfaces/text_document_item.rb +0 -57
  105. data/lib/language_server/protocol/interfaces/text_document_position_params.rb +0 -38
  106. data/lib/language_server/protocol/interfaces/text_document_registration_options.rb +0 -30
  107. data/lib/language_server/protocol/interfaces/text_document_save_registration_options.rb +0 -29
  108. data/lib/language_server/protocol/interfaces/text_document_sync_options.rb +0 -66
  109. data/lib/language_server/protocol/interfaces/text_edit.rb +0 -40
  110. data/lib/language_server/protocol/interfaces/unregistration.rb +0 -42
  111. data/lib/language_server/protocol/interfaces/unregistration_params.rb +0 -26
  112. data/lib/language_server/protocol/interfaces/versioned_text_document_identifier.rb +0 -29
  113. data/lib/language_server/protocol/interfaces/will_save_text_document_params.rb +0 -41
  114. data/lib/language_server/protocol/interfaces/workspace_client_capabilites.rb +0 -78
  115. data/lib/language_server/protocol/interfaces/workspace_edit.rb +0 -40
  116. data/lib/language_server/protocol/interfaces/workspace_symbol_params.rb +0 -32
  117. data/lib/language_server/protocol/interfaces.rb +0 -87
  118. data/lib/language_server/protocol/stdio/reader.rb +0 -37
  119. data/lib/language_server/protocol/stdio/writer.rb +0 -38
  120. data/lib/language_server/protocol/stdio.rb +0 -2
  121. data/scripts/generateFiles.ts +0 -224
  122. data/yarn.lock +0 -295
@@ -1,42 +0,0 @@
1
- module LanguageServer
2
- module Protocol
3
- module Interfaces
4
- #
5
- # General parameters to unregister a capability.
6
- #
7
- class Unregistration
8
- def initialize(id:, method:)
9
- @attributes = {}
10
-
11
- @attributes[:id] = id
12
- @attributes[:method] = method
13
-
14
- @attributes.freeze
15
- end
16
-
17
- #
18
- # The id used to unregister the request or notification. Usually an id
19
- # provided during the register request.
20
- #
21
- # @return [string]
22
- def id
23
- attributes.fetch(:id)
24
- end
25
-
26
- #
27
- # The method / capability to unregister for.
28
- #
29
- # @return [string]
30
- def method
31
- attributes.fetch(:method)
32
- end
33
-
34
- attr_reader :attributes
35
-
36
- def to_json(*args)
37
- attributes.to_json(*args)
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,26 +0,0 @@
1
- module LanguageServer
2
- module Protocol
3
- module Interfaces
4
- class UnregistrationParams
5
- def initialize(unregisterations:)
6
- @attributes = {}
7
-
8
- @attributes[:unregisterations] = unregisterations
9
-
10
- @attributes.freeze
11
- end
12
-
13
- # @return [Unregistration[]]
14
- def unregisterations
15
- attributes.fetch(:unregisterations)
16
- end
17
-
18
- attr_reader :attributes
19
-
20
- def to_json(*args)
21
- attributes.to_json(*args)
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,29 +0,0 @@
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
@@ -1,41 +0,0 @@
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
@@ -1,78 +0,0 @@
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
@@ -1,40 +0,0 @@
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
@@ -1,32 +0,0 @@
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
@@ -1,87 +0,0 @@
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"
@@ -1,37 +0,0 @@
1
- module LanguageServer
2
- module Protocol
3
- module Stdio
4
- class Reader
5
- def read(&block)
6
- buffer = ""
7
- header_parsed = false
8
- content_length = nil
9
-
10
- while char = STDIN.getc
11
- buffer << char
12
-
13
- unless header_parsed
14
- if buffer[-4..-1] == "\r\n" * 2
15
- content_length = buffer.match(/Content-Length: (\d+)/i)[1].to_i
16
-
17
- header_parsed = true
18
- buffer.clear
19
- end
20
- else
21
- if buffer.bytesize == content_length
22
- LanguageServer.logger.debug("Receive: #{buffer}")
23
-
24
- request = JSON.parse(buffer, symbolize_names: true)
25
-
26
- block.call(request)
27
-
28
- header_parsed = false
29
- buffer.clear
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,38 +0,0 @@
1
- module LanguageServer
2
- module Protocol
3
- module Stdio
4
- class Writer
5
- def respond(id:, result:)
6
- write(id: id, result: result)
7
- end
8
-
9
- def notify(method:, params: {})
10
- write(method: method, params: params)
11
- end
12
-
13
- private
14
-
15
- def write(response)
16
- response_str = response.merge(
17
- jsonrpc: "2.0"
18
- ).to_json
19
-
20
- headers = {
21
- "Content-Length" => response_str.bytesize
22
- }
23
-
24
- headers.each do |k, v|
25
- STDOUT.print "#{k}: #{v}\r\n"
26
- end
27
-
28
- STDOUT.print "\r\n"
29
-
30
- STDOUT.print response_str
31
- STDOUT.flush
32
-
33
- LanguageServer.logger.debug("Response: #{response_str}")
34
- end
35
- end
36
- end
37
- end
38
- end
@@ -1,2 +0,0 @@
1
- require "language_server/protocol/stdio/reader"
2
- require "language_server/protocol/stdio/writer"
@@ -1,224 +0,0 @@
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
- })();