My dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Readme.md 10 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. # coc-tsserver
  2. Tsserver language server extension for [coc.nvim](https://github.com/neoclide/coc.nvim).
  3. Most of the code is from `typescript-language-features` extension which is bundled with VSCode.
  4. **Note:** for React to work as expected, you need your JSX filetype to be
  5. `javascript.jsx` and your TSX filetype to be `typescript.jsx` or
  6. `typescript.tsx`. In coc.nvim, these filetypes are mapped to `javascriptreact`
  7. and `typescriptreact` because that's what tsserver uses.
  8. **Note** for javascript project, make sure you have [jsconfig.json](https://code.visualstudio.com/docs/languages/jsconfig)
  9. ## Install
  10. In your vim/neovim, run command:
  11. ```
  12. :CocInstall coc-tsserver
  13. ```
  14. For yarn2 user what to use local typescript module:
  15. - Add PnPify to your dependencies:
  16. ```
  17. yarn add @yarnpkg/pnpify
  18. ```
  19. - Run the following command, which will generate a new directory called .vscode/pnpify
  20. ```
  21. yarn pnpify --sdk
  22. ```
  23. ### intructions for nvm users
  24. Disable [nvm](https://github.com/creationix/nvm) with the following command:
  25. ```
  26. nvm deactivate
  27. ```
  28. Next, find out what the global path of your installed version of npm with the following command:
  29. ```
  30. which npm
  31. ```
  32. The output of the above command should go into the `tsserver.npm` property in your `coc-settings.json` file, a partial example listed below:
  33. ```
  34. "tsserver.npm": "/usr/local/bin/npm"
  35. ```
  36. ## Features
  37. Almost the same as VSCode.
  38. - Supports javascript & typescript and jsx/tsx.
  39. - Installs typings automatically.
  40. - Commands to work with tsserver, including:
  41. - `tsserver.reloadProjects`
  42. - `tsserver.openTsServerLog`
  43. - `tsserver.goToProjectConfig`
  44. - `tsserver.restart`
  45. - `tsserver.format`
  46. - `tsserver.organizeImports`
  47. - `tsserver.watchBuild`
  48. - Code completion support.
  49. - Go to definition.
  50. - Code validation.
  51. - Document highlight.
  52. - Document symbols of current buffer.
  53. - Folding and folding range of current buffer.
  54. - Format current buffer, range format and format on type.
  55. - Hover for documentation.
  56. - Implementations codeLens and references codeLens.
  57. - Organize imports command.
  58. - Quickfix using code actions.
  59. - Code refactor using code actions.
  60. - Find references.
  61. - Signature help.
  62. - Rename symbols support.
  63. - Rename imports on file rename, require [watchman](https://facebook.github.io/watchman/) installed in your \$PATH.
  64. - Search for workspace symbols.
  65. Tsserver module first resolved from your local workspace. If it's not found,
  66. use tsserver from `tsserver.tsdk` configuration or use bundled tsserver with
  67. this extension.
  68. ## Configuration options
  69. Checkout [using the configuration file](https://github.com/neoclide/coc.nvim/wiki/Using-the-configuration-file) for guide of coc.nvim's configuration.
  70. - `tsserver.enable`:Enable tsserver extension, default: `true`
  71. - `tsserver.locale`:Locale of tsserver, default: `""`
  72. - `tsserver.typingsCacheLocation`:Folder path for cache typings, default: `""`
  73. - `tsserver.formatOnType`:Run format on type special characters., default: `true`
  74. - `tsserver.enableJavascript`:Use tsserver for javascript files, default: `true`
  75. - `tsserver.maxTsServerMemory`:Set the maximum amount of memory to allocate to the TypeScript server process
  76. - `tsserver.tsdk`:Directory contains tsserver.js,, default: `""`
  77. - `tsserver.npm`:Executable path of npm for download typings, default: `""`
  78. - `tsserver.log`:Log level of tsserver, default: `"off"`
  79. - `tsserver.trace.server`:Trace level of tsserver, default: `"off"`
  80. - `tsserver.pluginRoot`:Folder contains tsserver plugins, default: `[]`
  81. - `tsserver.debugPort`:Debug port number of tsserver
  82. - `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.
  83. - `tsserver.reportStyleChecksAsWarnings` default: `true`
  84. - `tsserver.implicitProjectConfig.checkJs`:Enable checkJs for implicit project, default: `false`
  85. - `tsserver.implicitProjectConfig.experimentalDecorators`:Enable experimentalDecorators for implicit project, default: `false`
  86. - `tsserver.disableAutomaticTypeAcquisition`:Disable download of typings, default: `false`
  87. - `tsserver.useBatchedBufferSync`: use batched buffer synchronize support.
  88. - `typescript.updateImportsOnFileMove.enable`:Enable update imports on file move., default: `true`
  89. - `typescript.implementationsCodeLens.enable`:Enable codeLens for implementations, default: `true`
  90. - `typescript.referencesCodeLens.enable`:Enable codeLens for references, default: `true`
  91. - `typescript.preferences.importModuleSpecifier` default: `"auto"`
  92. - `typescript.preferences.importModuleSpecifierEnding` default: `true`
  93. - `typescript.preferences.quoteStyle` default: `"single"`
  94. - `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`
  95. - `typescript.validate.enable`:Enable/disable TypeScript validation., default: `true`
  96. - `typescript.showUnused`: show unused variable hint, default: `true`.
  97. - `typescript.suggest.enabled` default: `true`
  98. - `typescript.suggest.paths`:Enable/disable suggest paths in import statement and require calls, default: `true`
  99. - `typescript.suggest.autoImports`:Enable/disable auto import suggests., default: `true`
  100. - `typescript.suggest.completeFunctionCalls`:Enable snippet for method suggestion, default: `true`
  101. - `typescript.format.enabled`:Enable/disable format of typescript files.
  102. - `typescript.format.insertSpaceAfterCommaDelimiter` default: `true`
  103. - `typescript.format.insertSpaceAfterConstructor` default: `false`
  104. - `typescript.format.insertSpaceAfterSemicolonInForStatements` default: `true`
  105. - `typescript.format.insertSpaceBeforeAndAfterBinaryOperators` default: `true`
  106. - `typescript.format.insertSpaceAfterKeywordsInControlFlowStatements` default: `true`
  107. - `typescript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions` default: `true`
  108. - `typescript.format.insertSpaceBeforeFunctionParenthesis` default: `false`
  109. - `typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets` default: `false`
  110. - `typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces` default: `false`
  111. - `typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis` default: `false`
  112. - `typescript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces` default: `false`
  113. - `typescript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces` default: `false`
  114. - `typescript.format.insertSpaceAfterTypeAssertion` default: `false`
  115. - `typescript.format.placeOpenBraceOnNewLineForFunctions` default: `false`
  116. - `typescript.format.placeOpenBraceOnNewLineForControlBlocks` default: `false`
  117. - `typescript.suggest.includeAutomaticOptionalChainCompletions`: default: `true`
  118. - `javascript.format.enabled`: Enable/disable format for javascript files.
  119. - `javascript.showUnused`: show unused variable hint.
  120. - `javascript.updateImportsOnFileMove.enable` default: `true`
  121. - `javascript.implementationsCodeLens.enable` default: `true`
  122. - `javascript.referencesCodeLens.enable` default: `true`
  123. - `javascript.preferences.importModuleSpecifier` default: `"auto"`
  124. - `javascript.preferences.importModuleSpecifierEnding` default: `true`
  125. - `javascript.preferences.quoteStyle` default: `"single"`
  126. - `javascript.validate.enable`: Enable/disable JavaScript validation., default: `true`
  127. - `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`
  128. - `javascript.suggest.names`: default `true`
  129. - `javascript.suggest.enabled`: default `true`
  130. - `javascript.suggest.paths`: Enable/disable suggest paths in import statement and require calls, default: `true`
  131. - `javascript.suggest.autoImports`: Enable/disable auto import suggests., default: `true`
  132. - `javascript.suggest.completeFunctionCalls`:Enable snippet for method suggestion, default: `true`
  133. - `javascript.format.insertSpaceAfterCommaDelimiter` default: `true`
  134. - `javascript.format.insertSpaceAfterConstructor` default: `false`
  135. - `javascript.format.insertSpaceAfterSemicolonInForStatements` default: `true`
  136. - `javascript.format.insertSpaceBeforeAndAfterBinaryOperators` default: `true`
  137. - `javascript.format.insertSpaceAfterKeywordsInControlFlowStatements` default: `true`
  138. - `javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions` default: `true`
  139. - `javascript.format.insertSpaceBeforeFunctionParenthesis` default: `false`
  140. - `javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets` default: `false`
  141. - `javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces` default: `false`
  142. - `javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis` default: `false`
  143. - `javascript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces` default: `false`
  144. - `javascript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces` default: `false`
  145. - `javascript.format.insertSpaceAfterTypeAssertion` default: `false`
  146. - `javascript.format.placeOpenBraceOnNewLineForFunctions` default: `false`
  147. - `javascript.format.placeOpenBraceOnNewLineForControlBlocks` default: `false`
  148. - `javascript.suggest.includeAutomaticOptionalChainCompletions`: default: `true`
  149. Configurations are the same as with VSCode. Try completion with `tsserver`, `typescript`
  150. or `javascript` in your `coc-settings.json`.
  151. ## Related extensions
  152. - [coc-eslint](https://github.com/neoclide/coc-eslint): enable [eslint](https://github.com/eslint/eslint) plugin for tsserver to lint TypeScript and JavaScript files.
  153. - [coc-tslint-plugin](https://github.com/neoclide/coc-tslint-plugin): enable [tslint](https://github.com/palantir/tslint)
  154. plugin for tsserver ([deprecated](https://github.com/palantir/tslint/issues/4534)).
  155. - [coc-vetur](https://github.com/neoclide/coc-vetur): [vue](https://github.com/vuejs/vue) extension.
  156. - [coc-angular](https://github.com/iamcco/coc-angular): [angular](https://github.com/angular/angular) extension.
  157. ## Troubleshooting
  158. - Add `"tsserver.log": "verbose"` to your `coc-settings.json` (opened by command
  159. `:CocConfig`)
  160. - To trace LSP communication, add `"tsserver.trace.server": "verbose"` to your
  161. `coc-settings.json`
  162. - Restart coc server by command `:CocRestart`
  163. - Make the issue happen.
  164. - Open tsserver log file by command `CocCommand tsserver.openTsServerLog`
  165. - Open tsserver output channel by command `CocCommand workspace.showOutput tsserver`
  166. If you find any issues, please [create an issue](https://github.com/neoclide/coc-tsserver/issues/new).
  167. ## License
  168. MIT