Class: RubyLanguageServer::Server
- Inherits:
-
Object
- Object
- RubyLanguageServer::Server
- Defined in:
- lib/ruby_language_server/server.rb
Defined Under Namespace
Classes: Position
Instance Attribute Summary collapse
-
#io ⇒ Object
Returns the value of attribute io.
Instance Method Summary collapse
-
#initialize(mutex) ⇒ Server
constructor
A new instance of Server.
- #on_initialize(params) ⇒ Object
- #on_initialized(_hash) ⇒ Object
- #on_shutdown(_params) ⇒ Object
- #on_textDocument_completion(params) ⇒ Object
- #on_textDocument_definition(params) ⇒ Object
- #on_textDocument_didChange(params) ⇒ Object
- #on_textDocument_didOpen(params) ⇒ Object
- #on_textDocument_documentSymbol(params) ⇒ Object
- #on_textDocument_hover(params) ⇒ Object
- #on_workspace_didChangeWatchedFiles(params) ⇒ Object
- #send_diagnostics(uri, text) ⇒ Object
Constructor Details
#initialize(mutex) ⇒ Server
Returns a new instance of Server.
10 11 12 |
# File 'lib/ruby_language_server/server.rb', line 10 def initialize(mutex) @mutex = mutex end |
Instance Attribute Details
#io ⇒ Object
Returns the value of attribute io.
8 9 10 |
# File 'lib/ruby_language_server/server.rb', line 8 def io @io end |
Instance Method Details
#on_initialize(params) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ruby_language_server/server.rb', line 14 def on_initialize(params) RubyLanguageServer.logger.info("on_initialize: #{params}") RubyLanguageServer::CodeFile.all # Just to warm up active_record. root_path = params['rootPath'] root_uri = params['rootUri'] @project_manager = ProjectManager.new(root_path, root_uri) @project_manager.scan_all_project_files gem_string = ENV.fetch('ADDITIONAL_GEMS', nil) gem_array = (gem_string.split(',').compact.map(&:strip).reject { |string| string == '' } if gem_string && !gem_string.empty?) @project_manager.install_additional_gems(gem_array) { capabilities: { textDocumentSync: 1, hoverProvider: true, signatureHelpProvider: { triggerCharacters: ['(', ','] }, definitionProvider: true, referencesProvider: true, documentSymbolProvider: true, workspaceSymbolProvider: true, xworkspaceReferencesProvider: true, xdefinitionProvider: true, xdependenciesProvider: true, completionProvider: { resolveProvider: true, triggerCharacters: ['.', '::'] }, codeActionProvider: true, renameProvider: true, executeCommandProvider: { commands: [] }, xpackagesProvider: true } } end |
#on_initialized(_hash) ⇒ Object
52 53 54 |
# File 'lib/ruby_language_server/server.rb', line 52 def on_initialized(_hash) RubyLanguageServer.logger.info("RubyLanguageServer::VERSION #{RubyLanguageServer::VERSION}") end |
#on_shutdown(_params) ⇒ Object
116 117 118 |
# File 'lib/ruby_language_server/server.rb', line 116 def on_shutdown(_params) RubyLanguageServer.logger.info('on_shutdown') end |
#on_textDocument_completion(params) ⇒ Object
107 108 109 110 111 112 113 114 |
# File 'lib/ruby_language_server/server.rb', line 107 def on_textDocument_completion(params) RubyLanguageServer.logger.info("on_textDocument_completion #{params}") uri = uri_from_params(params) position = postition_from_params(params) completions = @project_manager.completion_at(uri, position) RubyLanguageServer.logger.debug("completions: #{completions}") completions end |
#on_textDocument_definition(params) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/ruby_language_server/server.rb', line 79 def on_textDocument_definition(params) RubyLanguageServer.logger.debug("on_textDocument_definition #{params}") uri = uri_from_params(params) position = postition_from_params(params) @project_manager.possible_definitions(uri, position) end |
#on_textDocument_didChange(params) ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/ruby_language_server/server.rb', line 99 def on_textDocument_didChange(params) uri = uri_from_params(params) RubyLanguageServer.logger.debug("on_textDocument_didChange #{uri}") content_changes = params['contentChanges'] text = content_changes.first['text'] send_diagnostics(uri, text) end |
#on_textDocument_didOpen(params) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/ruby_language_server/server.rb', line 91 def on_textDocument_didOpen(params) textDocument = params['textDocument'] uri = textDocument['uri'] RubyLanguageServer.logger.debug("on_textDocument_didOpen #{uri}") text = textDocument['text'] send_diagnostics(uri, text) end |
#on_textDocument_documentSymbol(params) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ruby_language_server/server.rb', line 68 def on_textDocument_documentSymbol(params) RubyLanguageServer.logger.debug('on_textDocument_documentSymbol') RubyLanguageServer.logger.debug(params) uri = uri_from_params(params) # {"kind":"module","line":4,"language":"Ruby","path":"(eval)","pattern":"module RubyLanguageServer","full_name":"RubyLanguageServer","name":"RubyLanguageServer"} symbols = @project_manager.(uri) RubyLanguageServer.logger.debug("symbols #{symbols}") symbols end |
#on_textDocument_hover(params) ⇒ Object
62 63 64 65 66 |
# File 'lib/ruby_language_server/server.rb', line 62 def on_textDocument_hover(params) RubyLanguageServer.logger.debug('on_textDocument_hover') RubyLanguageServer.logger.debug(params) {} end |
#on_workspace_didChangeWatchedFiles(params) ⇒ Object
56 57 58 59 60 |
# File 'lib/ruby_language_server/server.rb', line 56 def on_workspace_didChangeWatchedFiles(params) RubyLanguageServer.logger.debug('on_workspace_didChangeWatchedFiles') RubyLanguageServer.logger.debug(params) {} end |
#send_diagnostics(uri, text) ⇒ Object
86 87 88 89 |
# File 'lib/ruby_language_server/server.rb', line 86 def send_diagnostics(uri, text) hash = @project_manager.update_document_content(uri, text) io.send_notification('textDocument/publishDiagnostics', uri:, diagnostics: hash) end |