2021-01-28 11:19:14 +09:00
## Local Change
2021-10-17 03:47:01 +09:00
Support disabling suggestionActions by code number.
### Example
In coc-settings.json:
```
{
"typescript.suggestionActions.disabledCodes": [80001, 80002],
"javascript.suggestionActions.disabledCodes": [80001, 80002, 7016]
}
```
2021-01-28 11:19:14 +09:00
2018-09-07 21:40:51 +09:00
# coc-tsserver
2020-08-08 11:03:33 +09:00
Tsserver language server extension for
[coc.nvim ](https://github.com/neoclide/coc.nvim ).
2018-09-07 21:40:51 +09:00
2020-06-29 12:37:20 +09:00
Tsserver is part of [TypeScript ](https://github.com/microsoft/TypeScript ) which
provide rich features for javascript and typescript.
2020-08-08 11:03:33 +09:00
This extension is a fork of `typescript-language-features` extension which is
bundled with VSCode.
2018-09-07 21:40:51 +09:00
2019-06-11 13:23:34 +09:00
**Note:** for React to work as expected, you need your JSX filetype to be
2020-08-08 11:03:33 +09:00
`javascript.jsx` or `javascriptreact` and your TSX filetype to be
`typescript.jsx` or `typescript.tsx` or `typescriptreact` . In coc.nvim, these
filetypes are mapped to `javascriptreact` and `typescriptreact` because that's
2020-09-10 22:10:52 +09:00
what tsserver uses. For filetype like `typescript.javascript` , you need
configure `g:coc_filetype_map` variable in vimrc.
2019-03-27 20:02:33 +09:00
2020-08-08 11:03:33 +09:00
**Note** for javascript project, configure
[jsconfig.json ](https://code.visualstudio.com/docs/languages/jsconfig ) to make
tsserver understand your code.
2020-05-22 15:07:39 +09:00
2020-11-02 19:18:39 +09:00
**Note:** for rename import on file rename, you have to install
[watchman ](https://facebook.github.io/watchman/ ) in your \$PATH.
**Note:** for [nvm ](https://github.com/creationix/nvm ) users, you need configure
`tsserver.npm` to your global npm path or configure
`"tsserver.disableAutomaticTypeAcquisition": false` to disable automatic typings
installation.
**Note:** tsserver could be quite slow to initialize on big project, exclude
2021-12-21 14:57:51 +09:00
unnecessary files in your jsconfig.json/tsconfig.json.
2020-11-02 19:18:39 +09:00
2021-01-19 15:16:58 +09:00
**Note:** if you're using WSL, copy you project files from mounted dirs to linux home otherwise tsserver will not work properly.
2020-12-09 16:41:00 +09:00
## Supporting
If you like my extension, consider supporting me on Patreon or PayPal:
< a href = "https://www.patreon.com/chemzqm" > < img src = "https://c5.patreon.com/external/logo/become_a_patron_button.png" alt = "Patreon donate button" / > < / a >
< a href = "https://www.paypal.com/paypalme/chezqm" > < img src = "https://werwolv.net/assets/paypal_banner.png" alt = "PayPal donate button" / > < / a >
2018-09-07 21:40:51 +09:00
## Install
In your vim/neovim, run command:
2020-08-08 11:03:33 +09:00
`:CocInstall coc-tsserver`
2018-09-07 21:40:51 +09:00
2020-06-29 12:37:20 +09:00
For yarn2 ( >= v2.0.0-rc.36) user want to use local typescript module:
2020-04-17 13:19:17 +09:00
2021-09-03 00:01:14 +09:00
- Run command `yarn dlx @yarnpkg/sdks vim` , which will generate
2020-08-08 11:03:33 +09:00
`.vim/coc-settings.json` , with content:
2020-04-17 13:19:17 +09:00
2021-02-09 19:54:01 +09:00
```json
2020-10-27 17:24:53 +09:00
{
"eslint.packageManager": "yarn",
2021-09-03 00:01:14 +09:00
"eslint.nodePath": ".yarn/sdks",
"workspace.workspaceFolderCheckCwd": false,
"tsserver.tsdk": ".yarn/sdks/typescript/lib"
2021-02-09 19:54:01 +09:00
}
```
2020-04-17 13:19:17 +09:00
2018-09-07 21:40:51 +09:00
## Features
2019-04-20 04:52:07 +09:00
Almost the same as VSCode.
2018-09-07 21:40:51 +09:00
2019-04-20 04:52:07 +09:00
- Supports javascript & typescript and jsx/tsx.
- Installs typings automatically.
2018-10-21 14:21:25 +09:00
- Commands to work with tsserver, including:
- `tsserver.reloadProjects`
- `tsserver.openTsServerLog`
- `tsserver.goToProjectConfig`
- `tsserver.restart`
- `tsserver.organizeImports`
- `tsserver.watchBuild`
2021-06-04 19:54:48 +09:00
- `tsserver.findAllFileReferences`
2018-10-21 14:21:25 +09:00
- Code completion support.
2021-04-07 19:28:07 +09:00
- Go to definition (more info in [microsoft/TypeScript#37777 ](https://github.com/microsoft/TypeScript/issues/37777 ))
2018-10-21 14:21:25 +09:00
- Code validation.
- Document highlight.
- Document symbols of current buffer.
- Folding and folding range of current buffer.
- Format current buffer, range format and format on type.
- Hover for documentation.
- Implementations codeLens and references codeLens.
- Organize imports command.
- Quickfix using code actions.
- Code refactor using code actions.
- Find references.
- Signature help.
2022-01-20 05:08:19 +09:00
- Call hierarchy.
- Selection range.
2022-01-20 00:22:30 +09:00
- Semantic tokens.
2018-10-21 14:21:25 +09:00
- Rename symbols support.
2022-01-20 00:22:30 +09:00
- Automatic tag closing.
2020-08-08 11:03:33 +09:00
- Rename imports on file rename, require
[watchman ](https://facebook.github.io/watchman/ ) installed in your \$PATH.
2018-10-21 14:21:25 +09:00
- Search for workspace symbols.
2021-12-24 19:39:29 +09:00
- Inlay hints support using virtual text feature of neovim, which requires:
- TypeScript >= 4.4.0
- Neovim >= 0.4.0
- Enabled by options starts with `typescript.inlayHints` or
`javascript.inlayHints` .
2018-09-07 21:40:51 +09:00
2020-08-08 11:03:33 +09:00
Tsserver module first resolved from your local workspace. If it's not found, use
tsserver from `tsserver.tsdk` configuration or use bundled tsserver with this
extension.
2018-10-14 11:06:11 +09:00
2018-09-07 21:40:51 +09:00
## Configuration options
2020-08-08 11:03:33 +09:00
Checkout [using the configuration
file](https://github.com/neoclide/coc.nvim/wiki/Using-the-configuration-file)
for guide of coc.nvim's configuration.
2019-11-23 19:40:48 +09:00
2019-04-19 20:07:15 +09:00
- `tsserver.enable` :Enable tsserver extension, default: `true`
- `tsserver.locale` :Locale of tsserver, default: `""`
2022-02-16 19:48:32 +09:00
- `tsserver.ignoreLocalTsserver` :Always use tsserver module from tsserver.tsdk
or coc-tsserver extension.
2019-04-19 20:07:15 +09:00
- `tsserver.typingsCacheLocation` :Folder path for cache typings, default: `""`
2020-08-08 11:03:33 +09:00
- `tsserver.formatOnType` :Run format on type special characters., default:
`true`
2019-04-19 20:07:15 +09:00
- `tsserver.enableJavascript` :Use tsserver for javascript files, default: `true`
2020-08-08 11:03:33 +09:00
- `tsserver.maxTsServerMemory` :Set the maximum amount of memory to allocate to
the TypeScript server process
2019-04-19 20:07:15 +09:00
- `tsserver.tsdk` :Directory contains tsserver.js,, default: `""`
- `tsserver.npm` :Executable path of npm for download typings, default: `""`
- `tsserver.log` :Log level of tsserver, default: `"off"`
- `tsserver.trace.server` :Trace level of tsserver, default: `"off"`
2020-07-13 20:56:13 +09:00
- `tsserver.pluginPaths` :Folders contains tsserver plugins, default: `[]`
2020-08-08 11:03:33 +09:00
- `tsserver.watchOptions` :Configure which watching strategies should be used to
keep track of files and directories. Requires using TypeScript 3.8+ in the
2021-12-21 14:57:51 +09:00
workspace, default: `undefined`
2019-04-19 20:07:15 +09:00
- `tsserver.reportStyleChecksAsWarnings` default: `true`
2020-08-08 11:03:33 +09:00
- `tsserver.implicitProjectConfig.checkJs` :Enable checkJs for implicit project,
default: `false`
- `tsserver.implicitProjectConfig.experimentalDecorators` :Enable
experimentalDecorators for implicit project, default: `false`
- `tsserver.disableAutomaticTypeAcquisition` :Disable download of typings,
default: `false`
2021-12-21 14:57:51 +09:00
- `tsserver.useBatchedBufferSync` : use batched buffer synchronize support, default: `true`
2021-12-21 19:04:20 +09:00
- `tsserver.enableTracing` : Enables tracing TS server performance to a
directory. These trace files can be used to diagnose TS Server performance
issues. The log may contain file paths, source code, and other potentially
sensitive information from your project, default: `false`
2021-12-22 02:17:42 +09:00
- `typescript.check.npmIsInstalled` : Check if npm is installed for [Automatic
Type
Acquisition](https://code.visualstudio.com/docs/nodejs/working-with-javascript#_typings-and-automatic-type-acquisition).
2020-08-08 11:03:33 +09:00
- `typescript.updateImportsOnFileMove.enable` :Enable update imports on file
move., default: `true`
- `typescript.implementationsCodeLens.enable` :Enable codeLens for
implementations, default: `true`
- `typescript.referencesCodeLens.enable` :Enable codeLens for references,
default: `true`
2022-01-13 01:29:12 +09:00
- `typescript.referencesCodeLens.showOnAllFunctions` : Enable/disable references CodeLens on all functions in typescript files. Default: `false`
2022-01-28 06:59:53 +09:00
- `typescript.preferences.importModuleSpecifier` default: `"shortest"`
2020-12-13 14:33:55 +09:00
- `typescript.preferences.importModuleSpecifierEnding` default: `"auto"`
2019-04-19 20:07:15 +09:00
- `typescript.preferences.quoteStyle` default: `"single"`
2021-12-21 18:38:28 +09:00
- `typescript.preferences.includePackageJsonAutoImports` : Enable/disable
searching `package.json` dependencies for available auto imports, default:
`"auto"`
2020-08-08 11:03:33 +09:00
- `typescript.suggestionActions.enabled` :Enable/disable suggestion diagnostics
for TypeScript files in the editor. Requires using TypeScript 2.8 or newer in
the workspace., default: `true`
- `typescript.validate.enable` :Enable/disable TypeScript validation., default:
`true`
2019-06-27 11:43:32 +09:00
- `typescript.showUnused` : show unused variable hint, default: `true` .
2022-01-20 05:04:13 +09:00
- `typescript.autoClosingTags` : Enable/disable autoClosing of JSX tags, default: `true`
2019-04-19 20:07:15 +09:00
- `typescript.suggest.enabled` default: `true`
2020-08-08 11:03:33 +09:00
- `typescript.suggest.paths` :Enable/disable suggest paths in import statement
and require calls, default: `true`
2021-12-21 14:57:51 +09:00
- `typescript.suggest.autoImports` :Enable/disable auto import suggests,
2020-08-08 11:03:33 +09:00
default: `true`
- `typescript.suggest.completeFunctionCalls` :Enable snippet for method
suggestion, default: `true`
2021-05-28 19:45:47 +09:00
- `typescript.suggest.includeCompletionsForImportStatements` : Enable/disable
auto-import-style completions on partially-typed import statements. Requires using
TypeScript 4.3+ in the workspace, default: `true`
- `typescript.suggest.includeCompletionsWithSnippetText` : Enable snippet completions
from TS Server. Requires using TypeScript 4.3+ in the workspace, default: `true`
2021-12-21 18:00:49 +09:00
- `typescript.suggest.classMemberSnippets.enabled` : Enable/disable
2021-12-21 14:54:47 +09:00
snippet completions for class members. Requires using TypeScript 4.5+ in the
workspace, default: `true`
2021-12-21 18:22:46 +09:00
- `typescript.suggest.jsdoc.generateReturns` : Enable/disable generating
`@return` annotations for JSDoc templates. Requires using TypeScript 4.2+ in
the workspace. default: `true`
2022-01-20 00:22:30 +09:00
- `typescript.suggest.includeAutomaticOptionalChainCompletions` : default: `true`
2019-11-23 18:12:58 +09:00
- `typescript.format.enabled` :Enable/disable format of typescript files.
2019-04-19 20:07:15 +09:00
- `typescript.format.insertSpaceAfterCommaDelimiter` default: `true`
- `typescript.format.insertSpaceAfterConstructor` default: `false`
- `typescript.format.insertSpaceAfterSemicolonInForStatements` default: `true`
- `typescript.format.insertSpaceBeforeAndAfterBinaryOperators` default: `true`
2020-08-08 11:03:33 +09:00
- `typescript.format.insertSpaceAfterKeywordsInControlFlowStatements` default:
`true`
- `typescript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions`
default: `true`
2019-04-19 20:07:15 +09:00
- `typescript.format.insertSpaceBeforeFunctionParenthesis` default: `false`
2020-08-08 11:03:33 +09:00
- `typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets`
default: `false`
2020-12-10 17:55:04 +09:00
- `typescript.format.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces`
default: `false`
2020-08-08 11:03:33 +09:00
- `typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces`
default: `false`
- `typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis`
default: `false`
- `typescript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces`
default: `false`
- `typescript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces`
default: `false`
2019-04-19 20:07:15 +09:00
- `typescript.format.insertSpaceAfterTypeAssertion` default: `false`
- `typescript.format.placeOpenBraceOnNewLineForFunctions` default: `false`
- `typescript.format.placeOpenBraceOnNewLineForControlBlocks` default: `false`
2021-12-24 19:39:29 +09:00
- `typescript.inlayHints` : inlayHints related options.
2021-12-21 14:57:51 +09:00
- `javascript.format.enabled` : Enable/disable format for javascript files, default: `true`
- `javascript.showUnused` : show unused variable hint, default: `true`
2022-01-20 05:04:13 +09:00
- `javascript.autoClosingTags` : Enable/disable autoClosing of JSX tags, default: `true`
2019-04-19 20:07:15 +09:00
- `javascript.updateImportsOnFileMove.enable` default: `true`
- `javascript.implementationsCodeLens.enable` default: `true`
- `javascript.referencesCodeLens.enable` default: `true`
2022-01-13 01:29:12 +09:00
- `javascript.referencesCodeLens.showOnAllFunctions` : Enable/disable references CodeLens on all functions in JavaScript files default: `false`
2022-01-28 06:59:53 +09:00
- `javascript.preferences.importModuleSpecifier` default: `"shortest"`
2020-12-13 14:33:55 +09:00
- `javascript.preferences.importModuleSpecifierEnding` default: `"auto"`
2019-04-19 20:07:15 +09:00
- `javascript.preferences.quoteStyle` default: `"single"`
2020-08-08 11:03:33 +09:00
- `javascript.validate.enable` : Enable/disable JavaScript validation., default:
`true`
- `javascript.suggestionActions.enabled` : Enable/disable suggestion diagnostics
for JavaScript files in the editor. Requires using TypeScript 2.8 or newer in
the workspace., default: `true`
2019-11-23 18:12:58 +09:00
- `javascript.suggest.names` : default `true`
- `javascript.suggest.enabled` : default `true`
2020-08-08 11:03:33 +09:00
- `javascript.suggest.paths` : Enable/disable suggest paths in import statement
and require calls, default: `true`
- `javascript.suggest.autoImports` : Enable/disable auto import suggests.,
default: `true`
- `javascript.suggest.completeFunctionCalls` :Enable snippet for method
suggestion, default: `true`
2021-05-28 19:45:47 +09:00
- `javascript.suggest.includeCompletionsForImportStatements` : Enable/disable
auto-import-style completions on partially-typed import statements. Requires
using TypeScript 4.3+ in the workspace, default: `true`
2021-12-21 18:22:46 +09:00
- `javascript.suggest.jsdoc.generateReturns` : Enable/disable generating
`@return` annotations for JSDoc templates. Requires using TypeScript 4.2+ in
the workspace. default: `true`
2021-12-21 18:00:49 +09:00
- `javascript.suggest.classMemberSnippets.enabled` : Enable/disable
snippet completions for class members. Requires using TypeScript 4.5+ in the
workspace, default: `true`
2022-01-20 00:22:30 +09:00
- `javascript.suggest.includeAutomaticOptionalChainCompletions` : default: `true`
2019-04-19 20:07:15 +09:00
- `javascript.format.insertSpaceAfterCommaDelimiter` default: `true`
- `javascript.format.insertSpaceAfterConstructor` default: `false`
- `javascript.format.insertSpaceAfterSemicolonInForStatements` default: `true`
- `javascript.format.insertSpaceBeforeAndAfterBinaryOperators` default: `true`
2020-08-08 11:03:33 +09:00
- `javascript.format.insertSpaceAfterKeywordsInControlFlowStatements` default:
`true`
- `javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions`
default: `true`
2019-04-19 20:07:15 +09:00
- `javascript.format.insertSpaceBeforeFunctionParenthesis` default: `false`
2020-08-08 11:03:33 +09:00
- `javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets`
default: `false`
2020-12-10 17:55:04 +09:00
- `javascript.format.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces`
default: `false`
2020-08-08 11:03:33 +09:00
- `javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces`
default: `false`
- `javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis`
default: `false`
- `javascript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces`
default: `false`
- `javascript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces`
default: `false`
2019-04-19 20:07:15 +09:00
- `javascript.format.insertSpaceAfterTypeAssertion` default: `false`
- `javascript.format.placeOpenBraceOnNewLineForFunctions` default: `false`
- `javascript.format.placeOpenBraceOnNewLineForControlBlocks` default: `false`
2021-12-24 19:39:29 +09:00
- `javascript.inlayHints` : inlayHints related options.
2019-04-19 20:07:15 +09:00
2022-04-10 16:07:17 +09:00
### Added on 1.10.0
- `javascript.suggest.completeJSDocs` `typescript.suggest.completeJSDocs` :
Enable/disable suggestion to complete JSDoc comments. default: `true`
2022-04-10 16:15:32 +09:00
### Added on 1.10.1
- `typescript.suggest.objectLiteralMethodSnippets.enabled`
`javascript.suggest.objectLiteralMethodSnippets.enabled` :
Enable/disable snippet completions for methods in object literals. Requires using TypeScript 4.7+ in the workspace
2019-04-19 20:07:15 +09:00
2022-01-20 00:22:30 +09:00
Configurations are the same as with VSCode. Install
[coc-json ](https://github.com/neoclide/coc-json ) and try completion with
`tsserver` , `typescript` or `javascript` in your
`coc-settings.json` .
2018-09-07 21:40:51 +09:00
2019-03-30 21:27:10 +09:00
## Related extensions
2020-02-07 15:23:48 +09:00
- [coc-eslint ](https://github.com/neoclide/coc-eslint ): enable [eslint ](https://github.com/eslint/eslint ) plugin for tsserver to lint TypeScript and JavaScript files.
2020-07-22 17:46:17 +09:00
- [coc-tslint-plugin ](https://github.com/neoclide/coc-tslint-plugin ): enable [tslint ](https://github.com/palantir/tslint ) plugin for tsserver ([deprecated](https://github.com/palantir/tslint/issues/4534)).
2020-07-22 16:49:18 +09:00
- [coc-styled-components ](https://github.com/fannheyward/coc-styled-components/ ): Styled component for coc.nvim as a tsserver plugin.
2020-07-22 17:46:17 +09:00
- [coc-react-refactor ](https://github.com/fannheyward/coc-react-refactor ): React refactor extension for coc.nvim, forked from vscode-react-refactor.
2019-03-30 21:27:10 +09:00
- [coc-vetur ](https://github.com/neoclide/coc-vetur ): [vue ](https://github.com/vuejs/vue ) extension.
- [coc-angular ](https://github.com/iamcco/coc-angular ): [angular ](https://github.com/angular/angular ) extension.
2019-11-20 11:31:38 +09:00
## Troubleshooting
2018-10-21 14:21:25 +09:00
- Add `"tsserver.log": "verbose"` to your `coc-settings.json` (opened by command
`:CocConfig` )
2018-11-18 23:40:30 +09:00
- To trace LSP communication, add `"tsserver.trace.server": "verbose"` to your
`coc-settings.json`
- Restart coc server by command `:CocRestart`
- Make the issue happen.
- Open tsserver log file by command `CocCommand tsserver.openTsServerLog`
- Open tsserver output channel by command `CocCommand workspace.showOutput tsserver`
2018-10-21 14:21:25 +09:00
2020-08-08 11:03:33 +09:00
If you find any issues, please [create an
issue](https://github.com/neoclide/coc-tsserver/issues/new).
2019-04-20 04:52:07 +09:00
2018-09-07 21:40:51 +09:00
## License
MIT