3 Tsserver language server extension for
4 [coc.nvim](https://github.com/neoclide/coc.nvim).
6 Tsserver is part of [TypeScript](https://github.com/microsoft/TypeScript) which
7 provide rich features for javascript and typescript.
9 This extension is a fork of `typescript-language-features` extension which is
12 **Note:** for React to work as expected, you need your JSX filetype to be
13 `javascript.jsx` or `javascriptreact` and your TSX filetype to be
14 `typescript.jsx` or `typescript.tsx` or `typescriptreact`. In coc.nvim, these
15 filetypes are mapped to `javascriptreact` and `typescriptreact` because that's
16 what tsserver uses. For filetype like `typescript.javascript`, you need
17 configure `g:coc_filetype_map` variable in vimrc.
19 **Note** for javascript project, configure
20 [jsconfig.json](https://code.visualstudio.com/docs/languages/jsconfig) to make
21 tsserver understand your code.
23 **Note:** for rename import on file rename, you have to install
24 [watchman](https://facebook.github.io/watchman/) in your \$PATH.
26 **Note:** for [nvm](https://github.com/creationix/nvm) users, you need configure
27 `tsserver.npm` to your global npm path or configure
28 `"tsserver.disableAutomaticTypeAcquisition": false` to disable automatic typings
31 **Note:** tsserver could be quite slow to initialize on big project, exclude
32 unneunnecessary files in your jsconfig.json/tsconfig.json.
36 If you like my extension, consider supporting me on Patreon or PayPal:
38 <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>
39 <a href="https://www.paypal.com/paypalme/chezqm"><img src="https://werwolv.net/assets/paypal_banner.png" alt="PayPal donate button" /> </a>
43 In your vim/neovim, run command:
45 `:CocInstall coc-tsserver`
47 For yarn2 ( >= v2.0.0-rc.36) user want to use local typescript module:
49 - Run command `yarn dlx @yarnpkg/pnpify --sdk vim`, which will generate
50 `.vim/coc-settings.json`, with content:
54 "tsserver.tsdk": ".yarn/sdks/typescript/lib",
55 "eslint.packageManager": "yarn",
56 "eslint.nodePath": ".yarn/sdks"
62 Almost the same as VSCode.
64 - Supports javascript & typescript and jsx/tsx.
65 - Installs typings automatically.
66 - Commands to work with tsserver, including:
67 - `tsserver.reloadProjects`
68 - `tsserver.openTsServerLog`
69 - `tsserver.goToProjectConfig`
71 - `tsserver.organizeImports`
72 - `tsserver.watchBuild`
73 - Code completion support.
77 - Document symbols of current buffer.
78 - Folding and folding range of current buffer.
79 - Format current buffer, range format and format on type.
80 - Hover for documentation.
81 - Implementations codeLens and references codeLens.
82 - Organize imports command.
83 - Quickfix using code actions.
84 - Code refactor using code actions.
87 - Rename symbols support.
88 - Rename imports on file rename, require
89 [watchman](https://facebook.github.io/watchman/) installed in your \$PATH.
90 - Search for workspace symbols.
92 Tsserver module first resolved from your local workspace. If it's not found, use
93 tsserver from `tsserver.tsdk` configuration or use bundled tsserver with this
96 ## Configuration options
98 Checkout [using the configuration
99 file](https://github.com/neoclide/coc.nvim/wiki/Using-the-configuration-file)
100 for guide of coc.nvim's configuration.
102 - `tsserver.enable`:Enable tsserver extension, default: `true`
103 - `tsserver.locale`:Locale of tsserver, default: `""`
104 - `tsserver.typingsCacheLocation`:Folder path for cache typings, default: `""`
105 - `tsserver.formatOnType`:Run format on type special characters., default:
107 - `tsserver.enableJavascript`:Use tsserver for javascript files, default: `true`
108 - `tsserver.maxTsServerMemory`:Set the maximum amount of memory to allocate to
109 the TypeScript server process
110 - `tsserver.tsdk`:Directory contains tsserver.js,, default: `""`
111 - `tsserver.npm`:Executable path of npm for download typings, default: `""`
112 - `tsserver.log`:Log level of tsserver, default: `"off"`
113 - `tsserver.trace.server`:Trace level of tsserver, default: `"off"`
114 - `tsserver.pluginPaths`:Folders contains tsserver plugins, default: `[]`
115 - `tsserver.debugPort`:Debug port number of tsserver
116 - `tsserver.watchOptions`:Configure which watching strategies should be used to
117 keep track of files and directories. Requires using TypeScript 3.8+ in the
118 workspace, default: undefined.
119 - `tsserver.reportStyleChecksAsWarnings` default: `true`
120 - `tsserver.implicitProjectConfig.checkJs`:Enable checkJs for implicit project,
122 - `tsserver.implicitProjectConfig.experimentalDecorators`:Enable
123 experimentalDecorators for implicit project, default: `false`
124 - `tsserver.disableAutomaticTypeAcquisition`:Disable download of typings,
126 - `tsserver.useBatchedBufferSync`: use batched buffer synchronize support.
127 - `typescript.updateImportsOnFileMove.enable`:Enable update imports on file
128 move., default: `true`
129 - `typescript.implementationsCodeLens.enable`:Enable codeLens for
130 implementations, default: `true`
131 - `typescript.referencesCodeLens.enable`:Enable codeLens for references,
133 - `typescript.preferences.importModuleSpecifier` default: `"auto"`
134 - `typescript.preferences.importModuleSpecifierEnding` default: `"auto"`
135 - `typescript.preferences.quoteStyle` default: `"single"`
136 - `typescript.suggestionActions.enabled`:Enable/disable suggestion diagnostics
137 for TypeScript files in the editor. Requires using TypeScript 2.8 or newer in
138 the workspace., default: `true`
139 - `typescript.validate.enable`:Enable/disable TypeScript validation., default:
141 - `typescript.showUnused`: show unused variable hint, default: `true`.
142 - `typescript.suggest.enabled` default: `true`
143 - `typescript.suggest.paths`:Enable/disable suggest paths in import statement
144 and require calls, default: `true`
145 - `typescript.suggest.autoImports`:Enable/disable auto import suggests.,
147 - `typescript.suggest.completeFunctionCalls`:Enable snippet for method
148 suggestion, default: `true`
149 - `typescript.format.enabled`:Enable/disable format of typescript files.
150 - `typescript.format.insertSpaceAfterCommaDelimiter` default: `true`
151 - `typescript.format.insertSpaceAfterConstructor` default: `false`
152 - `typescript.format.insertSpaceAfterSemicolonInForStatements` default: `true`
153 - `typescript.format.insertSpaceBeforeAndAfterBinaryOperators` default: `true`
154 - `typescript.format.insertSpaceAfterKeywordsInControlFlowStatements` default:
156 - `typescript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions`
158 - `typescript.format.insertSpaceBeforeFunctionParenthesis` default: `false`
159 - `typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets`
161 - `typescript.format.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces`
163 - `typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces`
165 - `typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis`
167 - `typescript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces`
169 - `typescript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces`
171 - `typescript.format.insertSpaceAfterTypeAssertion` default: `false`
172 - `typescript.format.placeOpenBraceOnNewLineForFunctions` default: `false`
173 - `typescript.format.placeOpenBraceOnNewLineForControlBlocks` default: `false`
174 - `typescript.suggest.includeAutomaticOptionalChainCompletions`: default: `true`
175 - `javascript.format.enabled`: Enable/disable format for javascript files.
176 - `javascript.showUnused`: show unused variable hint.
177 - `javascript.updateImportsOnFileMove.enable` default: `true`
178 - `javascript.implementationsCodeLens.enable` default: `true`
179 - `javascript.referencesCodeLens.enable` default: `true`
180 - `javascript.preferences.importModuleSpecifier` default: `"auto"`
181 - `javascript.preferences.importModuleSpecifierEnding` default: `"auto"`
182 - `javascript.preferences.quoteStyle` default: `"single"`
183 - `javascript.validate.enable`: Enable/disable JavaScript validation., default:
185 - `javascript.suggestionActions.enabled`: Enable/disable suggestion diagnostics
186 for JavaScript files in the editor. Requires using TypeScript 2.8 or newer in
187 the workspace., default: `true`
188 - `javascript.suggest.names`: default `true`
189 - `javascript.suggest.enabled`: default `true`
190 - `javascript.suggest.paths`: Enable/disable suggest paths in import statement
191 and require calls, default: `true`
192 - `javascript.suggest.autoImports`: Enable/disable auto import suggests.,
194 - `javascript.suggest.completeFunctionCalls`:Enable snippet for method
195 suggestion, default: `true`
196 - `javascript.format.insertSpaceAfterCommaDelimiter` default: `true`
197 - `javascript.format.insertSpaceAfterConstructor` default: `false`
198 - `javascript.format.insertSpaceAfterSemicolonInForStatements` default: `true`
199 - `javascript.format.insertSpaceBeforeAndAfterBinaryOperators` default: `true`
200 - `javascript.format.insertSpaceAfterKeywordsInControlFlowStatements` default:
202 - `javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions`
204 - `javascript.format.insertSpaceBeforeFunctionParenthesis` default: `false`
205 - `javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets`
207 - `javascript.format.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces`
209 - `javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces`
211 - `javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis`
213 - `javascript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces`
215 - `javascript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces`
217 - `javascript.format.insertSpaceAfterTypeAssertion` default: `false`
218 - `javascript.format.placeOpenBraceOnNewLineForFunctions` default: `false`
219 - `javascript.format.placeOpenBraceOnNewLineForControlBlocks` default: `false`
220 - `javascript.suggest.includeAutomaticOptionalChainCompletions`: default: `true`
222 Configurations are the same as with VSCode. Try completion with `tsserver`,
223 `typescript` or `javascript` in your `coc-settings.json`.
225 ## Related extensions
227 - [coc-eslint](https://github.com/neoclide/coc-eslint): enable [eslint](https://github.com/eslint/eslint) plugin for tsserver to lint TypeScript and JavaScript files.
228 - [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)).
229 - [coc-styled-components](https://github.com/fannheyward/coc-styled-components/): Styled component for coc.nvim as a tsserver plugin.
230 - [coc-react-refactor](https://github.com/fannheyward/coc-react-refactor): React refactor extension for coc.nvim, forked from vscode-react-refactor.
231 - [coc-vetur](https://github.com/neoclide/coc-vetur): [vue](https://github.com/vuejs/vue) extension.
232 - [coc-angular](https://github.com/iamcco/coc-angular): [angular](https://github.com/angular/angular) extension.
236 - Add `"tsserver.log": "verbose"` to your `coc-settings.json` (opened by command
238 - To trace LSP communication, add `"tsserver.trace.server": "verbose"` to your
240 - Restart coc server by command `:CocRestart`
241 - Make the issue happen.
242 - Open tsserver log file by command `CocCommand tsserver.openTsServerLog`
243 - Open tsserver output channel by command `CocCommand workspace.showOutput tsserver`
245 If you find any issues, please [create an
246 issue](https://github.com/neoclide/coc-tsserver/issues/new).