kbrose / vsc-python-indent

Correctly indent python code on the fly, in Visual Studio Code.
https://marketplace.visualstudio.com/items?itemName=KevinRose.vsc-python-indent
MIT License
82 stars 19 forks source link

Fail to generate Indentation for a specific file and code copied from that file #115

Closed Ruiz-Reginald closed 10 months ago

Ruiz-Reginald commented 10 months ago

What the code looks like before pressing enter:

    def __init__(self, data=None, dim=None, init_value=0):
        if data != None: # 输入data不为空的情况
            self.data = data
            self.dim = (len(data), len(data[0]))
        elif dim == None: # data和dim全为空的情况
            raise ValueError("data和dim不能全为None")
        else: # data为空,dim和init_value决定矩阵的情况
            self.data = [[init_value for column_num in range(0, dim[1])] for row_num in range(0, dim[0])]|
            self.dim = dim```

What I want the code to look like after pressing `enter`:

```python
    def __init__(self, data=None, dim=None, init_value=0):
        if data != None: # 输入data不为空的情况
            self.data = data
            self.dim = (len(data), len(data[0]))
        elif dim == None: # data和dim全为空的情况
            raise ValueError("data和dim不能全为None")
        else: # data为空,dim和init_value决定矩阵的情况
            self.data = [[init_value for column_num in range(0, dim[1])] for row_num in range(0, dim[0])]
            self.dim = dim
                        |

What the code actually looks like after pressing enter:

    def __init__(self, data=None, dim=None, init_value=0):
        if data != None: # 输入data不为空的情况
            self.data = data
            self.dim = (len(data), len(data[0]))
        elif dim == None: # data和dim全为空的情况
            raise ValueError("data和dim不能全为None")
        else: # data为空,dim和init_value决定矩阵的情况
            self.data = [[init_value for column_num in range(0, dim[1])] for row_num in range(0, dim[0])]
            self.dim = dim
 |

before:

image

after:

image
Ruiz-Reginald commented 10 months ago

it's the file itself that causes the problem, after formatting the file, the problem is gone