github / semantic

Parsing, analyzing, and comparing source code across many languages
8.98k stars 452 forks source link

Getting the line number of the end of a function definition #684

Open hendychua opened 2 years ago

hendychua commented 2 years ago

Hi there,

I would like to get the line number of the end of a function definition. Is there a way to do this?

To give an example, suppose the source code is:

def Foo(x): # line 1
  if x == 42:
    return True
  else:
    return False # line 5

The parsed output would return where the function definition completes, i.e. line 5.

Currently, span.end seems to point to where the symbol name definition ends but not where the whole function ends:

{
  "symbol": "Foo",
  "kind": "Function",
  "line": "def Foo(x):",
  "span": {
    "start": {
      "line": 1,
      "column": 5
    },
    "end": {
      "line": 1,
      "column": 8
    }
  },
  "nodeType": "DEFINITION"
},

Thank you.