typescript-language-server / typescript-language-server

TypeScript & JavaScript Language Server

Home Page:https://www.npmjs.com/package/typescript-language-server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Completion items have incorrect "kind"

babyccino opened this issue · comments

commented

Completion items give strange kinds. For example const is given the kind 'variable', types are given the kind 'class', etc. They are resolved in asCompletionItemKind in completion.ts. Not sure if there's a reason for this but it would seem to be an error and an easy fix

Please provide steps to reproduce the issue.

And what would you expect the type of foo (const foo) be if not a variable?

commented

I don't see why it wouldn't be CompletionItemKind 21 "Constant", that makes the most sense

Server tries to match this VSCode code: https://github.com/microsoft/vscode/blob/428dd56479f4f9987fe0b0a444c11c46e84b2525/extensions/typescript-language-features/src/languageFeatures/completions.ts#L440-L499

As you see both here and there, the Constant is used for string literal.

Constant wouldn't really be more correct as const foo is still a variable, just of a const type. You can't satisfy everyone since it's only possible to describe the completion with a single type. And I would argue that it's more useful to see that the completion is a variable than that it has constant type.

commented

I figured that was the reason, I think the completion item kind interface also more closesly matches with TypeScript's type rather than class but I understand you're trying to just match with VsCode as much as possible.

The other LSPs I've worked with (rust-analyzer, gopls) give a function signature or variable type in the item details as well as the import. Is there any appetite to have typescript-language-server function in the same way? I'm not familiar with the VsCode codebase but their completions do give the correct kind for types, const, let, etc. I'd be happy to implement this if so

I'm not familiar with the VsCode codebase but their completions do give the correct kind for types, const, let, etc. I'd be happy to implement this if so

What do you mean by that. I've said above that this project tries to match VSCode implementation so if it's not matching it then that would be a "bug".