Skip to content

Commit 6faecfb

Browse files
committed
feat: meet @ts-diagnostic-disable! Support can be enabled via new setting, define this on first line in // comment and disable diagnostics you won't see in the editor
1 parent fe8caba commit 6faecfb

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/configurationType.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,12 @@ export type Configuration = {
158158
* @default true
159159
*/
160160
enableMethodSnippets: boolean
161+
/**
162+
* Support `@ts-diagnostic-disable` top-level comment for disabling spefici semantic diagnostics
163+
* Example: `// @ts-diagnostic-disable
164+
* Advanced usage only! Enable in `.vscode/settings.json` for projects that need this
165+
* Since its changes only IDE experience, but not tsc
166+
* @default false
167+
*/
168+
supportTsDiagnosticDisableComment: boolean
161169
}

typescript/src/index.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type { Configuration } from '../../src/configurationType'
66
import _ from 'lodash'
77
import { GetConfig } from './types'
88
import { getCompletionsAtPosition, PrevCompletionMap } from './completionsAtPosition'
9-
import { getParameterListParts } from './completionGetMethodParameters'
109
import { oneOf } from '@zardoy/utils'
1110
import { isGoodPositionMethodCompletion } from './isGootPositionMethodCompletion'
1211

@@ -134,7 +133,7 @@ export = function ({ typescript }: { typescript: typeof import('typescript/lib/t
134133
proxy.getCodeFixesAtPosition = (fileName, start, end, errorCodes, formatOptions, preferences) => {
135134
let prior = info.languageService.getCodeFixesAtPosition(fileName, start, end, errorCodes, formatOptions, preferences)
136135
// const scriptSnapshot = info.project.getScriptSnapshot(fileName)
137-
const diagnostics = info.languageService.getSemanticDiagnostics(fileName)
136+
const diagnostics = proxy.getSemanticDiagnostics(fileName)
138137

139138
// https://github.com/Microsoft/TypeScript/blob/v4.5.5/src/compiler/diagnosticMessages.json#L458
140139
const appliableErrorCode = [1156, 1157].find(code => errorCodes.includes(code))
@@ -203,6 +202,22 @@ export = function ({ typescript }: { typescript: typeof import('typescript/lib/t
203202
return prior
204203
}
205204

205+
proxy.getSemanticDiagnostics = fileName => {
206+
let prior = info.languageService.getSemanticDiagnostics(fileName)
207+
if (c('supportTsDiagnosticDisableComment')) {
208+
const scriptSnapshot = info.project.getScriptSnapshot(fileName)!
209+
const firstLine = scriptSnapshot.getText(0, scriptSnapshot.getLength()).split(/\r?\n/)[0]!
210+
if (firstLine.startsWith('//')) {
211+
const match = firstLine.match(/@ts-diagnostic-disable ((\d+, )*(\d+))/)
212+
if (match) {
213+
const codesToDisable = match[1]!.split(', ').map(Number)
214+
prior = prior.filter(({ code }) => !codesToDisable.includes(code))
215+
}
216+
}
217+
}
218+
return prior
219+
}
220+
206221
info.languageService[thisPluginMarker] = true
207222

208223
return proxy

0 commit comments

Comments
 (0)