Skip to content

Commit 803333f

Browse files
authored
Merge pull request #13 from mtsmfm/add-character
Add character
2 parents fe3223c + 4a7ceb3 commit 803333f

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

lib/language_server/project/node.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def attribute_names
2121
end
2222
end
2323

24-
attributes :lineno, :path
24+
attributes :lineno, :character, :path
2525

2626
def remote_path; path.remote_path; end
2727
def local_path; path.local_path; end

lib/language_server/project/parser.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ def initialize(src, path)
3232

3333
private
3434

35+
alias character column
36+
3537
attr_reader :path
3638

3739
def lineno
@@ -40,13 +42,13 @@ def lineno
4042
end
4143

4244
def on_const(name)
43-
Constant.new(namespaces: [], name: name, value: nil, lineno: lineno, path: path).tap do |c|
45+
build_node(Constant, namespaces: [], name: name, value: nil).tap do |c|
4446
@current_constants.push(c)
4547
end
4648
end
4749

4850
def on_int(value)
49-
LiteralValue.new(value: value.to_i, lineno: lineno, path: path)
51+
build_node(LiteralValue, value: value.to_i)
5052
end
5153

5254
def on_stmts_add(*args)
@@ -62,19 +64,23 @@ def on_assign(left, right)
6264

6365
def on_module(constant, children)
6466
cn = children.select {|child| child.instance_of?(Constant) || child.instance_of?(Module) || child.instance_of?(Class)}
65-
Module.new(constant: constant, lineno: lineno, path: path, children: cn).tap do |m|
67+
build_node(Module, constant: constant, children: cn).tap do |m|
6668
result.modules << m
6769
cn.each {|child| child.unshift_namespace(m) }
6870
end
6971
end
7072

7173
def on_class(constant, superclass, children)
7274
cn = children.select {|child| child.instance_of?(Constant) || child.instance_of?(Module) || child.instance_of?(Class)}
73-
Class.new(constant: constant, superclass: superclass, lineno: lineno, path: path, children: cn).tap do |c|
75+
build_node(Class, constant: constant, superclass: superclass, children: cn).tap do |c|
7476
result.classes << c
7577
cn.each {|child| child.unshift_namespace(c) }
7678
end
7779
end
80+
81+
def build_node(klass, **args)
82+
klass.new({lineno: lineno, character: character, path: path}.merge(args))
83+
end
7884
end
7985
end
8086
end

0 commit comments

Comments
 (0)