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

Reference codeLens action not working #495

Open
razzeee opened this issue Jun 6, 2019 · 12 comments
Open

Reference codeLens action not working #495

razzeee opened this issue Jun 6, 2019 · 12 comments
Labels
feature-request Request for new features or functionality good first issue help wanted Issues identified as good community contribution opportunities
Milestone

Comments

@razzeee
Copy link
Contributor

razzeee commented Jun 6, 2019

I'm trying to use the build in command for editor.action.showReferences and have it bound to a codeLens. But I can't figure out, what I'm doing wrong.

[Trace - 12:51:43 AM] Received response 'codeLens/resolve - (25)' in 6ms.
Result: {
    "range": {
        "start": {
            "line": 380,
            "character": 8
        },
        "end": {
            "line": 381,
            "character": 50
        }
    },
    "data": {
        "codeLensType": "referenceCounter",
        "references": [
            {
                "uri": "file:///home/razze/Development/elm-spa-example/src/Page/Article/Editor.elm",
                "range": {
                    "start": {
                        "line": 380,
                        "character": 8
                    },
                    "end": {
                        "line": 380,
                        "character": 16
                    }
                }
            },
            {
                "uri": "file:///home/razze/Development/elm-spa-example/src/Page/Article/Editor.elm",
                "range": {
                    "start": {
                        "line": 117,
                        "character": 30
                    },
                    "end": {
                        "line": 117,
                        "character": 38
                    }
                }
            },
            {
                "uri": "file:///home/razze/Development/elm-spa-example/src/Page/Article/Editor.elm",
                "range": {
                    "start": {
                        "line": 152,
                        "character": 35
                    },
                    "end": {
                        "line": 152,
                        "character": 43
                    }
                }
            },
            {
                "uri": "file:///home/razze/Development/elm-spa-example/src/Page/Article/Editor.elm",
                "range": {
                    "start": {
                        "line": 157,
                        "character": 35
                    },
                    "end": {
                        "line": 157,
                        "character": 43
                    }
                }
            },
            {
                "uri": "file:///home/razze/Development/elm-spa-example/src/Page/Article/Editor.elm",
                "range": {
                    "start": {
                        "line": 350,
                        "character": 35
                    },
                    "end": {
                        "line": 350,
                        "character": 43
                    }
                }
            },
            {
                "uri": "file:///home/razze/Development/elm-spa-example/src/Page/Article/Editor.elm",
                "range": {
                    "start": {
                        "line": 363,
                        "character": 33
                    },
                    "end": {
                        "line": 363,
                        "character": 41
                    }
                }
            },
            {
                "uri": "file:///home/razze/Development/elm-spa-example/src/Page/Article/Editor.elm",
                "range": {
                    "start": {
                        "line": 385,
                        "character": 25
                    },
                    "end": {
                        "line": 385,
                        "character": 33
                    }
                }
            },
            {
                "uri": "file:///home/razze/Development/elm-spa-example/src/Page/Article/Editor.elm",
                "range": {
                    "start": {
                        "line": 388,
                        "character": 23
                    },
                    "end": {
                        "line": 388,
                        "character": 31
                    }
                }
            },
            {
                "uri": "file:///home/razze/Development/elm-spa-example/src/Page/Article/Editor.elm",
                "range": {
                    "start": {
                        "line": 479,
                        "character": 16
                    },
                    "end": {
                        "line": 479,
                        "character": 24
                    }
                }
            }
        ],
        "uri": "file:///home/razze/Development/elm-spa-example/src/Page/Article/Editor.elm"
    },
    "command": {
        "title": "9 references",
        "command": "editor.action.showReferences",
        "arguments": [
            {
                "$mid": 1,
                "path": "/home/razze/Development/elm-spa-example/src/Page/Article/Editor.elm",
                "scheme": "file"
            },
            {
                "line": 380,
                "character": 8
            },
            [
                {
                    "uri": "file:///home/razze/Development/elm-spa-example/src/Page/Article/Editor.elm",
                    "range": {
                        "start": {
                            "line": 380,
                            "character": 8
                        },
                        "end": {
                            "line": 380,
                            "character": 16
                        }
                    }
                },
                {
                    "uri": "file:///home/razze/Development/elm-spa-example/src/Page/Article/Editor.elm",
                    "range": {
                        "start": {
                            "line": 117,
                            "character": 30
                        },
                        "end": {
                            "line": 117,
                            "character": 38
                        }
                    }
                },
                {
                    "uri": "file:///home/razze/Development/elm-spa-example/src/Page/Article/Editor.elm",
                    "range": {
                        "start": {
                            "line": 152,
                            "character": 35
                        },
                        "end": {
                            "line": 152,
                            "character": 43
                        }
                    }
                },
                {
                    "uri": "file:///home/razze/Development/elm-spa-example/src/Page/Article/Editor.elm",
                    "range": {
                        "start": {
                            "line": 157,
                            "character": 35
                        },
                        "end": {
                            "line": 157,
                            "character": 43
                        }
                    }
                },
                {
                    "uri": "file:///home/razze/Development/elm-spa-example/src/Page/Article/Editor.elm",
                    "range": {
                        "start": {
                            "line": 350,
                            "character": 35
                        },
                        "end": {
                            "line": 350,
                            "character": 43
                        }
                    }
                },
                {
                    "uri": "file:///home/razze/Development/elm-spa-example/src/Page/Article/Editor.elm",
                    "range": {
                        "start": {
                            "line": 363,
                            "character": 33
                        },
                        "end": {
                            "line": 363,
                            "character": 41
                        }
                    }
                },
                {
                    "uri": "file:///home/razze/Development/elm-spa-example/src/Page/Article/Editor.elm",
                    "range": {
                        "start": {
                            "line": 385,
                            "character": 25
                        },
                        "end": {
                            "line": 385,
                            "character": 33
                        }
                    }
                },
                {
                    "uri": "file:///home/razze/Development/elm-spa-example/src/Page/Article/Editor.elm",
                    "range": {
                        "start": {
                            "line": 388,
                            "character": 23
                        },
                        "end": {
                            "line": 388,
                            "character": 31
                        }
                    }
                },
                {
                    "uri": "file:///home/razze/Development/elm-spa-example/src/Page/Article/Editor.elm",
                    "range": {
                        "start": {
                            "line": 479,
                            "character": 16
                        },
                        "end": {
                            "line": 479,
                            "character": 24
                        }
                    }
                }
            ]
        ]
    }
}


