1
1
mirror of https://github.com/github/semantic.git synced 2024-12-01 09:15:01 +03:00

Fix ruby function v. method calls

This commit is contained in:
Timothy Clem 2016-11-04 14:49:39 -07:00
parent 8b425e0a91
commit 961ea9a1de
6 changed files with 373 additions and 15 deletions

View File

@ -43,12 +43,10 @@ termConstructor source sourceSpan name range children
("conditional", condition : cases) -> S.Ternary condition cases
("conditional", _ ) -> S.Error children
("function_call", _) -> case children of
[ member, args ] |
category (extract member) == MemberAccess,
category (extract args) == Args -> case toList (unwrap member) of
[target, method] -> S.MethodCall target method (toList (unwrap args))
_ -> S.Error children
[ function, args ] | category (extract args) == Args -> S.FunctionCall function (toList (unwrap args))
member : args | category (extract member) == MemberAccess -> case toList (unwrap member) of
[target, method] -> S.MethodCall target method (toList . unwrap =<< args)
_ -> S.Error children
function : args -> S.FunctionCall function (toList . unwrap =<< args)
_ -> S.Error children
("hash", _) -> S.Object $ foldMap toTuple children
("if_modifier", [ lhs, condition ]) -> S.If condition [lhs]
@ -107,7 +105,9 @@ termConstructor source sourceSpan name range children
where
withDefaultInfo syntax = do
sourceSpan' <- sourceSpan
pure $! cofree ((range .: categoryForRubyName name .: sourceSpan' .: RNil) :< syntax)
pure $! case syntax of
S.MethodCall{} -> cofree ((range .: MethodCall .: sourceSpan' .: RNil) :< syntax)
_ -> cofree ((range .: categoryForRubyName name .: sourceSpan' .: RNil) :< syntax)
categoryForRubyName :: Text -> Category
categoryForRubyName = \case

View File

@ -0,0 +1,353 @@
[{
"testCaseDescription": "ruby-method-calls-insert-test",
"expectedResult": {
"changes": {
"method-calls.rb": [
{
"span": {
"insert": {
"start": [
1,
1
],
"end": [
1,
8
]
}
},
"summary": "Added the 'x.foo()' method call"
}
]
},
"errors": {}
},
"filePaths": [
"method-calls.rb"
],
"patch": [
"diff --git a/method-calls.rb b/method-calls.rb",
"index e69de29..5831d31 100644",
"--- a/method-calls.rb",
"+++ b/method-calls.rb",
"@@ -0,0 +1 @@",
"+x.foo()"
],
"gitDir": "test/corpus/repos/ruby",
"shas": "17903b081197a8af07c0566effcb951a5c2b4e92..e934fefb49abf087c33e1240f8f6dd8750461981"
}
,{
"testCaseDescription": "ruby-method-calls-replacement-insert-test",
"expectedResult": {
"changes": {
"method-calls.rb": [
{
"span": {
"insert": {
"start": [
1,
1
],
"end": [
1,
6
]
}
},
"summary": "Added the 'bar()' function call"
},
{
"span": {
"insert": {
"start": [
2,
1
],
"end": [
2,
8
]
}
},
"summary": "Added the 'x.foo()' method call"
}
]
},
"errors": {}
},
"filePaths": [
"method-calls.rb"
],
"patch": [
"diff --git a/method-calls.rb b/method-calls.rb",
"index 5831d31..ce891a7 100644",
"--- a/method-calls.rb",
"+++ b/method-calls.rb",
"@@ -1 +1,3 @@",
"+bar()",
"+x.foo()",
" x.foo()"
],
"gitDir": "test/corpus/repos/ruby",
"shas": "e934fefb49abf087c33e1240f8f6dd8750461981..aa456894a021e11601d5c5545633e8f9391038a9"
}
,{
"testCaseDescription": "ruby-method-calls-delete-insert-test",
"expectedResult": {
"changes": {
"method-calls.rb": [
{
"span": {
"insert": {
"start": [
1,
1
],
"end": [
1,
8
]
}
},
"summary": "Added the 'x.foo()' method call"
},
{
"span": {
"delete": {
"start": [
1,
1
],
"end": [
1,
6
]
}
},
"summary": "Deleted the 'bar()' function call"
}
]
},
"errors": {}
},
"filePaths": [
"method-calls.rb"
],
"patch": [
"diff --git a/method-calls.rb b/method-calls.rb",
"index ce891a7..472abf1 100644",
"--- a/method-calls.rb",
"+++ b/method-calls.rb",
"@@ -1,3 +1,3 @@",
"-bar()",
"+x.foo()",
" x.foo()",
" x.foo()"
],
"gitDir": "test/corpus/repos/ruby",
"shas": "aa456894a021e11601d5c5545633e8f9391038a9..526f90542e5291bf410c4f56e69c47282675bd1c"
}
,{
"testCaseDescription": "ruby-method-calls-replacement-test",
"expectedResult": {
"changes": {
"method-calls.rb": [
{
"span": {
"insert": {
"start": [
1,
1
],
"end": [
1,
6
]
}
},
"summary": "Added the 'bar()' function call"
},
{
"span": {
"delete": {
"start": [
1,
1
],
"end": [
1,
8
]
}
},
"summary": "Deleted the 'x.foo()' method call"
}
]
},
"errors": {}
},
"filePaths": [
"method-calls.rb"
],
"patch": [
"diff --git a/method-calls.rb b/method-calls.rb",
"index 472abf1..ce891a7 100644",
"--- a/method-calls.rb",
"+++ b/method-calls.rb",
"@@ -1,3 +1,3 @@",
"-x.foo()",
"+bar()",
" x.foo()",
" x.foo()"
],
"gitDir": "test/corpus/repos/ruby",
"shas": "526f90542e5291bf410c4f56e69c47282675bd1c..7c5ce020e41d5b01f7ea9f88acf3386f426e01e6"
}
,{
"testCaseDescription": "ruby-method-calls-delete-replacement-test",
"expectedResult": {
"changes": {
"method-calls.rb": [
{
"span": {
"delete": {
"start": [
1,
1
],
"end": [
1,
6
]
}
},
"summary": "Deleted the 'bar()' function call"
},
{
"span": {
"delete": {
"start": [
2,
1
],
"end": [
2,
8
]
}
},
"summary": "Deleted the 'x.foo()' method call"
},
{
"span": {
"insert": {
"start": [
2,
1
],
"end": [
2,
6
]
}
},
"summary": "Added the 'bar()' function call"
}
]
},
"errors": {}
},
"filePaths": [
"method-calls.rb"
],
"patch": [
"diff --git a/method-calls.rb b/method-calls.rb",
"index ce891a7..6c5bbe0 100644",
"--- a/method-calls.rb",
"+++ b/method-calls.rb",
"@@ -1,3 +1,2 @@",
"-bar()",
"-x.foo()",
" x.foo()",
"+bar()"
],
"gitDir": "test/corpus/repos/ruby",
"shas": "7c5ce020e41d5b01f7ea9f88acf3386f426e01e6..ee7be1e9e40189aa48d053b3891b9f9ad093db4e"
}
,{
"testCaseDescription": "ruby-method-calls-delete-test",
"expectedResult": {
"changes": {
"method-calls.rb": [
{
"span": {
"delete": {
"start": [
1,
1
],
"end": [
1,
8
]
}
},
"summary": "Deleted the 'x.foo()' method call"
}
]
},
"errors": {}
},
"filePaths": [
"method-calls.rb"
],
"patch": [
"diff --git a/method-calls.rb b/method-calls.rb",
"index 6c5bbe0..4be2e26 100644",
"--- a/method-calls.rb",
"+++ b/method-calls.rb",
"@@ -1,2 +1 @@",
"-x.foo()",
" bar()"
],
"gitDir": "test/corpus/repos/ruby",
"shas": "ee7be1e9e40189aa48d053b3891b9f9ad093db4e..beafe8aef216cb2b54edb534e94edb3fd5138052"
}
,{
"testCaseDescription": "ruby-method-calls-delete-rest-test",
"expectedResult": {
"changes": {
"method-calls.rb": [
{
"span": {
"delete": {
"start": [
1,
1
],
"end": [
1,
6
]
}
},
"summary": "Deleted the 'bar()' function call"
}
]
},
"errors": {}
},
"filePaths": [
"method-calls.rb"
],
"patch": [
"diff --git a/method-calls.rb b/method-calls.rb",
"index 4be2e26..e69de29 100644",
"--- a/method-calls.rb",
"+++ b/method-calls.rb",
"@@ -1 +0,0 @@",
"-bar()"
],
"gitDir": "test/corpus/repos/ruby",
"shas": "beafe8aef216cb2b54edb534e94edb3fd5138052..eb51a430951de620d64e6e92df9603e953708321"
}]

View File

@ -101,7 +101,7 @@
]
}
},
"summary": "Added the 'foo.bar()' function call"
"summary": "Added the 'foo.bar()' method call"
},
{
"span": {
@ -283,7 +283,7 @@
]
}
},
"summary": "Deleted the 'foo.bar()' function call"
"summary": "Deleted the 'foo.bar()' method call"
},
{
"span": {
@ -375,7 +375,7 @@
]
}
},
"summary": "Added the 'foo.bar()' function call"
"summary": "Added the 'foo.bar()' method call"
},
{
"span": {
@ -665,7 +665,7 @@
]
}
},
"summary": "Deleted the 'foo.bar()' function call"
"summary": "Deleted the 'foo.bar()' method call"
},
{
"span": {

View File

@ -5,9 +5,9 @@
"repoUrl": "https://github.com/diff-fixtures/ruby.git",
"syntaxes": [
{
"syntax": "module",
"insert": "module Foo\nend",
"replacement": "module Foo\n def bar\nend\nend"
"syntax": "method-calls",
"insert": "x.foo()",
"replacement": "bar()"
}
]
}

View File

@ -110,6 +110,11 @@
"insert": "print\nfoo.bar\nbar",
"replacement": "print(\"hello world\")\nfoo.bar()\nbar 2, 3\nbar(2, 3)"
},
{
"syntax": "method-calls",
"insert": "x.foo()",
"replacement": "bar()"
},
{
"syntax": "class",
"insert": "class Foo < Super\n def test; end\nend",

@ -1 +1 @@
Subproject commit 118c643eafd1e37132a89af409f899e58621d0e4
Subproject commit eb51a430951de620d64e6e92df9603e953708321