Ⅰ. 插件描述
Tsserver extension for coc.nvimⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'neoclide/coc-tsserver'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'neoclide/coc-tsserver'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'neoclide/coc-tsserver'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/neoclide/coc-tsserver
Ⅳ. 文档说明
# coc-tsserver
Tsserver language server extension for coc.nvim.
Most of the code is from typescript-language-features extension which is bundled with VSCode.
Note: if you're using nvm or other
node version manager, you need to configure tsserver.npm to your global npm
executable path to avoid fetching types on vim start every time.
Note: for React to work as expected, you need your JSX filetype to bejavascript.jsx and your TSX filetype to be typescript.jsx ortypescript.tsx. In coc.nvim, these filetypes are mapped to javascriptreact
and typescriptreact because that's what tsserver uses.
Install
In your vim/neovim, run command:
:CocInstall coc-tsserverFeatures
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.formattsserver.organizeImportstsserver.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.
- Rename imports on file rename, require watchman installed in your $PATH.
- Search for workspace symbols.
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.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.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 tsservertsserver.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.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.preferences.importModuleSpecifierdefault:"non-relative"typescript.preferences.quoteStyledefault:"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:truetypescript.validate.enable:Enable/disable TypeScript validation., default:truetypescript.showUnused: show unused variable hint, default:true.typescript.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.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.insertSpaceAfterOpeningAndBeforeClosingNonemptyBracesdefault:falsetypescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesisdefault:falsetypescript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBracesdefault:falsetypescript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBracesdefault:falsetypescript.format.insertSpaceAfterTypeAssertiondefault:falsetypescript.format.placeOpenBraceOnNewLineForFunctionsdefault:falsetypescript.format.placeOpenBraceOnNewLineForControlBlocksdefault:falsejavascript.format.enabled: Enable/disable format for javascript files.javascript.showUnused: show unused variable hint.javascript.updateImportsOnFileMove.enabledefault:truejavascript.implementationsCodeLens.enabledefault:truejavascript.referencesCodeLens.enabledefault:truejavascript.preferences.importModuleSpecifierdefault:"non-relative"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.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.insertSpaceAfterOpeningAndBeforeClosingNonemptyBracesdefault:falsejavascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesisdefault:falsejavascript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBracesdefault:falsejavascript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBracesdefault:falsejavascript.format.insertSpaceAfterTypeAssertiondefault:falsejavascript.format.placeOpenBraceOnNewLineForFunctionsdefault:falsejavascript.format.placeOpenBraceOnNewLineForControlBlocksdefault:false
Configurations are the same as with VSCode. 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-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 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
If you find any issues, please create an issue.
License
MIT