weixin_39929918
weixin_39929918
2020-12-03 01:36

[CoC/neovim] Go to definition fails for some functions

Expected Behavior

I expect "go to definition" to work regardless of the context.

Current Behavior

For some functions, whether they are in the same file or not, I instead get an error from CoC: [coc.nvim] Definition not found

Looking into the log with :CocInfo, this is what I see:


[Info  - 1:54:25 PM] A definition was requested
[Error  - 1:54:25 PM] Request textDocument/definition failed.
  Message: Request textDocument/definition failed with message: anonymousFunctionExprNodes.flatMap is not a function
  Code: -32603

Possible Solution

I have none, sorry!

Steps to Reproduce (for bugs)¶

I don't have an SSCCE, sorry, but i've had the bug occur on my latest pet project, which consists of one Main.elm file, so I figure it's OK to use it to showcase the issue? Let me know if it is not. 1. git clone --single-branch --branch animation-test git.com:Augustin82/0h-n0 2. open ./0h-n0/src/Main.elm 3. go to the use of toColor (l.135) and try to go to definition: it works 4. go to the use of fromColor (l.140) and try to go to definition: it does not work

Context

Going to the definition would be peachy!

Your Environment

  • Version used: 1.7.1
  • Editor used: neovim
  • Environment name and version (e.g. node.js 5.4): nodejs 10.20.1
  • Operating System and version: Ubuntu Gnome 18.04

该提问来源于开源项目:elm-tooling/elm-language-server

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

