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.
34 **Note:** if you're using WSL, copy you project files from mounted dirs to linux home otherwise tsserver will not work properly.
38 If you like my extension, consider supporting me on Patreon or PayPal:
40 <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>
41 <a href="https://www.paypal.com/paypalme/chezqm"><img src="https://werwolv.net/assets/paypal_banner.png" alt="PayPal donate button" /> </a>
45 In your vim/neovim, run command:
47 `:CocInstall coc-tsserver`
49 For yarn2 ( >= v2.0.0-rc.36) user want to use local typescript module:
51 - Run command `yarn dlx @yarnpkg/pnpify --sdk vim`, which will generate
52 `.vim/coc-settings.json`, with content:
56 "tsserver.tsdk": ".yarn/sdks/typescript/lib",
57 "eslint.packageManager": "yarn",
58 "eslint.nodePath": ".yarn/sdks"
64 Almost the same as VSCode.
66 - Supports javascript & typescript and jsx/tsx.
67 - Installs typings automatically.
68 - Commands to work with tsserver, including:
69 - `tsserver.reloadProjects`
70 - `tsserver.openTsServerLog`
71 - `tsserver.goToProjectConfig`
73 - `tsserver.organizeImports`
74 - `tsserver.watchBuild`
75 - `tsserver.findAllFileReferences`
76 - Code completion support.
77 - Go to definition (more info in [microsoft/TypeScript#37777](https://github.com/microsoft/TypeScript/issues/37777))
80 - Document symbols of current buffer.
81 - Folding and folding range of current buffer.
82 - Format current buffer, range format and format on type.
83 - Hover for documentation.
84 - Implementations codeLens and references codeLens.
85 - Organize imports command.
86 - Quickfix using code actions.
87 - Code refactor using code actions.
90 - Rename symbols support.
91 - Rename imports on file rename, require
92 [watchman](https://facebook.github.io/watchman/) installed in your \$PATH.
93 - Search for workspace symbols.
95 Tsserver module first resolved from your local workspace. If it's not found, use
96 tsserver from `tsserver.tsdk` configuration or use bundled tsserver with this
99 ## Configuration options
101 Checkout [using the configuration
102 file](https://github.com/neoclide/coc.nvim/wiki/Using-the-configuration-file)
103 for guide of coc.nvim's configuration.
105 - `tsserver.enable`:Enable tsserver extension, default: `true`
106 - `tsserver.locale`:Locale of tsserver, default: `""`
107 - `tsserver.typingsCacheLocation`:Folder path for cache typings, default: `""`
108 - `tsserver.formatOnType`:Run format on type special characters., default:
110 - `tsserver.enableJavascript`:Use tsserver for javascript files, default: `true`
111 - `tsserver.maxTsServerMemory`:Set the maximum amount of memory to allocate to
112 the TypeScript server process
113 - `tsserver.tsdk`:Directory contains tsserver.js,, default: `""`
114 - `tsserver.npm`:Executable path of npm for download typings, default: `""`
115 - `tsserver.log`:Log level of tsserver, default: `"off"`
116 - `tsserver.trace.server`:Trace level of tsserver, default: `"off"`
117 - `tsserver.pluginPaths`:Folders contains tsserver plugins, default: `[]`
118 - `tsserver.debugPort`:Debug port number of tsserver
119 - `tsserver.watchOptions`:Configure which watching strategies should be used to
120 keep track of files and directories. Requires using TypeScript 3.8+ in the
121 workspace, default: undefined.
122 - `tsserver.reportStyleChecksAsWarnings` default: `true`
123 - `tsserver.implicitProjectConfig.checkJs`:Enable checkJs for implicit project,
125 - `tsserver.implicitProjectConfig.experimentalDecorators`:Enable
126 experimentalDecorators for implicit project, default: `false`
127 - `tsserver.disableAutomaticTypeAcquisition`:Disable download of typings,
129 - `tsserver.useBatchedBufferSync`: use batched buffer synchronize support.
130 - `typescript.updateImportsOnFileMove.enable`:Enable update imports on file
131 move., default: `true`
132 - `typescript.implementationsCodeLens.enable`:Enable codeLens for
133 implementations, default: `true`
134 - `typescript.referencesCodeLens.enable`:Enable codeLens for references,
136 - `typescript.preferences.importModuleSpecifier` default: `"auto"`
137 - `typescript.preferences.importModuleSpecifierEnding` default: `"auto"`
138 - `typescript.preferences.quoteStyle` default: `"single"`
139 - `typescript.suggestionActions.enabled`:Enable/disable suggestion diagnostics
140 for TypeScript files in the editor. Requires using TypeScript 2.8 or newer in
141 the workspace., default: `true`
142 - `typescript.validate.enable`:Enable/disable TypeScript validation., default:
144 - `typescript.showUnused`: show unused variable hint, default: `true`.
145 - `typescript.autoClosingTags`: Enable/disable autoClosing of JSX tags, default: `false`.
146 - `typescript.suggest.enabled` default: `true`
147 - `typescript.suggest.paths`:Enable/disable suggest paths in import statement
148 and require calls, default: `true`
149 - `typescript.suggest.autoImports`:Enable/disable auto import suggests.,
151 - `typescript.suggest.completeFunctionCalls`:Enable snippet for method
152 suggestion, default: `true`
153 - `typescript.suggest.includeCompletionsForImportStatements`: Enable/disable
154 auto-import-style completions on partially-typed import statements. Requires using
155 TypeScript 4.3+ in the workspace, default: `true`
156 - `typescript.suggest.includeCompletionsWithSnippetText`: Enable snippet completions
157 from TS Server. Requires using TypeScript 4.3+ in the workspace, default: `true`
158 - `typescript.format.enabled`:Enable/disable format of typescript files.
159 - `typescript.format.insertSpaceAfterCommaDelimiter` default: `true`
160 - `typescript.format.insertSpaceAfterConstructor` default: `false`
161 - `typescript.format.insertSpaceAfterSemicolonInForStatements` default: `true`
162 - `typescript.format.insertSpaceBeforeAndAfterBinaryOperators` default: `true`
163 - `typescript.format.insertSpaceAfterKeywordsInControlFlowStatements` default:
165 - `typescript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions`
167 - `typescript.format.insertSpaceBeforeFunctionParenthesis` default: `false`
168 - `typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets`
170 - `typescript.format.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces`
172 - `typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces`
174 - `typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis`
176 - `typescript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces`
178 - `typescript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces`
180 - `typescript.format.insertSpaceAfterTypeAssertion` default: `false`
181 - `typescript.format.placeOpenBraceOnNewLineForFunctions` default: `false`
182 - `typescript.format.placeOpenBraceOnNewLineForControlBlocks` default: `false`
183 - `typescript.suggest.includeAutomaticOptionalChainCompletions`: default: `true`
184 - `javascript.format.enabled`: Enable/disable format for javascript files.
185 - `javascript.showUnused`: show unused variable hint.
186 - `javascript.autoClosingTags`: Enable/disable autoClosing of JSX tags, default: `false`.
187 - `javascript.updateImportsOnFileMove.enable` default: `true`
188 - `javascript.implementationsCodeLens.enable` default: `true`
189 - `javascript.referencesCodeLens.enable` default: `true`
190 - `javascript.preferences.importModuleSpecifier` default: `"auto"`
191 - `javascript.preferences.importModuleSpecifierEnding` default: `"auto"`
192 - `javascript.preferences.quoteStyle` default: `"single"`
193 - `javascript.validate.enable`: Enable/disable JavaScript validation., default:
195 - `javascript.suggestionActions.enabled`: Enable/disable suggestion diagnostics
196 for JavaScript files in the editor. Requires using TypeScript 2.8 or newer in
197 the workspace., default: `true`
198 - `javascript.suggest.names`: default `true`
199 - `javascript.suggest.enabled`: default `true`
200 - `javascript.suggest.paths`: Enable/disable suggest paths in import statement
201 and require calls, default: `true`
202 - `javascript.suggest.autoImports`: Enable/disable auto import suggests.,
204 - `javascript.suggest.completeFunctionCalls`:Enable snippet for method
205 suggestion, default: `true`
206 - `javascript.suggest.includeCompletionsForImportStatements`: Enable/disable
207 auto-import-style completions on partially-typed import statements. Requires
208 using TypeScript 4.3+ in the workspace, default: `true`
209 - `javascript.format.insertSpaceAfterCommaDelimiter` default: `true`
210 - `javascript.format.insertSpaceAfterConstructor` default: `false`
211 - `javascript.format.insertSpaceAfterSemicolonInForStatements` default: `true`
212 - `javascript.format.insertSpaceBeforeAndAfterBinaryOperators` default: `true`
213 - `javascript.format.insertSpaceAfterKeywordsInControlFlowStatements` default:
215 - `javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions`
217 - `javascript.format.insertSpaceBeforeFunctionParenthesis` default: `false`
218 - `javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets`
220 - `javascript.format.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces`
222 - `javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces`
224 - `javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis`
226 - `javascript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces`
228 - `javascript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces`
230 - `javascript.format.insertSpaceAfterTypeAssertion` default: `false`
231 - `javascript.format.placeOpenBraceOnNewLineForFunctions` default: `false`
232 - `javascript.format.placeOpenBraceOnNewLineForControlBlocks` default: `false`
233 - `javascript.suggest.includeAutomaticOptionalChainCompletions`: default: `true`
235 Configurations are the same as with VSCode. Try completion with `tsserver`,
236 `typescript` or `javascript` in your `coc-settings.json`.
238 ## Related extensions
240 - [coc-eslint](https://github.com/neoclide/coc-eslint): enable [eslint](https://github.com/eslint/eslint) plugin for tsserver to lint TypeScript and JavaScript files.
241 - [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)).
242 - [coc-styled-components](https://github.com/fannheyward/coc-styled-components/): Styled component for coc.nvim as a tsserver plugin.
243 - [coc-react-refactor](https://github.com/fannheyward/coc-react-refactor): React refactor extension for coc.nvim, forked from vscode-react-refactor.
244 - [coc-vetur](https://github.com/neoclide/coc-vetur): [vue](https://github.com/vuejs/vue) extension.
245 - [coc-angular](https://github.com/iamcco/coc-angular): [angular](https://github.com/angular/angular) extension.
249 - Add `"tsserver.log": "verbose"` to your `coc-settings.json` (opened by command
251 - To trace LSP communication, add `"tsserver.trace.server": "verbose"` to your
253 - Restart coc server by command `:CocRestart`
254 - Make the issue happen.
255 - Open tsserver log file by command `CocCommand tsserver.openTsServerLog`
256 - Open tsserver output channel by command `CocCommand workspace.showOutput tsserver`
258 If you find any issues, please [create an
259 issue](https://github.com/neoclide/coc-tsserver/issues/new).