upgrade typescript module, remove noSemicolons preferences
This commit is contained in:
parent
3a4f993918
commit
486202a7e5
8 changed files with 25 additions and 118 deletions
|
@ -78,7 +78,6 @@ this extension.
|
||||||
- `typescript.implementationsCodeLens.enable`:Enable codeLens for implementations, default: `true`
|
- `typescript.implementationsCodeLens.enable`:Enable codeLens for implementations, default: `true`
|
||||||
- `typescript.referencesCodeLens.enable`:Enable codeLens for references, default: `true`
|
- `typescript.referencesCodeLens.enable`:Enable codeLens for references, default: `true`
|
||||||
- `typescript.preferences.importModuleSpecifier` default: `"non-relative"`
|
- `typescript.preferences.importModuleSpecifier` default: `"non-relative"`
|
||||||
- `typescript.preferences.noSemicolons` default: `false`
|
|
||||||
- `typescript.preferences.quoteStyle` default: `"single"`
|
- `typescript.preferences.quoteStyle` default: `"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: `true`
|
- `typescript.suggestionActions.enabled`:Enable/disable suggestion diagnostics for TypeScript files in the editor. Requires using TypeScript 2.8 or newer in the workspace., default: `true`
|
||||||
- `typescript.validate.enable`:Enable/disable TypeScript validation., default: `true`
|
- `typescript.validate.enable`:Enable/disable TypeScript validation., default: `true`
|
||||||
|
@ -108,7 +107,6 @@ this extension.
|
||||||
- `javascript.implementationsCodeLens.enable` default: `true`
|
- `javascript.implementationsCodeLens.enable` default: `true`
|
||||||
- `javascript.referencesCodeLens.enable` default: `true`
|
- `javascript.referencesCodeLens.enable` default: `true`
|
||||||
- `javascript.preferences.importModuleSpecifier` default: `"non-relative"`
|
- `javascript.preferences.importModuleSpecifier` default: `"non-relative"`
|
||||||
- `javascript.preferences.noSemicolons` default: `false`
|
|
||||||
- `javascript.preferences.quoteStyle` default: `"single"`
|
- `javascript.preferences.quoteStyle` default: `"single"`
|
||||||
- `javascript.validate.enable`:Enable/disable JavaScript validation., default: `true`
|
- `javascript.validate.enable`:Enable/disable JavaScript validation., default: `true`
|
||||||
- `javascript.suggestionActions.enabled`:Enable/disable suggestion diagnostics for JavaScript files in the editor. Requires using TypeScript 2.8 or newer in the workspace., default: `true`
|
- `javascript.suggestionActions.enabled`:Enable/disable suggestion diagnostics for JavaScript files in the editor. Requires using TypeScript 2.8 or newer in the workspace., default: `true`
|
||||||
|
|
18
package.json
18
package.json
|
@ -230,10 +230,6 @@
|
||||||
"auto"
|
"auto"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"typescript.preferences.noSemicolons": {
|
|
||||||
"type": "boolean",
|
|
||||||
"default": false
|
|
||||||
},
|
|
||||||
"typescript.preferences.quoteStyle": {
|
"typescript.preferences.quoteStyle": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "single",
|
"default": "single",
|
||||||
|
@ -356,10 +352,6 @@
|
||||||
"relative"
|
"relative"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"javascript.preferences.noSemicolons": {
|
|
||||||
"type": "boolean",
|
|
||||||
"default": false
|
|
||||||
},
|
|
||||||
"javascript.preferences.quoteStyle": {
|
"javascript.preferences.quoteStyle": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "single",
|
"default": "single",
|
||||||
|
@ -480,19 +472,19 @@
|
||||||
"@chemzqm/tsconfig": "^0.0.3",
|
"@chemzqm/tsconfig": "^0.0.3",
|
||||||
"@chemzqm/tslint-config": "^1.0.18",
|
"@chemzqm/tslint-config": "^1.0.18",
|
||||||
"@types/fast-diff": "^1.2.0",
|
"@types/fast-diff": "^1.2.0",
|
||||||
"@types/node": "^12.7.2",
|
"@types/node": "^12.7.4",
|
||||||
"coc.nvim": "^0.0.73",
|
"coc.nvim": "^0.0.73",
|
||||||
"fast-diff": "^1.2.0",
|
"fast-diff": "^1.2.0",
|
||||||
"rimraf": "^3.0.0",
|
"rimraf": "^3.0.0",
|
||||||
"semver": "^6.3.0",
|
"semver": "^6.3.0",
|
||||||
"ts-loader": "^6.0.4",
|
"ts-loader": "^6.0.4",
|
||||||
"tslint": "^5.18.0",
|
"tslint": "^5.19.0",
|
||||||
"vscode-languageserver-protocol": "^3.15.0-next.5",
|
"vscode-languageserver-protocol": "^3.15.0-next.5",
|
||||||
"webpack": "^4.39.2",
|
"webpack": "^4.39.3",
|
||||||
"webpack-cli": "^3.3.6",
|
"webpack-cli": "^3.3.8",
|
||||||
"which": "^1.3.1"
|
"which": "^1.3.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"typescript": "3.5.3"
|
"typescript": "3.6.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,6 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP
|
||||||
|
|
||||||
public static readonly triggerCharacters = ['.', '"', '\'', '/', '@']
|
public static readonly triggerCharacters = ['.', '"', '\'', '/', '@']
|
||||||
private completeOption: SuggestOptions
|
private completeOption: SuggestOptions
|
||||||
private noSemicolons = false
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly client: ITypeScriptServiceClient,
|
private readonly client: ITypeScriptServiceClient,
|
||||||
|
@ -70,7 +69,6 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP
|
||||||
|
|
||||||
private setCompleteOption(languageId: string): void {
|
private setCompleteOption(languageId: string): void {
|
||||||
this.completeOption = this.fileConfigurationManager.getCompleteOptions(languageId)
|
this.completeOption = this.fileConfigurationManager.getCompleteOptions(languageId)
|
||||||
this.noSemicolons = this.fileConfigurationManager.removeSemicolons(languageId)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -291,12 +289,6 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (additionalTextEdits.length && this.noSemicolons) {
|
|
||||||
// remove comma
|
|
||||||
additionalTextEdits.forEach(o => {
|
|
||||||
o.newText = o.newText.replace(/;(?=(\n|$))/g, '')
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
command,
|
command,
|
||||||
additionalTextEdits: additionalTextEdits.length
|
additionalTextEdits: additionalTextEdits.length
|
||||||
|
|
|
@ -134,12 +134,6 @@ export default class FileConfigurationManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public removeSemicolons(languageId: string): boolean {
|
|
||||||
const lang = this.isTypeScriptDocument(languageId) ? 'typescript' : 'javascript'
|
|
||||||
const config = workspace.getConfiguration(`${lang}.preferences`)
|
|
||||||
return config.get<boolean>('noSemicolons', false)
|
|
||||||
}
|
|
||||||
|
|
||||||
public getPreferences(language: string): Proto.UserPreferences {
|
public getPreferences(language: string): Proto.UserPreferences {
|
||||||
if (!this.client.apiVersion.gte(API.v290)) {
|
if (!this.client.apiVersion.gte(API.v290)) {
|
||||||
return {}
|
return {}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import { DocumentFormattingEditProvider, DocumentRangeFormattingEditProvider } f
|
||||||
import { CancellationToken, FormattingOptions, Position, Range, TextDocument, TextEdit } from 'vscode-languageserver-protocol'
|
import { CancellationToken, FormattingOptions, Position, Range, TextDocument, TextEdit } from 'vscode-languageserver-protocol'
|
||||||
import * as Proto from '../protocol'
|
import * as Proto from '../protocol'
|
||||||
import { ITypeScriptServiceClient } from '../typescriptService'
|
import { ITypeScriptServiceClient } from '../typescriptService'
|
||||||
import { removeSemicolon } from '../utils/semicolon'
|
|
||||||
import * as typeConverters from '../utils/typeConverters'
|
import * as typeConverters from '../utils/typeConverters'
|
||||||
import FileConfigurationManager from './fileConfigurationManager'
|
import FileConfigurationManager from './fileConfigurationManager'
|
||||||
|
|
||||||
|
@ -36,9 +35,6 @@ export default class TypeScriptFormattingProvider
|
||||||
const response = await this.client.execute('format', args, token)
|
const response = await this.client.execute('format', args, token)
|
||||||
if (response.type == 'response' && response.body) {
|
if (response.type == 'response' && response.body) {
|
||||||
let edits = response.body.map(typeConverters.TextEdit.fromCodeEdit)
|
let edits = response.body.map(typeConverters.TextEdit.fromCodeEdit)
|
||||||
if (this.formattingOptionsManager.removeSemicolons(document.languageId)) {
|
|
||||||
return removeSemicolon(document, edits)
|
|
||||||
}
|
|
||||||
return edits
|
return edits
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
|
|
@ -42,19 +42,6 @@ export class OrganizeImportsCommand implements Command {
|
||||||
)
|
)
|
||||||
let desc = standardLanguageDescriptions.find(o => o.modeIds.indexOf(document.languageId) !== -1)
|
let desc = standardLanguageDescriptions.find(o => o.modeIds.indexOf(document.languageId) !== -1)
|
||||||
if (!desc) return null
|
if (!desc) return null
|
||||||
const config = workspace.getConfiguration(`${desc.id}.preferences`)
|
|
||||||
let noSemicolons = config.get<boolean>('noSemicolons', false)
|
|
||||||
|
|
||||||
if (noSemicolons) {
|
|
||||||
let { changes } = edit
|
|
||||||
if (changes) {
|
|
||||||
for (let c of Object.keys(changes)) {
|
|
||||||
for (let textEdit of changes[c]) {
|
|
||||||
textEdit.newText = textEdit.newText.replace(/;(?=(\n|$))/g, '')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return edit
|
return edit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
import fastDiff from 'fast-diff'
|
|
||||||
import { TextDocument, TextEdit } from 'vscode-languageserver-protocol'
|
|
||||||
|
|
||||||
interface Change {
|
|
||||||
start: number
|
|
||||||
end: number
|
|
||||||
newText: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export function removeSemicolon(document: TextDocument, edits: TextEdit[]): TextEdit[] {
|
|
||||||
let orig = document.getText()
|
|
||||||
let content = TextDocument.applyEdits(document, edits)
|
|
||||||
let result = content.split('\n').map(s => s.replace(/;$/, '')).join('\n')
|
|
||||||
if (result == content) return edits
|
|
||||||
let change = getChange(orig, result)
|
|
||||||
return [{
|
|
||||||
range: {
|
|
||||||
start: document.positionAt(change.start),
|
|
||||||
end: document.positionAt(change.end)
|
|
||||||
},
|
|
||||||
newText: change.newText
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
|
|
||||||
function getChange(oldStr: string, newStr: string): Change {
|
|
||||||
let result = fastDiff(oldStr, newStr, 1)
|
|
||||||
let curr = 0
|
|
||||||
let start = -1
|
|
||||||
let end = -1
|
|
||||||
let newText = ''
|
|
||||||
let remain = ''
|
|
||||||
for (let item of result) {
|
|
||||||
let [t, str] = item
|
|
||||||
// equal
|
|
||||||
if (t == 0) {
|
|
||||||
curr = curr + str.length
|
|
||||||
if (start != -1) remain = remain + str
|
|
||||||
} else {
|
|
||||||
if (start == -1) start = curr
|
|
||||||
if (t == 1) {
|
|
||||||
newText = newText + remain + str
|
|
||||||
end = curr
|
|
||||||
} else {
|
|
||||||
newText = newText + remain
|
|
||||||
end = curr + str.length
|
|
||||||
}
|
|
||||||
remain = ''
|
|
||||||
if (t == -1) curr = curr + str.length
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return { start, end, newText }
|
|
||||||
}
|
|
40
yarn.lock
40
yarn.lock
|
@ -45,10 +45,10 @@
|
||||||
dependencies:
|
dependencies:
|
||||||
fast-diff "*"
|
fast-diff "*"
|
||||||
|
|
||||||
"@types/node@^12.7.2":
|
"@types/node@^12.7.4":
|
||||||
version "12.7.2"
|
version "12.7.4"
|
||||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.7.2.tgz#c4e63af5e8823ce9cc3f0b34f7b998c2171f0c44"
|
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.7.4.tgz#64db61e0359eb5a8d99b55e05c729f130a678b04"
|
||||||
integrity sha512-dyYO+f6ihZEtNPDcWNR1fkoTDf3zAK3lAABDze3mz6POyIercH0lEUawUFXlG8xaQZmm1yEBON/4TsYv/laDYg==
|
integrity sha512-W0+n1Y+gK/8G2P/piTkBBN38Qc5Q1ZSO6B5H3QmPCUewaiXOo2GCAWZ4ElZCcNhjJuBSUSLGFUJnmlCn5+nxOQ==
|
||||||
|
|
||||||
"@webassemblyjs/ast@1.8.5":
|
"@webassemblyjs/ast@1.8.5":
|
||||||
version "1.8.5"
|
version "1.8.5"
|
||||||
|
@ -3087,10 +3087,10 @@ tslint-react@^3.2.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
tsutils "^2.13.1"
|
tsutils "^2.13.1"
|
||||||
|
|
||||||
tslint@^5.18.0:
|
tslint@^5.19.0:
|
||||||
version "5.18.0"
|
version "5.19.0"
|
||||||
resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.18.0.tgz#f61a6ddcf372344ac5e41708095bbf043a147ac6"
|
resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.19.0.tgz#a2cbd4a7699386da823f6b499b8394d6c47bb968"
|
||||||
integrity sha512-Q3kXkuDEijQ37nXZZLKErssQVnwCV/+23gFEMROi8IlbaBG6tXqLPQJ5Wjcyt/yHPKBC+hD5SzuGaMora+ZS6w==
|
integrity sha512-1LwwtBxfRJZnUvoS9c0uj8XQtAnyhWr9KlNvDIdB+oXyT+VpsOAaEhEgKi1HrZ8rq0ki/AAnbGSv4KM6/AfVZw==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@babel/code-frame" "^7.0.0"
|
"@babel/code-frame" "^7.0.0"
|
||||||
builtin-modules "^1.1.1"
|
builtin-modules "^1.1.1"
|
||||||
|
@ -3128,10 +3128,10 @@ typedarray@^0.0.6:
|
||||||
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
|
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
|
||||||
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
|
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
|
||||||
|
|
||||||
typescript@3.5.3:
|
typescript@3.6.2:
|
||||||
version "3.5.3"
|
version "3.6.2"
|
||||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.5.3.tgz#c830f657f93f1ea846819e929092f5fe5983e977"
|
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.6.2.tgz#105b0f1934119dde543ac8eb71af3a91009efe54"
|
||||||
integrity sha512-ACzBtm/PhXBDId6a6sDJfroT2pOWt/oOnk4/dElG5G33ZL776N3Y6/6bKZJBFpd+b05F3Ct9qDjMeJmRWtE2/g==
|
integrity sha512-lmQ4L+J6mnu3xweP8+rOrUwzmN+MRAj7TgtJtDaXE5PMyX2kCrklhg3rvOsOIfNeAWMQWO2F1GPc1kMD2vLAfw==
|
||||||
|
|
||||||
union-value@^1.0.0:
|
union-value@^1.0.0:
|
||||||
version "1.0.1"
|
version "1.0.1"
|
||||||
|
@ -3279,10 +3279,10 @@ watchpack@^1.6.0:
|
||||||
graceful-fs "^4.1.2"
|
graceful-fs "^4.1.2"
|
||||||
neo-async "^2.5.0"
|
neo-async "^2.5.0"
|
||||||
|
|
||||||
webpack-cli@^3.3.6:
|
webpack-cli@^3.3.8:
|
||||||
version "3.3.6"
|
version "3.3.8"
|
||||||
resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-3.3.6.tgz#2c8c399a2642133f8d736a359007a052e060032c"
|
resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-3.3.8.tgz#caeaebcc26f685db1736e5decd3f01aac30123ec"
|
||||||
integrity sha512-0vEa83M7kJtxK/jUhlpZ27WHIOndz5mghWL2O53kiDoA9DIxSKnfqB92LoqEn77cT4f3H2cZm1BMEat/6AZz3A==
|
integrity sha512-RANYSXwikSWINjHMd/mtesblNSpjpDLoYTBtP99n1RhXqVI/wxN40Auqy42I7y4xrbmRBoA5Zy5E0JSBD5XRhw==
|
||||||
dependencies:
|
dependencies:
|
||||||
chalk "2.4.2"
|
chalk "2.4.2"
|
||||||
cross-spawn "6.0.5"
|
cross-spawn "6.0.5"
|
||||||
|
@ -3304,10 +3304,10 @@ webpack-sources@^1.4.0, webpack-sources@^1.4.1:
|
||||||
source-list-map "^2.0.0"
|
source-list-map "^2.0.0"
|
||||||
source-map "~0.6.1"
|
source-map "~0.6.1"
|
||||||
|
|
||||||
webpack@^4.39.2:
|
webpack@^4.39.3:
|
||||||
version "4.39.2"
|
version "4.39.3"
|
||||||
resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.39.2.tgz#c9aa5c1776d7c309d1b3911764f0288c8c2816aa"
|
resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.39.3.tgz#a02179d1032156b713b6ec2da7e0df9d037def50"
|
||||||
integrity sha512-AKgTfz3xPSsEibH00JfZ9sHXGUwIQ6eZ9tLN8+VLzachk1Cw2LVmy+4R7ZiwTa9cZZ15tzySjeMui/UnSCAZhA==
|
integrity sha512-BXSI9M211JyCVc3JxHWDpze85CvjC842EvpRsVTc/d15YJGlox7GIDd38kJgWrb3ZluyvIjgenbLDMBQPDcxYQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@webassemblyjs/ast" "1.8.5"
|
"@webassemblyjs/ast" "1.8.5"
|
||||||
"@webassemblyjs/helper-module-context" "1.8.5"
|
"@webassemblyjs/helper-module-context" "1.8.5"
|
||||||
|
|
Loading…
Reference in a new issue