diff --git a/Readme.md b/Readme.md index 5174b27..e161d42 100644 --- a/Readme.md +++ b/Readme.md @@ -160,7 +160,7 @@ for guide of coc.nvim's configuration. - `typescript.validate.enable`:Enable/disable TypeScript validation., default: `true` - `typescript.showUnused`: show unused variable hint, default: `true`. -- `typescript.autoClosingTags`: Enable/disable autoClosing of JSX tags, default: `false` +- `typescript.autoClosingTags`: Enable/disable autoClosing of JSX tags, default: `true` - `typescript.suggest.enabled` default: `true` - `typescript.suggest.paths`:Enable/disable suggest paths in import statement and require calls, default: `true` @@ -208,7 +208,7 @@ for guide of coc.nvim's configuration. - `typescript.inlayHints`: inlayHints related options. - `javascript.format.enabled`: Enable/disable format for javascript files, default: `true` - `javascript.showUnused`: show unused variable hint, default: `true` -- `javascript.autoClosingTags`: Enable/disable autoClosing of JSX tags, default: `false` +- `javascript.autoClosingTags`: Enable/disable autoClosing of JSX tags, default: `true` - `javascript.updateImportsOnFileMove.enable` default: `true` - `javascript.implementationsCodeLens.enable` default: `true` - `javascript.referencesCodeLens.enable` default: `true` diff --git a/history.md b/history.md index 4ec8778..de52c96 100644 --- a/history.md +++ b/history.md @@ -1,3 +1,7 @@ +# 1.9.7 + +- Change default of `javascript.autoClosingTags` and `typescript.autoClosingTags` to `true`. + # 1.9.6 - Rework codeLens related. diff --git a/package.json b/package.json index 5ed2d6f..e80ac19 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coc-tsserver", - "version": "1.9.6", + "version": "1.9.7", "description": "tsserver extension for coc.nvim", "main": "lib/index.js", "publisher": "chemzqm", @@ -529,7 +529,8 @@ }, "typescript.autoClosingTags": { "type": "boolean", - "default": false + "default": true, + "description": "Enable/disable automatic closing of JSX tags." }, "javascript.showUnused": { "type": "boolean", @@ -851,7 +852,8 @@ }, "javascript.autoClosingTags": { "type": "boolean", - "default": false + "default": true, + "description": "Enable/disable automatic closing of JSX tags." }, "javascript.format.semicolons": { "type": "string", @@ -881,7 +883,7 @@ "license": "MIT", "devDependencies": { "@types/node": "^12.12.12", - "coc.nvim": "^0.0.81-next.8", + "coc.nvim": "^0.0.81-next.11", "esbuild": "^0.14.11", "semver": "^7.3.5", "vscode-languageserver-protocol": "^3.16.0", diff --git a/src/server/features/tagClosing.ts b/src/server/features/tagClosing.ts index bb53810..b11ffb4 100644 --- a/src/server/features/tagClosing.ts +++ b/src/server/features/tagClosing.ts @@ -5,13 +5,10 @@ import { CancellationTokenSource, Disposable, disposeAll, Position, Range, snippetManager, events, workspace, InsertChange } from 'coc.nvim' import * as Proto from '../protocol' import { ITypeScriptServiceClient } from '../typescriptService' -import API from '../utils/api' import SnippetString from '../utils/SnippetString' import * as typeConverters from '../utils/typeConverters' export default class TagClosing implements Disposable { - public static readonly minVersion = API.v300 - private static _configurationLanguages: Record = { 'javascriptreact': 'javascript', 'typescriptreact': 'typescript', @@ -21,27 +18,21 @@ export default class TagClosing implements Disposable { private _disposed = false private _timeout: NodeJS.Timer | undefined = undefined private _cancel: CancellationTokenSource | undefined = undefined - private lastInsert: string constructor( private readonly client: ITypeScriptServiceClient, private readonly descriptionLanguageId: string ) { - events.on('InsertCharPre', character => { - this.lastInsert = character - }, null, this._disposables) - events.on('TextChangedI', this.onChange, this, this._disposables) - events.on('TextChangedP', this.onChange, this, this._disposables) + events.on('TextInsert', this.onInsertChange, this, this._disposables) } - private async onChange(bufnr: number, change: InsertChange): Promise { + private async onInsertChange(bufnr: number, change: InsertChange, lastInsert: string): Promise { let doc = workspace.getDocument((bufnr)) if (!doc || !doc.attached) return let enabled = this.isEnabled(doc.filetype, doc.uri) if (!enabled) return let { pre, changedtick, lnum } = change - if (!pre.endsWith('/') && !pre.endsWith('>')) return - if (!pre.endsWith(this.lastInsert)) return + if (lastInsert !== '/' && lastInsert != '>') return if (pre.length > 1 && pre[pre.length - 2] == '>') return const filepath = this.client.toOpenedFilePath(doc.uri) if (!filepath) return @@ -73,7 +64,6 @@ export default class TagClosing implements Disposable { return } if (this._disposed) return - const insertion = response.body if (doc.changedtick === changedtick) { snippetManager.insertSnippet( @@ -82,7 +72,7 @@ export default class TagClosing implements Disposable { Range.create(position, position) ) } - }, 50) + }, 30) } private isEnabled(languageId: string, uri: string): boolean { diff --git a/yarn.lock b/yarn.lock index fced966..5687257 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7,10 +7,10 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.41.tgz#81d7734c5257da9f04354bd9084a6ebbdd5198a5" integrity sha512-f6xOqucbDirG7LOzedpvzjP3UTmHttRou3Mosx3vL9wr9AIQGhcPgVnqa8ihpZYnxyM1rxeNCvTyukPKZtq10Q== -coc.nvim@^0.0.81-next.8: - version "0.0.81-next.8" - resolved "https://registry.yarnpkg.com/coc.nvim/-/coc.nvim-0.0.81-next.8.tgz#7c0ec46cfab29d41ebdb9e3e9cabf1cb5cc2b920" - integrity sha512-1dk2j571Gxk4lXw2GVdGfOJeZAhfZ5HgmtA/p4NW5gorNVnCcC6qe2sp0LiecgiWfah3o+BsOTahr+Vjwj6GYA== +coc.nvim@^0.0.81-next.11: + version "0.0.81-next.11" + resolved "https://registry.yarnpkg.com/coc.nvim/-/coc.nvim-0.0.81-next.11.tgz#2ac44f770da662adbaf30678edc837715016fe90" + integrity sha512-XxRRdpK67tVJH+zvwi4bHc9e/UJWBj2ZJdY8Q9/Twp0tgipDstoCqK3KeoszT79J7whPzS/1Y/8VG7dRNrMJ4w== esbuild-android-arm64@0.14.11: version "0.14.11"