Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

folding multiline decorators #6

Open
pmav99 opened this issue Sep 1, 2022 · 2 comments
Open

folding multiline decorators #6

pmav99 opened this issue Sep 1, 2022 · 2 comments

Comments

@pmav99
Copy link

pmav99 commented Sep 1, 2022

The folding is not working really well when you are using multiline decorators. For example, using some fastapi code:

@router.get(
    "/all",
    response_model=Page[models.CollectionRecordView],
    summary="Retrieve a List of all CollectionRecords"
)
def view_collection_record_all(
    db_session: Session = Depends(get_db),
    params: Params = Depends(),
    search: Optional[str] = None,
    sort: Optional[list[str]] = Query(None, regex=SORT_STRING_REGEX),
):
    collection_records = service.get_all(db_session=db_session, search=search, sort_string=sort)
    if not collection_records:
        raise HTTPException(status_code=404, detail=f"No collection_records have been created")
    return paginate(collection_records, params)

Results in
image

If we force the decorator arguments to be on a single line we get this instead which is obviously much better but the linters are complaining:

image

So, for the multiline case, I am not sure if it is possible to achieve the following but, I think that something like this would be ideal:

@router.get( ... ) (3)
def view_collection_record_all( ... ) (8)
@eddiebergman
Copy link
Owner

eddiebergman commented Sep 1, 2022

Interesting, I seem to get the behaviour where the decorators are not folded at all, which honestly has the other effect where sometimes the decorator is too many lines and I would like that folded as a seperate entity as you show in the last block.

I remember looking into it but it's hard because I think tree sitter see's it as something different from the function, i.e. it's a seperate block of code so tying them together is difficult.

I don't really have time for the next while to look into it but you can use treesitter-playground to see how the structure looks and all the folding syntax is contained here. I think the python treesitter parser is not actively maintained so I don't see it being solved on their end anytime soon either.

Thanks for raising an issue though :)

@eddiebergman
Copy link
Owner

Can you let me know if the recent merge #10 works for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants