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

Accepting completion of import statement with CTRL-Y deletes the entire line #15

Closed
bgx90 opened this issue Apr 1, 2019 · 12 comments
Closed

Comments

@bgx90
Copy link

bgx90 commented Apr 1, 2019

When I try to use CTRL-Y to accept completion while typing import org.apache.commons.lang3.StringUtils; the entire line gets deleted immediately after the insertion. This happens if I try CTRL-Y at any point after org. Sometimes pressing CTRL-Y partway through the statement will cause completion as a star import like import org.apache.*; or import org.apache.commons.*;, but this happens randomly and I can't tell what is causing it to happen. Most of the time the entire line just disappears when I press CTRL-Y. I see no errors from coc#status() or :CocInfo. I should add that while trying to add the import to my file, I do not have the lang3 jar on the classpath yet, but it is offered by the completion anyway. I know that the program won't compile until I make the lang3 package available, but I don't think that I should be prevented from adding an import statement to a file because of this.

@chemzqm
Copy link
Member

chemzqm commented Apr 1, 2019

Looks like your <C-y> is remapped by other plugin, checkout :verbose imap <C-y>

@bgx90
Copy link
Author

bgx90 commented Apr 1, 2019

I don't think that is the problem. I have had no problems with C-y triggering completions except for import statements. C-y was being used as the leader key for the emmet plugin, but that just caused a slight delay when accepting completions while nvim waited for the leader delay to timeout. To be sure, I remapped the emmet leader key. C-y is not used by any mapping at all and the line with the import statement is still deleted as soon as it completes.

@chemzqm
Copy link
Member

chemzqm commented Apr 1, 2019

will cause completion as a star import like import org.apache.; or import org.apache.commons.;

It's expected, they're textEdits returned from language server, you can chekcout ouput channel https://github.com/neoclide/coc.nvim/wiki/Debug-language-server#using-output-channel to see them.

@bgx90
Copy link
Author

bgx90 commented Apr 1, 2019

will cause completion as a star import like import org.apache.; or import org.apache.commons.;

It's expected, they're textEdits returned from language server, you can chekcout ouput channel https://github.com/neoclide/coc.nvim/wiki/Debug-language-server#using-output-channel to see them.

Right, I assumed that the star imports were expected. i only mentioned it because the completion is deleting the line at random more often than not with no discernible cause. Am I incorrect in assuming that the language server should never give me a textEdit that deletes a line from my file immediately after inserting it using completion? I mean the deletion I am experiencing is not expected behavior, is it?

@chemzqm
Copy link
Member

chemzqm commented Apr 1, 2019

The problem is I don't know how to reproduce this: deletes a line from my file immediately after inserting it using completion.
Consider provide output from https://github.com/neoclide/coc.nvim/wiki/Debug-language-server#using-output-channel so I can understand what happened.

@bgx90
Copy link
Author

bgx90 commented Apr 1, 2019

Here is the output I get when I try to autocomplete StringUtils
outputchannel.txt

I'm not sure, but I think the relevant part is lines 8339 -8494:

[Trace - 6:24:15 PM] Sending notification 'textDocument/didChange'.
Params: {
    "textDocument": {
        "version": 10,
        "uri": "file:///home/user/udemy/maven/hello/HelloWorld.java"
    },
    "contentChanges": [
        {
            "range": {
                "start": {
                    "line": 0,
                    "character": 32
                },
                "end": {
                    "line": 0,
                    "character": 32
                }
            },
            "rangeLength": 0,
            "text": "StringUtils"
        }
    ]
}


[Trace - 6:24:15 PM] Sending request 'completionItem/resolve - (7)'.
Params: {
    "label": "StringUtils - org.apache.commons.lang3",
    "kind": 7,
    "sortText": "999999212",
    "filterText": "StringUtils",
    "insertText": "StringUtils",
    "data": {
        "decl_signature": "Lorg.apache.commons.lang3.StringUtils;",
        "pid": "38",
        "rid": "5",
        "uri": "file:///home/user/udemy/maven/hello/HelloWorld.java"
    }
}


[Trace - 6:24:15 PM] Received response 'completionItem/resolve - (7)' in 41ms.
Result: {
    "label": "StringUtils - org.apache.commons.lang3",
    "kind": 7,
    "documentation": {
        "kind": "markdown"
    },
    "sortText": "999999212",
    "filterText": "StringUtils",
    "insertText": "StringUtils",
    "insertTextFormat": 2,
    "textEdit": {
        "range": {
            "start": {
                "line": 0,
                "character": 32
            },
            "end": {
                "line": 0,
                "character": 32
            }
        },
        "newText": "StringUtils;"
    },
    "additionalTextEdits": [
        {
            "range": {
                "start": {
                    "line": 0,
                    "character": 0
                },
                "end": {
                    "line": 1,
                    "character": 0
                }
            },
            "newText": ""
        }
    ]
}