This is the error that happens, when I click the code action.
Screenshot from 2019-06-07 00-50-26

#210

https://github.com/elm-tooling/elm-language-server/blob/57550c1a0c95b74df3ecb71c98b261785a306c69/src/providers/codeLensProvider.ts#L79

@dbaeumer
Copy link
Member

The problem is very likely this:

            {
                "$mid": 1,
                "path": "/home/razze/Development/elm-spa-example/src/Page/Article/Editor.elm",
                "scheme": "file"
            }

since the LSP has no support (on purpose) for decoding VS Code URIs. Since you make this VS Code speicific in the first place (by using the VS Code command editor.action.showReferences) you are better of handling this in the VS Code extension. Options are:

  • having you own command that then calls editor.action.showReferences
  • implementing a VS Code LSP client middleware and send the URI as a string and then convert it on the client side to a VS Code speicific URI format.

LEt me know how it goes.

@dbaeumer dbaeumer added the info-needed Issue requires more information from poster label Jun 11, 2019
@razzeee
Copy link
Contributor Author

razzeee commented Jun 11, 2019 via email

@dbaeumer
Copy link
Member

You can of course call the textDocument/references request in the server yourself. The LSP spec explicitly allows this even for files that are not open in the editor.

@razzeee
Copy link
Contributor Author

razzeee commented Jun 19, 2019

Are there any docs on how to do this with vscode-languageserver-node?

@dbaeumer
Copy link
Member

dbaeumer commented Aug 7, 2019

@razzeee