31条回答

  • weixin_39725118 weixin_39725118 5月前

    flatMap requires node >= 11. image https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap

    Is the es2019 libr meant to transpile or to polyfill flatMap?

    点赞 评论 复制链接分享
  • weixin_39929918 weixin_39929918 5月前

    Would it make sense to add this in the code? https://github.com/jonathantneal/array-flat-polyfill

    点赞 评论 复制链接分享
  • weixin_39725118 weixin_39725118 5月前

    There's also this: https://github.com/ryanelian/ts-polyfill

    I'm surprised if there is no poly-filling going on, if you target es5 or es6.

    点赞 评论 复制链接分享
  • weixin_39725118 weixin_39725118 5月前

    So current theory is: Output will not work with node <= 10 and has to be verified.

    Comparison with VS Code is (I guess) not useful because it's integrated as plugin and in a different way.

    Update

    Tested on my machine.

    • node 12: npm link branch master is working with fromColor
    • node 10: npm link branch master is not working with fromColor
    点赞 评论 复制链接分享
  • weixin_39590635 weixin_39590635 5月前

    https://github.com/elm-tooling/elm-language-server/tree/workaround-flatmap might help

    点赞 评论 复制链接分享
  • weixin_39725118 weixin_39725118 5月前

    I installed the branch with node 10 and can confirm it is working

    点赞 评论 复制链接分享
  • weixin_39590635 weixin_39590635 5月前

    Closing this, as I merged the branch.

    点赞 评论 复制链接分享
  • weixin_39929918 weixin_39929918 5月前

    For the record, I've experienced other instances of the problem, without being able to pinpoint it to anything. The CoC log remained empty. I don't have anything more meaningful to contribute, just thought I'd let you know.

    Thanks a lot for the fix, in any case!

    点赞 评论 复制链接分享
  • weixin_39590635 weixin_39590635 5月前

    Please let me know if your able to pinpoint it at some point.

    点赞 评论 复制链接分享
  • weixin_39590635 weixin_39590635 5月前

    Peek 2020-04-21 20-10

    just tried myself in vim on manjaro. Language server installed via npm or npm link works fine for me.

    点赞 评论 复制链接分享
  • weixin_39725118 weixin_39725118 5月前

    I can confirm it's working with Vim and elm-language-server 1.7.1 installed with npm and it's not working with 1.7.1 installed with nix.

    点赞 评论 复制链接分享
  • weixin_39929918 weixin_39929918 5月前

    I installed using yarn. I'll try using npm (if I ever sort the problems with paths and authorizations and stuff...).

    点赞 评论 复制链接分享
  • weixin_39725118 weixin_39725118 5月前

    Nix seems to use node 10: https://github.com/andys8/nixpkgs/blob/523fe988217eaa56952c2a87760fef612c857bee/pkgs/development/compilers/elm/packages/generate-node-packages.sh#L9

    点赞 评论 复制链接分享
  • weixin_39590635 weixin_39590635 5月前

    I think the best thing would be, if you were able to reproduce it in vscode.

    点赞 评论 复制链接分享
  • weixin_39929918 weixin_39929918 5月前

    Ok, I'll try to install it and check.

    点赞 评论 复制链接分享
  • weixin_39929918 weixin_39929918 5月前

    It works fine in VSCode, like you said. Kudos on the feature set there, btw, it looks impressive, I'm almost tempted to try it for a while =P

    So, how should I go about finding the problem, which is most likely in the way CoC and ElmLS talk, right?

    点赞 评论 复制链接分享
  • weixin_39929918 weixin_39929918 5月前

    Indeed, replacing the if block on l. 673 of utils/treeUtils.js by the following, and then restarting CoC, resulted in the gotodef working.

    
            if (node && node.type === "parenthesized_expr") {
                const anonymousFunctionExprNodes = this.descendantsOfType(node, "anonymous_function_expr");
                if (!anonymousFunctionExprNodes.flatMap) {
                    return;
                }
                const match = anonymousFunctionExprNodes
                    .flatMap((a) => a.children)
                    .find((child) => child.type === "pattern" && child.text === functionParameterName);
                if (match) {
                    return match;
                }
            }
    

    I don't mind leaving it there as a hotfix for now, but can I do anything to try and pinpoint the actual problem, and maybe possibly fix it? I'm very new to LSPs but I can always hack at it until it works ;)

    点赞 评论 复制链接分享
  • weixin_39590635 weixin_39590635 5月前

    The real question is how this happens, best would be to figure that out and create a test for it here https://github.com/tree-sitter/tree-sitter/blob/82fab90c0b91cc57a949b9d96768d7f3b7a621e4/lib/binding_web/test/node-test.js#L315

    Then we could show it to the maintainers of tree-sitter and figure out how to advance.

    点赞 评论 复制链接分享
  • weixin_39929918 weixin_39929918 5月前

    I'm afraid I don't understand how to translate what I have observed (gotodef fails when the function whose definition you're trying to reach is wrapped in a parenthesized lamda function) into such a test =/ Any pointers from one more familiar? Or should I create an issue over there, linking here, and asking for help?

    点赞 评论 复制链接分享
  • weixin_39590635 weixin_39590635 5月前

    I'm not so sure either, can you check/print anonymousFunctionExprNodes if it's null? We could at least open a conversation over at their repo around that. I'm not sure how/if that's something we cause somehow.

    点赞 评论 复制链接分享
  • weixin_39929918 weixin_39929918 5月前

    they said:

    I'm going to close this one out for now because currently, it sounds like you are investigating an issue with elm-language-server or tree-sitter-elm.

    What's our next step? What can I do to help?

    点赞 评论 复制链接分享
  • weixin_39590635 weixin_39590635 5月前

    I think the best would be to get someone else to test it with coc and neovim and confirm, that it breaks, like it does for you.

    Then generating a trace that we can feed into https://microsoft.github.io/language-server-protocol/inspector/ or replay (somehow) and maybe attach a debugger to the server.

    Maybe can help

    点赞 评论 复制链接分享
  • weixin_39725118 weixin_39725118 5月前

    I can reproduce it in Vim. I can't reproduce it in VSCode.

    
    [Trace - 5:08:06 PM] Received notification 'window/logMessage'.
    Params: {
        "type": 3,
        "message": "A definition was requested"
    }
    
    
    [Info  - 5:08:06 PM] A definition was requested
    [Trace - 5:08:06 PM] Received response 'textDocument/definition - (10)' in 3ms. Request failed: Request textDocument/definition failed with message: anonymousFunctionExprNodes.flatMap is not a function (-32603).
    [Error  - 5:08:06 PM] Request textDocument/definition failed.
      Message: Request textDocument/definition failed with message: anonymousFunctionExprNodes.flatMap is not a function
      Code: -32603 
    
    
    vim version: VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Apr  4 2020 13:23:00)
    node version: v12.5.0
    coc.nvim version: 0.0.78-6e3ecc04cf
    term: dumb
    platform: linux
    elm-language-server  --version: 1.7.1
    
    点赞 评论 复制链接分享
  • weixin_39590635 weixin_39590635 5月前

    Does this mean the node context via vim is different? Searching for that error basically says, it's not supported in your browser https://stackoverflow.com/questions/55530690/javascript-flatmap-method-over-array-flatmap-is-not-a-function

    点赞 评论 复制链接分享
  • weixin_39725118 weixin_39725118 5月前

    goto def fromColor not working

    elm
    color1 state =
        Animator.color state
            (\s ->
                case s of
                    Ready ->
                        fromColor blue
    
                    Loading ->
                        fromColor red
            )
    

    goto def fromColor working

    elm
    color1 state =
        let
            f =
                \s ->
                    case s of
                        Ready ->
                            fromColor blue
    
                        Loading ->
                            fromColor red
        in
        Animator.color state f
    
    点赞 评论 复制链接分享
  • weixin_39725118 weixin_39725118 5月前

    I think you're on the right way

    anonymousFunctionExprNodes.flatMap is not a function doesn't say anonymousFunctionExprNodes is null but it doesn't have flatMap.

    点赞 评论 复制链接分享
  • weixin_39725118 weixin_39725118 5月前

    You could try if transpilling to es5 would remove the error.

    https://stackoverflow.com/questions/53556409/typescript-flatmap-flat-flatten-doesnt-exist-on-type-any

    点赞 评论 复制链接分享
  • weixin_39590635 weixin_39590635 5月前

    Hrm we already define es6 and es2019

    点赞 评论 复制链接分享
  • weixin_39725118 weixin_39725118 5月前

    es5 != es6

    点赞 评论 复制链接分享
  • weixin_39590635 weixin_39590635 5月前

    hrm, that seems to work for me. even when I run 1.7.1 instead of master, can you check again?

    I tested in vscode

    点赞 评论 复制链接分享
  • weixin_39929918 weixin_39929918 5月前

    I've tested several times, including cloning the repo in a new directory.

    What are things I could do to check if it's due to my neovim config, or to my CoC setup, or something else? Should I add debugging to the Elm LS code to get more information on that error (code 32603), or is it a red herring?

    点赞 评论 复制链接分享

相关推荐