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

Refactor/code action "Move to a new file" has stopped working #501

Closed
ajitid opened this issue Jun 24, 2022 · 6 comments · Fixed by #502
Closed

Refactor/code action "Move to a new file" has stopped working #501

ajitid opened this issue Jun 24, 2022 · 6 comments · Fixed by #502

Comments

@ajitid
Copy link

ajitid commented Jun 24, 2022

I've seen this broken behavior in two editors — Neovim and Zed. It certainly used to work before.

This code action appears if you select a function and invoke a range code action. It used to create a new file and move the function along with the imports/references to this new file.

Current behavior: It creates a blank new file and doesn't might not make any code changes to the current file.

@rchl
Copy link
Member

rchl commented Jun 24, 2022

Are you able to provide some LSP communication logs from the editor?

@ajitid
Copy link
Author

ajitid commented Jun 24, 2022

Sure! https://gist.github.com/ajitid/381c5082f3ec7064bb14ea51175c6f2c. The log mentions indexAt, this is a function that I was trying to move to a new file.

@rchl
Copy link
Member

rchl commented Jun 24, 2022

Thanks. Seems like server returns changes with wrong range (-1):

method = "workspace/applyEdit", params = {
        edit = {
            changes = {
                ...
                ["file:///home/ajitid/ghq/github.com/ajitid/fzf-for-js/src/lib/indexAt.ts"] = {
                    {
                        newText = "export function indexAt(index: number, max: number, forward: boolean) {\n    if (forward) {\n        return index;\n    }\n\n    return max - index - 1;\n}\n", range = {
                            end = {
                                character = -1,
                                line = -1
                            },
                            start = {
                                character = -1,
                                line = -1
                            }
                        }
                    }
                }
            }
        }
    }

To which the editor responds with an error:

{
    result = {
        applied = false,
        failureReason = "...nvim.aQx9chy/usr/share/nvim/runtime/lua/vim/lsp/util.lua:456: start_col out of bounds"
    }, status = true
}

Should be fixable.

@rchl
Copy link
Member

rchl commented Jun 24, 2022

It's potentially something that has changed/broke in some version of Typescript and could be reported in its repo but it should still be handled here, of course.

@ajitid
Copy link
Author

ajitid commented Jun 24, 2022

Sublime LSP also uses this package, right? How come it is able to handle this code action just fine?

@rchl
Copy link
Member

rchl commented Jun 24, 2022

Likely because it's clamping the values which makes the start and end range correctly point at 0, 0

Spec defines Position as unsigned integer so -1 isn't really allowed.

rchl added a commit that referenced this issue Jun 24, 2022
Typescript appears to be sending 0, 0 ranges when providing edit for
creating new file, even though the positions are supposed to be 1-based.

Fixes #501
@rchl rchl closed this as completed in #502 Jun 24, 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
2 participants