neoclide / coc-tsserver

Tsserver extension for coc.nvim that provide rich features like VSCode for javascript & typescript
MIT License
1.05k stars 68 forks source link

Implement inlay hints #300

Closed resolritter closed 2 years ago

resolritter commented 3 years ago

Announcement: https://devblogs.microsoft.com/typescript/announcing-typescript-4-4-beta/#inlay-hints Linked PR: https://github.com/microsoft/TypeScript/pull/42089 (was already merged)

I believe this has not yet landed on a stable release although 4.4 is scheduled for next month already

chemzqm commented 3 years ago

It's not possible to add inline virtual text on both vim and neovim, so send your feature request to vim/neovim fist.

resolritter commented 3 years ago

It could work with virtual text at the end of the line in Neovim, like coc-rust-analyzer

fannheyward commented 3 years ago

I'll take a look on this after TS 4.4 released. There're several works:

  1. tsserver makes its own inlayHint protocol implementation, but LSP is working on a new/standard protocol on https://github.com/microsoft/vscode-languageserver-node/pull/772
  2. display with virtual text, it works but not perfect, this needs vim/nvim more works
fannheyward commented 3 years ago

Test code:

// enumMemberValues
enum E1 {
  A,
  B,
}

enum E2 {
  A = 0,
  B = 1,
}

// functionLikeReturnTypes
function foo() {
  return Date.now()
}

function bar(): number {
  return Date.now()
}

// parameterNames
parseInt('123', 8)

// parameterTypes
document.addEventListener('click', e => {
  console.log(e)
})

// propertyDeclarationTypes
class Bar {
  prop = Date.now;
}

// variableTypes
const xxf = Date.now()

In VSCode:

截屏2021-08-09 下午6 26 39

In coc, only enumMemberValues, functionLikeReturnTypes and variableTypes are enabled.

截屏2021-08-09 下午6 29 58

Because we can't set inline virtual text, parameterNames, parameterTypes and propertyDeclarationTypes are disabled.

@chemzqm any thoughts on this? Do we need to add this in coc-tsserver?

fannheyward commented 3 years ago

The variableTypes hints should be disabled too.

hadnet commented 2 years ago

How is this going, guys? Any updates? When can we use this feature?