[Trace - 6:24:15 PM] Sending notification 'textDocument/didChange'.
Params: {
    "textDocument": {
        "version": 11,
        "uri": "file:///home/user/udemy/maven/hello/HelloWorld.java"
    },
    "contentChanges": [
        {
            "range": {
                "start": {
                    "line": 0,
                    "character": 32
                },
                "end": {
                    "line": 0,
                    "character": 43
                }
            },
            "rangeLength": 11,
            "text": ""
        }
    ]
}


[Trace - 6:24:15 PM] Sending notification 'textDocument/didChange'.
Params: {
    "textDocument": {
        "version": 12,
        "uri": "file:///home/user/udemy/maven/hello/HelloWorld.java"
    },
    "contentChanges": [
        {
            "range": {
                "start": {
                    "line": 0,
                    "character": 32
                },
                "end": {
                    "line": 0,
                    "character": 32
                }
            },
            "rangeLength": 0,
            "text": "StringUtils;"
        }
    ]
}


[Trace - 6:24:15 PM] Sending notification 'textDocument/didChange'.
Params: {
    "textDocument": {
        "version": 13,
        "uri": "file:///home/user/udemy/maven/hello/HelloWorld.java"
    },
    "contentChanges": [
        {
            "range": {
                "start": {
                    "line": 0,
                    "character": 0
                },
                "end": {
                    "line": 1,
                    "character": 0
                }
            },
            "rangeLength": 45,
            "text": ""
        }
    ]
}

@chemzqm
Copy link
Member

chemzqm commented Apr 2, 2019

Got it

    "additionalTextEdits": [
        {
            "range": {
                "start": {
                    "line": 0,
                    "character": 0
                },
                "end": {
                    "line": 1,
                    "character": 0
                }
            },
            "newText": ""
        }
    ]

I have no idea why jdt.ls send this to client.

@chemzqm
Copy link
Member

chemzqm commented Apr 2, 2019

According to specification

	/**
	 * An optional array of additional text edits that are applied when
	 * selecting this completion. Edits must not overlap (including the same insert position)
	 * with the main edit nor with themselves.
	 *
	 * Additional text edits should be used to change text unrelated to the current cursor position
	 * (for example adding an import statement at the top of the file if the completion item will
	 * insert an unqualified type).
	 */
	additionalTextEdits?: TextEdit[];

Coc should ignore additionalTextEdit that have overlap.

@chemzqm
Copy link
Member

chemzqm commented Apr 2, 2019

Fixed on master of coc.nvim.

@bgx90
Copy link
Author

bgx90 commented Apr 2, 2019

I pulled the latest from coc.nvim on master. When I tried running yarn install I get the following errors:

yarn install v1.15.2
[1/4] Resolving packages...
success Already up-to-date.
$ yarnpkg clean && yarnpkg build
yarn run v1.15.2
$ rimraf lib build
Done in 0.21s.
yarn run v1.15.2
$ tsc -p tsconfig.json
src/completion/complete.ts:138:11 - error TS2339: Property 'removeDuplicatedLowerPriority' does not exist on type 'CompleteConfig'.

138     let { removeDuplicatedLowerPriority, snippetIndicator, fixInsertedWord } = this.config
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/completion/index.ts:151:7 - error TS2322: Type '{ autoTrigger: string; keepCompleteopt: boolean; acceptSuggestionOnCommitCharacter: boolean; removeDuplicatedLowerPriority: boolean; previewIsKeyword: string; reloadPumOnInsertChar: boolean; ... 10 more ...; localityBonus: boolean; }' is not assignable to type 'CompleteConfig'.
  Object literal may only specify known properties, and 'removeDuplicatedLowerPriority' does not exist in type 'CompleteConfig'.

151       removeDuplicatedLowerPriority: getConfig<boolean>('noselect', true),
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/plugin.ts:39:14 - error TS2554: Expected 1 arguments, but got 0.

39       return extensions.installExtensions()
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  src/extensions.ts:214:28
    214   public installExtensions(list: string[]): void {
                                   ~~~~~~~~~~~~~~
    An argument for 'list' was not provided.


Found 3 errors.

error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

@chemzqm
Copy link
Member

chemzqm commented Apr 2, 2019

My bad, just fixed.

@bgx90
Copy link
Author

bgx90 commented Apr 2, 2019

It is working as expected now. Thank you very much.

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

No branches or pull requests

2 participants