| .github | ||
| snippets | ||
| src | ||
| .gitignore | ||
| .npmignore | ||
| esbuild.js | ||
| history.md | ||
| package.json | ||
| Readme.md | ||
| tsconfig.json | ||
| yarn.lock | ||
Local Change
Support disabling suggestionActions by code number.
Example
In coc-settings.json:
{
"typescript.suggestionActions.disabledCodes": [80001, 80002],
"javascript.suggestionActions.disabledCodes": [80001, 80002, 7016]
}
coc-tsserver
Tsserver language server extension for coc.nvim.
Tsserver is part of TypeScript which provide rich features for javascript and typescript.
This extension is a fork of typescript-language-features extension which is
bundled with VSCode.
Note: for React to work as expected, you need your JSX filetype to be
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
what tsserver uses. For filetype like typescript.javascript, you need
configure g:coc_filetype_map variable in vimrc.
Note for javascript project, configure jsconfig.json to make tsserver understand your code.
Note: for rename import on file rename, you have to install watchman in your $PATH.
Note: for 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 unnecessary files in your jsconfig.json/tsconfig.json.
Note: if you're using WSL, copy you project files from mounted dirs to linux home otherwise tsserver will not work properly.
Supporting
If you like my extension, consider supporting me on Patreon or PayPal:
Install
In your vim/neovim, run command:
:CocInstall coc-tsserver
For yarn2 ( >= v2.0.0-rc.36) user want to use local typescript module:
-
Run command
yarn dlx @yarnpkg/sdks vim, which will generate.vim/coc-settings.json, with content:{ "eslint.packageManager": "yarn", "eslint.nodePath": ".yarn/sdks", "workspace.workspaceFolderCheckCwd": false, "tsserver.tsdk": ".yarn/sdks/typescript/lib" }
Features
Almost the same as VSCode.
- Supports javascript & typescript and jsx/tsx.
- Installs typings automatically.
- Commands to work with tsserver, including:
tsserver.reloadProjectstsserver.openTsServerLogtsserver.goToProjectConfigtsserver.restarttsserver.organizeImportstsserver.watchBuildtsserver.findAllFileReferences
- Code completion support.
- Go to definition (more info in microsoft/TypeScript#37777)
- 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.
- Call hierarchy.
- Selection range.
- Semantic tokens.
- Rename symbols support.
- Automatic tag closing.
- Rename imports on file rename, require watchman installed in your $PATH.
- Search for workspace symbols.
- 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.inlayHintsorjavascript.inlayHints.
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.
Configuration options
Checkout using the configuration file for guide of coc.nvim's configuration.
tsserver.enable:Enable tsserver extension, default:truetsserver.locale:Locale of tsserver, default:""tsserver.ignoreLocalTsserver:Always use tsserver module from tsserver.tsdk or coc-tsserver extension.tsserver.typingsCacheLocation:Folder path for cache typings, default:""tsserver.formatOnType:Run format on type special characters., default:truetsserver.enableJavascript:Use tsserver for javascript files, default:truetsserver.maxTsServerMemory:Set the maximum amount of memory to allocate to the TypeScript server processtsserver.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.pluginPaths:Folders contains tsserver plugins, default:[]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:undefinedtsserver.reportStyleChecksAsWarningsdefault:truetsserver.implicitProjectConfig.checkJs:Enable checkJs for implicit project, default:falsetsserver.implicitProjectConfig.experimentalDecorators:Enable experimentalDecorators for implicit project, default:falsetsserver.disableAutomaticTypeAcquisition:Disable download of typings, default:falsetsserver.useBatchedBufferSync: use batched buffer synchronize support, default:truetsserver.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:falsetypescript.check.npmIsInstalled: Check if npm is installed for Automatic Type Acquisition.typescript.updateImportsOnFileMove.enable:Enable update imports on file move., default:truetypescript.implementationsCodeLens.enable:Enable codeLens for implementations, default:truetypescript.referencesCodeLens.enable:Enable codeLens for references, default:truetypescript.referencesCodeLens.showOnAllFunctions: Enable/disable references CodeLens on all functions in typescript files. Default:falsetypescript.preferences.importModuleSpecifierdefault:"shortest"typescript.preferences.importModuleSpecifierEndingdefault:"auto"typescript.preferences.quoteStyledefault:"single"typescript.preferences.includePackageJsonAutoImports: Enable/disable searchingpackage.jsondependencies for available auto imports, default:"auto"typescript.suggestionActions.enabled:Enable/disable suggestion diagnostics for TypeScript files in the editor. Requires using TypeScript 2.8 or newer in the workspace., default:truetypescript.validate.enable:Enable/disable TypeScript validation., default:truetypescript.showUnused: show unused variable hint, default:true.typescript.autoClosingTags: Enable/disable autoClosing of JSX tags, default:truetypescript.suggest.enableddefault:truetypescript.suggest.paths:Enable/disable suggest paths in import statement and require calls, default:truetypescript.suggest.autoImports:Enable/disable auto import suggests, default:truetypescript.suggest.completeFunctionCalls:Enable snippet for method suggestion, default:truetypescript.suggest.includeCompletionsForImportStatements: Enable/disable auto-import-style completions on partially-typed import statements. Requires using TypeScript 4.3+ in the workspace, default:truetypescript.suggest.includeCompletionsWithSnippetText: Enable snippet completions from TS Server. Requires using TypeScript 4.3+ in the workspace, default:truetypescript.suggest.classMemberSnippets.enabled: Enable/disable snippet completions for class members. Requires using TypeScript 4.5+ in the workspace, default:truetypescript.suggest.jsdoc.generateReturns: Enable/disable generating@returnannotations for JSDoc templates. Requires using TypeScript 4.2+ in the workspace. default:truetypescript.suggest.includeAutomaticOptionalChainCompletions: default:truetypescript.format.enabled:Enable/disable format of typescript files.typescript.format.insertSpaceAfterCommaDelimiterdefault:truetypescript.format.insertSpaceAfterConstructordefault:falsetypescript.format.insertSpaceAfterSemicolonInForStatementsdefault:truetypescript.format.insertSpaceBeforeAndAfterBinaryOperatorsdefault:truetypescript.format.insertSpaceAfterKeywordsInControlFlowStatementsdefault:truetypescript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctionsdefault:truetypescript.format.insertSpaceBeforeFunctionParenthesisdefault:falsetypescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBracketsdefault:falsetypescript.format.insertSpaceAfterOpeningAndBeforeClosingEmptyBracesdefault:falsetypescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBracesdefault:falsetypescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesisdefault:falsetypescript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBracesdefault:falsetypescript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBracesdefault:falsetypescript.format.insertSpaceAfterTypeAssertiondefault:falsetypescript.format.placeOpenBraceOnNewLineForFunctionsdefault:falsetypescript.format.placeOpenBraceOnNewLineForControlBlocksdefault:falsetypescript.inlayHints: inlayHints related options.javascript.format.enabled: Enable/disable format for javascript files, default:truejavascript.showUnused: show unused variable hint, default:truejavascript.autoClosingTags: Enable/disable autoClosing of JSX tags, default:truejavascript.updateImportsOnFileMove.enabledefault:truejavascript.implementationsCodeLens.enabledefault:truejavascript.referencesCodeLens.enabledefault:truejavascript.referencesCodeLens.showOnAllFunctions: Enable/disable references CodeLens on all functions in JavaScript files default:falsejavascript.preferences.importModuleSpecifierdefault:"shortest"javascript.preferences.importModuleSpecifierEndingdefault:"auto"javascript.preferences.quoteStyledefault:"single"javascript.validate.enable: Enable/disable JavaScript validation., default:truejavascript.suggestionActions.enabled: Enable/disable suggestion diagnostics for JavaScript files in the editor. Requires using TypeScript 2.8 or newer in the workspace., default:truejavascript.suggest.names: defaulttruejavascript.suggest.enabled: defaulttruejavascript.suggest.paths: Enable/disable suggest paths in import statement and require calls, default:truejavascript.suggest.autoImports: Enable/disable auto import suggests., default:truejavascript.suggest.completeFunctionCalls:Enable snippet for method suggestion, default:truejavascript.suggest.includeCompletionsForImportStatements: Enable/disable auto-import-style completions on partially-typed import statements. Requires using TypeScript 4.3+ in the workspace, default:truejavascript.suggest.jsdoc.generateReturns: Enable/disable generating@returnannotations for JSDoc templates. Requires using TypeScript 4.2+ in the workspace. default:truejavascript.suggest.classMemberSnippets.enabled: Enable/disable snippet completions for class members. Requires using TypeScript 4.5+ in the workspace, default:truejavascript.suggest.includeAutomaticOptionalChainCompletions: default:truejavascript.format.insertSpaceAfterCommaDelimiterdefault:truejavascript.format.insertSpaceAfterConstructordefault:falsejavascript.format.insertSpaceAfterSemicolonInForStatementsdefault:truejavascript.format.insertSpaceBeforeAndAfterBinaryOperatorsdefault:truejavascript.format.insertSpaceAfterKeywordsInControlFlowStatementsdefault:truejavascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctionsdefault:truejavascript.format.insertSpaceBeforeFunctionParenthesisdefault:falsejavascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBracketsdefault:falsejavascript.format.insertSpaceAfterOpeningAndBeforeClosingEmptyBracesdefault:falsejavascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBracesdefault:falsejavascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesisdefault:falsejavascript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBracesdefault:falsejavascript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBracesdefault:falsejavascript.format.insertSpaceAfterTypeAssertiondefault:falsejavascript.format.placeOpenBraceOnNewLineForFunctionsdefault:falsejavascript.format.placeOpenBraceOnNewLineForControlBlocksdefault:falsejavascript.inlayHints: inlayHints related options.
Added on 1.10.0
javascript.suggest.completeJSDocstypescript.suggest.completeJSDocs: Enable/disable suggestion to complete JSDoc comments. default:true
Added on 1.10.1
typescript.suggest.objectLiteralMethodSnippets.enabledjavascript.suggest.objectLiteralMethodSnippets.enabled: Enable/disable snippet completions for methods in object literals. Requires using TypeScript 4.7+ in the workspace
Configurations are the same as with VSCode. Install
coc-json and try completion with
tsserver, typescript or javascript in your
coc-settings.json.
Related extensions
- coc-eslint: enable eslint plugin for tsserver to lint TypeScript and JavaScript files.
- coc-tslint-plugin: enable tslint plugin for tsserver (deprecated).
- coc-styled-components: Styled component for coc.nvim as a tsserver plugin.
- coc-react-refactor: React refactor extension for coc.nvim, forked from vscode-react-refactor.
- coc-vetur: vue extension.
- coc-angular: angular extension.
Troubleshooting
- Add
"tsserver.log": "verbose"to yourcoc-settings.json(opened by command:CocConfig) - To trace LSP communication, add
"tsserver.trace.server": "verbose"to yourcoc-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
If you find any issues, please create an issue.
License
MIT