2018-09-07 21:40:51 +09:00
# coc-tsserver
Tsserver language server extension for [coc.nvim ](https://github.com/neoclide/coc.nvim ).
2019-04-20 04:52:07 +09:00
Most of the code is from `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
`javascript.jsx` and your TSX filetype to be `typescript.jsx` or
`typescript.tsx` . In coc.nvim, these filetypes are mapped to `javascriptreact`
and `typescriptreact` because that's what tsserver uses.
2019-03-27 20:02:33 +09:00
2020-05-22 15:07:39 +09:00
**Note** for javascript project, make sure you have [jsconfig.json ](https://code.visualstudio.com/docs/languages/jsconfig )
2018-09-07 21:40:51 +09:00
## Install
In your vim/neovim, run command:
```
:CocInstall coc-tsserver
```
2020-04-17 13:19:17 +09:00
For yarn2 user what to use local typescript module:
- Add PnPify to your dependencies:
```
yarn add @yarnpkg/pnpify
```
- Run the following command, which will generate a new directory called .vscode/pnpify
```
yarn pnpify --sdk
```
2020-03-06 13:39:01 +09:00
### intructions for nvm users
Disable [nvm ](https://github.com/creationix/nvm ) with the following command:
2020-04-10 19:19:55 +09:00
2020-03-06 13:39:01 +09:00
```
nvm deactivate
```
Next, find out what the global path of your installed version of npm with the following command:
2020-04-10 19:19:55 +09:00
2020-03-06 13:39:01 +09:00
```
which npm
```
The output of the above command should go into the `tsserver.npm` property in your `coc-settings.json` file, a partial example listed below:
2020-04-10 19:19:55 +09:00
2020-03-06 13:39:01 +09:00
```
"tsserver.npm": "/usr/local/bin/npm"
```
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.format`
- `tsserver.organizeImports`
- `tsserver.watchBuild`
- Code completion support.
- Go to definition.
- 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.
- Rename symbols support.
2019-08-17 18:59:50 +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.
2018-09-07 21:40:51 +09:00
2019-06-27 11:43:32 +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
2019-11-23 19:40:48 +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-04-19 20:07:15 +09:00
- `tsserver.enable` :Enable tsserver extension, default: `true`
- `tsserver.locale` :Locale of tsserver, default: `""`
- `tsserver.typingsCacheLocation` :Folder path for cache typings, default: `""`
- `tsserver.formatOnType` :Run format on type special characters., default: `true`
- `tsserver.enableJavascript` :Use tsserver for javascript files, default: `true`
2020-03-23 12:31:53 +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"`
- `tsserver.pluginRoot` :Folder contains tsserver plugins, default: `[]`
- `tsserver.debugPort` :Debug port number of tsserver
2020-04-17 19:58:07 +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 workspace, default: undefined.
2019-04-19 20:07:15 +09:00
- `tsserver.reportStyleChecksAsWarnings` default: `true`
- `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`
2019-09-23 14:12:38 +09:00
- `tsserver.useBatchedBufferSync` : use batched buffer synchronize support.
2019-04-19 20:07:15 +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`
2020-04-10 19:50:14 +09:00
- `typescript.preferences.importModuleSpecifier` default: `"auto"`
2020-04-10 20:52:24 +09:00
- `typescript.preferences.importModuleSpecifierEnding` default: `true`
2019-04-19 20:07:15 +09:00
- `typescript.preferences.quoteStyle` default: `"single"`
- `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` .
2019-04-19 20:07:15 +09:00
- `typescript.suggest.enabled` default: `true`
- `typescript.suggest.paths` :Enable/disable suggest paths in import statement and require calls, default: `true`
- `typescript.suggest.autoImports` :Enable/disable auto import suggests., default: `true`
- `typescript.suggest.completeFunctionCalls` :Enable snippet for method suggestion, 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`
- `typescript.format.insertSpaceAfterKeywordsInControlFlowStatements` default: `true`
- `typescript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions` default: `true`
- `typescript.format.insertSpaceBeforeFunctionParenthesis` default: `false`
2019-06-03 22:43:48 +09:00
- `typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets` default: `false`
- `typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces` default: `false`
2019-04-19 20:07:15 +09:00
- `typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis` default: `false`
- `typescript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces` default: `false`
- `typescript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces` default: `false`
- `typescript.format.insertSpaceAfterTypeAssertion` default: `false`
- `typescript.format.placeOpenBraceOnNewLineForFunctions` default: `false`
- `typescript.format.placeOpenBraceOnNewLineForControlBlocks` default: `false`
2020-04-10 19:19:55 +09:00
- `typescript.suggest.includeAutomaticOptionalChainCompletions` : default: `true`
2019-11-23 18:12:58 +09:00
- `javascript.format.enabled` : Enable/disable format for javascript files.
2019-06-10 03:24:30 +09:00
- `javascript.showUnused` : show unused variable hint.
2019-04-19 20:07:15 +09:00
- `javascript.updateImportsOnFileMove.enable` default: `true`
- `javascript.implementationsCodeLens.enable` default: `true`
- `javascript.referencesCodeLens.enable` default: `true`
2020-04-10 19:50:14 +09:00
- `javascript.preferences.importModuleSpecifier` default: `"auto"`
2020-04-10 20:52:24 +09:00
- `javascript.preferences.importModuleSpecifierEnding` default: `true`
2019-04-19 20:07:15 +09:00
- `javascript.preferences.quoteStyle` default: `"single"`
2019-11-23 18:12:58 +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`
- `javascript.suggest.names` : default `true`
- `javascript.suggest.enabled` : default `true`
- `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`
2019-04-19 20:07:15 +09:00
- `javascript.suggest.completeFunctionCalls` :Enable snippet for method suggestion, default: `true`
- `javascript.format.insertSpaceAfterCommaDelimiter` default: `true`
- `javascript.format.insertSpaceAfterConstructor` default: `false`
- `javascript.format.insertSpaceAfterSemicolonInForStatements` default: `true`
- `javascript.format.insertSpaceBeforeAndAfterBinaryOperators` default: `true`
- `javascript.format.insertSpaceAfterKeywordsInControlFlowStatements` default: `true`
- `javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions` default: `true`
- `javascript.format.insertSpaceBeforeFunctionParenthesis` default: `false`
2019-06-03 22:43:48 +09:00
- `javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets` default: `false`
- `javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces` default: `false`
2019-04-19 20:07:15 +09:00
- `javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis` default: `false`
- `javascript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces` default: `false`
- `javascript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces` default: `false`
- `javascript.format.insertSpaceAfterTypeAssertion` default: `false`
- `javascript.format.placeOpenBraceOnNewLineForFunctions` default: `false`
- `javascript.format.placeOpenBraceOnNewLineForControlBlocks` default: `false`
2020-04-10 19:19:55 +09:00
- `javascript.suggest.includeAutomaticOptionalChainCompletions` : default: `true`
2019-04-19 20:07:15 +09:00
2019-04-20 04:52:07 +09:00
Configurations are the same as with VSCode. Try completion with `tsserver` , `typescript`
2019-04-19 20:07:15 +09:00
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.
2019-03-30 21:27:10 +09:00
- [coc-tslint-plugin ](https://github.com/neoclide/coc-tslint-plugin ): enable [tslint ](https://github.com/palantir/tslint )
2020-02-07 15:23:48 +09:00
plugin for tsserver ([deprecated](https://github.com/palantir/tslint/issues/4534)).
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
2019-04-20 04:52:07 +09:00
If you find any issues, please [create an issue ](https://github.com/neoclide/coc-tsserver/issues/new ).
2018-09-07 21:40:51 +09:00
## License
MIT