class RubyLanguageServer::CodeFile
Constants
- SYMBOL_KIND
Attributes
diagnostics[RW]
Public Class Methods
build(uri, text)
click to toggle source
# File lib/ruby_language_server/code_file.rb, line 20 def self.build(uri, text) RubyLanguageServer.logger.debug("CodeFile initialize #{uri}") create!(uri: uri, text: text) end
Public Instance Methods
ancestor_scope_name(scope)
click to toggle source
Find the ancestor of this scope with a name and return that. Or nil.
# File lib/ruby_language_server/code_file.rb, line 49 def ancestor_scope_name(scope) return_scope = scope while (return_scope = return_scope.parent) return return_scope.name unless return_scope.name.nil? || return_scope.block_scope? end end
context_at_location(position)
click to toggle source
Returns the context of what is being typed in the given line
# File lib/ruby_language_server/code_file.rb, line 132 def context_at_location(position) lines = text.split("\n") line = lines[position.line] return [] if line.nil? || line.strip.length.zero? LineContext.for(line, position.character) end
refresh_scopes_if_needed()
click to toggle source
# File lib/ruby_language_server/code_file.rb, line 111 def refresh_scopes_if_needed return unless refresh_root_scope RubyLanguageServer.logger.debug("Asking about root_scope for #{uri}") RubyLanguageServer::ScopeData::Variable.where(code_file_id: self).scoping do RubyLanguageServer::ScopeData::Scope.where(code_file_id: self).scoping do self.class.transaction do scopes.clear variables.clear new_root = ScopeParser.new(text).root_scope RubyLanguageServer.logger.debug("new_root.children #{new_root.children.as_json}") if new_root&.children raise ActiveRecord::Rollback if new_root.nil? || new_root.children.blank? update_attribute(:refresh_root_scope, false) new_root end end end end
root_scope()
click to toggle source
# File lib/ruby_language_server/code_file.rb, line 12 def root_scope where(class_type: RubyLanguageServer::ScopeData::Scope::TYPE_ROOT).first end
update_text(new_text)
click to toggle source
# File lib/ruby_language_server/code_file.rb, line 103 def update_text(new_text) RubyLanguageServer.logger.debug("update_text for #{uri}") return true if new_text == text RubyLanguageServer.logger.debug('Changed!') update(text: new_text, refresh_root_scope: true) end