you have your own command and then implement a command handler on the VS Code side which then

  • calls the editor command
  • or sends a textDocument/references to the server and renders the result in its own view, ...

@Krzysztof-Cieslak
Copy link

You can also register middleware in Code’s client side to transform the types - example in PowerShell client - https://github.com/PowerShell/vscode-powershell/blob/master/src/session.ts#L366

@dbaeumer
Copy link
Member

dbaeumer commented Aug 7, 2019

@Krzysztof-Cieslak cool idea!

@Krzysztof-Cieslak
Copy link

Yes, this is pretty OK workaround... but I kinda believe this behaviour should be fixed here in vscode-languageclient. Number-of-references CodeLenses is a feature supported by whole bunch of popular plugins (C#, F#, Powershell, Go to just name a few) and every single one of them needs to implement some type of workaround

@dbaeumer
Copy link
Member

@Krzysztof-Cieslak agree. Would require some spec in the LSP with some property to indicate that a code lens should trigger reference search. I don't want to standardize command id's in LSP. Then the VS Code implementation could trigger the command.

PR welcome.

@dbaeumer dbaeumer added feature request good first issue help wanted Issues identified as good community contribution opportunities and removed info-needed Issue requires more information from poster labels Aug 12, 2019
@dbaeumer dbaeumer added this to the Backlog milestone Aug 12, 2019
@angelozerr
Copy link

angelozerr commented Mar 1, 2021

I don't want to standardize command id's in LSP.

Why? It should be really nice to have command IDs standardization, XML CodeLens references is a very good sample. We have this problem with our XML Language Server which which provides references for DTD, XSD. It works pretty well in vscode (call just LSP textDocument/references request but not in Eclipse IDE which doesn't implement this request(see eclipse-wildwebdeveloper/wildwebdeveloper#644).

With standard command IDs, a lot of language server could benefit with standard commands (ex : click on references) without extra code.

@dbaeumer
Copy link
Member

dbaeumer commented Mar 2, 2021

If we standardize this it must be more than a string ID to make it an explicit concept. And clients still need to announce which commands it supports.

@angelozerr
Copy link

If we standardize this it must be more than a string ID to make it an explicit concept.

Yes sure it will require to specify ID + args command. It will give the capability to use standard structure for args on language server side. I think it can be a good idea.

And clients still need to announce which commands it supports.

Indeed and I think again it's a good idea because for XML Language Server we do that with custom capability. If we have standard capability, it should be cleaner.

bors bot added a commit to aya-prover/aya-vscode that referenced this issue Jun 12, 2022
21: Upgrade frontend to work with Aya language server r=ice1000 a=imkiva

Changes:
- Add middleware to workaround microsoft/vscode-languageserver-node#495
- Provide light and dark colors for semantic highlight
- Upgrade some dependencies


Co-authored-by: imkiva <imkiva@islovely.icu>
bors bot added a commit to aya-prover/aya-dev that referenced this issue Jun 12, 2022
424: New features to LSP r=ice1000 a=imkiva

this PR upgraded LSP4j to 0.14 with inlay hints support; added some features to the LSP backend:
- Inlay type hints for bind patterns (feel free to suggest more)
- CodeLens of each definition showing `%d usages`
- Code folding for definitions that occupy 3 or more LOC.
- Search Everywhere in VSCode (symbols only since VSC does not ask more from backend)

Try it: https://github.com/aya-prover/aya-vscode/suites/6895435995/artifacts/267446633

## See also
Language Server Protocol has recently upgraded to 3.17, and VSCode stabilized their inlay hints APIs
- https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_inlayHint
- rust-lang/rust-analyzer#11445
- microsoft/vscode-languageserver-node#495
- aya-prover/aya-vscode#21


Co-authored-by: imkiva <imkiva@islovely.icu>
@dbaeumer dbaeumer added feature-request Request for new features or functionality and removed feature request labels Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality good first issue help wanted Issues identified as good community contribution opportunities
Projects
None yet
Development

No branches or pull requests

4 participants