GithubHelp home page GithubHelp logo

code_diff's People

Contributors

cedricrupb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

code_diff's Issues

Information about the position of the modified lines / tokens

Hi, thank you very much for implementing this library.

I would like to have more information about its use for the following scenario: given two code snippets, I would like to know the location of the lines and tokens that have been changed or added.
Let's take this case as an example:

Code

output = cd.difference(
'''
String var = "Hello";
int x = x + 1 + 8;
List list = new ArrayList<>();
''',
'''
String var1 = "Hello";
int x = x + 1;
List list = new ArrayList<>();
List list2 = new ArrayList<>();
''',
lang = "java")

As you can see, the difference between the two code snippets lies in line 1 (renaming the variable 'var' to 'var1'), line 2 (adding a new addition), and finally, line 4 (adding a new statement).

The output of this execution is as follows:

Output

[
Insert((local_variable_declaration, N0), (program, line 1:8 - 4:4), 3),
Insert((generic_type, N1), N0, 0),
Insert((variable_declarator, N2), N0, 1),
Insert(;:;, N0, 2),
Update((identifier:var, line 1:15 - 1:18), var1),
Move((binary_expression, line 2:16 - 2:21), (variable_declarator, line 2:12 - 2:25), 2),
Insert(type_identifier:List, N1, 0),
Insert((type_arguments, N3), N1, 1),
Insert(identifier:list2, N2, 0),
Insert(=:=, N2, 1),
Insert((object_creation_expression, N4), N2, 2),
Insert(<:<, N3, 0),
Insert(type_identifier:String, N3, 1),
Insert(>:>, N3, 2),
Insert(new:new, N4, 0),
Insert((generic_type, N5), N4, 1),
Insert((argument_list, N6), N4, 2),
Insert(type_identifier:ArrayList, N5, 0),
Insert((type_arguments, N7), N5, 1),
Insert((:(, N6, 0),
Insert():), N6, 1),
Insert(<:<, N7, 0),
Insert(>:>, N7, 1),
Delete((+:+, line 2:22 - 2:23)),
Delete((decimal_integer_literal:8, line 2:24 - 2:25)),
Delete((binary_expression, line 2:16 - 2:25))
]

From this output, however, I cannot get the information I mentioned above. Does the library support this functionality or is there a way to get this information?

Thanks again for the support.

The target node information is not available in update operation

I have a use case where I need the information of the target nodes in the EditScript. However, only the target node text is passed to the Update objects. For example the code at code_diff/__init__.py:L200 is

if source_ast.type == target_ast.type and len(source_ast.children) == 0 and len(target_ast.children) == 0:
  # Both nodes are tokens of the same type 
  # Only an update is required
  return EditScript([Update(source_ast, target_ast.text)])

I suggest that the last line to be replaced with:

return EditScript([Update(source_ast, target_ast)])

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.