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

How to insert named arguments in function snippet #1115

Closed
sellithy opened this issue Oct 11, 2024 · 1 comment
Closed

How to insert named arguments in function snippet #1115

sellithy opened this issue Oct 11, 2024 · 1 comment
Assignees

Comments

@sellithy
Copy link

sellithy commented Oct 11, 2024

Apologies if this is not the correct channel to ask this

If I have

def foo(param1: float, param2: float): ...

I want to type foo and get

foo(
    param1=$1,
    param2=$2,
)$0
  1. Does coc-pyright support this right now?
    a. I think I've done enough research to say no because Pyright itself doesn't but want to double check
    b. I know, however, that coc-pyright add () after function names which Pyright itself doesn't add (code link)
  2. If not, would this be a good addition to coc-pyright (not Pyright)?
  3. If yes, how hard would it be to implement and can I get some pointers on how to implement it?
@fannheyward
Copy link
Owner

fannheyward commented Oct 11, 2024

coc-pyright doesn't support this, and there's no way to implement this because Pyright didn't return parameters info, let's use foo for example, here's what Pyright returns:

{
  label: 'foo',
  kind: 3,
  data: {
    uri: 'file:///Users/fannheyward/src/hello-p/meta.py',
    position: { line: 19, character: 3 },
    symbolLabel: 'foo'
  },
  sortText: '09.9999.foo'
}

Only label foo, no parameters/arguments.

Then coc.nvim requests to resolve the completion item:

{
    "label": "foo",
    "kind": 3,
    "data": {
        "uri": "file:///Users/fannheyward/src/hello-p/meta.py",
        "position": {
            "line": 20,
            "character": 3
        },
        "symbolLabel": "foo"
    },
    "sortText": "09.9999.foo",
    "insertText": "foo($1)$0",
    "insertTextFormat": 2,
    "documentation": {
        "kind": "markdown",
        "value": "```python\ndef foo(\n    param1: float,\n    param2: float\n) -> None\n```"
    }
}

The markdown document is what you got in the floating window. Can we use the document to implement this? yes or no, we need to resolve all items, parses the document, add parameters to insertText like https://github.com/fannheyward/coc-pyright/blob/master/src/middleware.ts#L121, this is too expensive because Pyright returns 120+ items after inputing f. Also, use the markdown document maybe fail because it's document, maybe includes additional info that needs to deal.

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