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

TypeError: document.getText is not a function #15

Closed
xavier-balesi opened this issue Jul 2, 2022 · 8 comments
Closed

TypeError: document.getText is not a function #15

xavier-balesi opened this issue Jul 2, 2022 · 8 comments

Comments

@xavier-balesi
Copy link

xavier-balesi commented Jul 2, 2022

Hi,
thank you for the plugin, it seems very cool.

I have an error when I run (coc-codeaction-line) then Add docstring for "Line or Selected" by pydocstring:

Error on request (doCodeAction): Vim(return):Error invoking 'doCodeAction' on channel 3 (coc):
TypeError: document.getText is not a function

note that CocCommand pydocstring.runFile works well.

Config:
nvim : v0.8.0-dev+448-g7b2b44bce
coc-pydocstring: 0.7.3
coc is up to date

doc is installed by CocCommand pydocstring.install

@yaegassy
Copy link
Owner

yaegassy commented Jul 2, 2022

Thanks for the issue report. 🙇

I am unable to reproduce this issue in my environment. Can you provide the Python code to reproduce and the steps to reproduce it?

@xavier-balesi
Copy link
Author

xavier-balesi commented Jul 3, 2022

a simple code with which I can reproduce :

def hello(param: str = "world"):
    print(f"hello {param}")

steps:

  • set cursor on the 'h' of 'hello'
  • trigger (coc-codeaction-line) (I use :Telescope coc code_actions for that)
  • the floating window with codeactions-line is shown
  • it contains the line Add docstring for "Line or Selected" by pydocstring
    image
  • select this line then press <CR>
  • the error happens
    image

is the function document.getText must be in CocCommand ? I don't have it :
image

Maybe you have some dependency that I didn't have installed...

@yaegassy
Copy link
Owner

yaegassy commented Jul 3, 2022

Does it work correctly when run without telescope?

@xavier-balesi
Copy link
Author

No it fails by the same way when I call (coc-codeaction-line) :
image
[coc.nvim] Error on notification "doCodeAction": TypeError: document.getText is not a function

But it works well when I call CocCommand pydocstring.runFile for the whole file.

@yaegassy
Copy link
Owner

yaegassy commented Jul 3, 2022

I cannot reproduce this in my environment.

DEMO (mp4):

coc-pydocstring-codeaction-check.mp4

@xavier-balesi
Copy link
Author

I have fix the problem by changing two lines in function "activate"
I am not really confortable with js and COC lib and I'm not able to explain the bug, but now it seems to works well.

  context.subscriptions.push(import_coc4.commands.registerCommand("pydocstring.runAction", async (document, range) => {
    const doc = import_coc4.workspace.getDocument(document.uri);
    let edits;
    const code = await doFormat(context, outputChannel, doc.textDocument, range); // document => doc.textDocument
    if (!range) {
      range = fullDocumentRange(document);
      edits = [import_coc4.TextEdit.replace(range, code)];
      if (edits) {
        return await doc.applyEdits(edits);
      }
    }
    if (doc.textDocument.getText() === code) { // document => doc.textDocument
      return;
    }
    edits = [import_coc4.TextEdit.replace(range, code)];
    if (edits) {
      return await doc.applyEdits(edits);
    }
  }, null, true));

@yaegassy
Copy link
Owner

yaegassy commented Jul 3, 2022

Thanks for looking into the fixes. However, I think it is probably occurring because of the particular way you are executing CodeAction.

Would the same error occur if you execute a code action in your environment with the following mappings?

Example key mapping:

nmap <silent> ga <Plug>(coc-codeaction-line)
xmap <silent> ga <Plug>(coc-codeaction-selected)

@xavier-balesi
Copy link
Author

OK !

I already tried by this way but I had the same issue.
but I removed a plugin that wrapped coc-action (weilbith/nvim-code-action-menu) and now it works (but not with telescope).

But maybe I could be interesting to make coc-pydocstring compatible with theses plugins.
Thanks for your help 👍🏽 .

@yaegassy yaegassy closed this as completed Jul 3, 2022
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