Class: Rsense::Server::Code
- Inherits:
-
Object
- Object
- Rsense::Server::Code
- Defined in:
- lib/rsense/server/code.rb
Constant Summary collapse
- TYPE_INFERENCE_METHOD_NAME =
Rsense::Server::Command::TYPE_INFERENCE_METHOD_NAME
- FIND_DEFINITION_METHOD_NAME_PREFIX =
Rsense::Server::Command::FIND_DEFINITION_METHOD_NAME_PREFIX
Instance Attribute Summary collapse
-
#lines ⇒ Object
Returns the value of attribute lines.
Instance Method Summary collapse
-
#initialize(code_str) ⇒ Code
constructor
A new instance of Code.
- #inject_definition_marker(injection, location) ⇒ Object
- #inject_inference_marker(location) ⇒ Object
Constructor Details
#initialize(code_str) ⇒ Code
Returns a new instance of Code.
8 9 10 |
# File 'lib/rsense/server/code.rb', line 8 def initialize(code_str) @lines = code_str.split("\n") end |
Instance Attribute Details
#lines ⇒ Object
Returns the value of attribute lines.
4 5 6 |
# File 'lib/rsense/server/code.rb', line 4 def lines @lines end |
Instance Method Details
#inject_definition_marker(injection, location) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rsense/server/code.rb', line 28 def inject_definition_marker(injection, location) row = location["row"] - 1 column = location["column"] - 1 lines = @lines.clone line = lines[row] match = line.slice(0, column).match(/.*(?:\.|::|\s)(\w+?[!?]?)/) start = match.end(0) line.insert(start - 1, injection) lines.join("\n") end |
#inject_inference_marker(location) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rsense/server/code.rb', line 12 def inject_inference_marker(location) row = location["row"] - 1 column = location["column"] - 1 lines = @lines.clone line = lines[row] return lines.join("\n") unless line && line.length >= column - 1 && column > 1 if line.slice(column - 1).end_with?(".") line.insert(column, TYPE_INFERENCE_METHOD_NAME) elsif line.slice(column - 2..column - 1).end_with?("::") line.insert(column, TYPE_INFERENCE_METHOD_NAME) else line.insert(column, ".#{TYPE_INFERENCE_METHOD_NAME}") end lines.join("\n") end |